microsoft/BotFramework-WebChat

Error with Power Virtual Agent Bot: Site Missing code 403 from https://directline.botframework.com/v3/directline/conversations

alessiodecastro opened this issue · 3 comments

Is it an issue related to Adaptive Cards?

No

Is this an accessibility issue?

No

What version of Web Chat are you using?

Latest production

Which distribution are you using Web Chat from?

Bundle (webchat.js)

Which hosting environment does this issue primarily affect?

Web apps

Which browsers and platforms do the issue happened?

No response

Which area does this issue affect?

Protocol or service

What is the public URL for the website?

No response

Please describe the bug

Hello, the following piece of code was working fine up to last week, from yesterday we are getting the following 403 error after successfully retrieve the token and then performing request to: https://directline.botframework.com/v3/directline/conversations

response body from https://directline.botframework.com/v3/directline/conversations:

"error": {
    "code": "BadArgument",
    "message": "Site missing. Learn more about sites  https://docs.microsoft.com/azure/bot-service/bot-service-channel-connect-directline?view=azure-bot-service-4.0#add-new-site."
  }

image

The webchat is using a Power Virtual Agent Bot and the relative token issuer, by the way from the power platform side there is no way to define sites as usually happen in the Azure Bot Service Resource.
Here is the full testing code running in localhost env:

<!DOCTYPE html>
<html lang="en-US">
  <head>
    <title>Web Chat</title>
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <script crossorigin="anonymous" src="https://cdn.botframework.com/botframework-webchat/latest/webchat.js"></script>
    <style>
      html,
      body {
        height: 100%;
      }

      body {
        margin: 0;
      }

      #webchat {
        height: 100%;
        width: 100%;
      }
    </style>
  </head>
  <body>
    <div id="webchat" role="main"></div>
    <script>
      (async function() {
        const res = await fetch('https://ced36af1b92ee6ae99db50a8734a78.5a.environment.api.powerplatform.com/powervirtualagents/bots/b8ab704c-8d06-417e-b2b5-fc65a0abf77f/directline/token?api-version=2022-03-01-preview', { method: 'GET' });
        const { token } = await res.json();

        window.WebChat.renderWebChat(
          {
            directLine: window.WebChat.createDirectLine({ token })
          },
          document.getElementById('webchat')
        );

        document.querySelector('#webchat > *').focus();
      })().catch(err => console.error(err));
    </script>
  </body>
</html>

Thanks for the support.

Do you see any errors in console log?

response body from https://directline.botframework.com/v3/directline/conversations: 

    "error": {
        "code": "BadArgument",
        "message": "Site missing. Learn more about sites  https://docs.microsoft.com/azure/bot-service/bot-service-channel-connect-directline?view=azure-bot-service-4.0#add-new-site."
      }

How to reproduce the issue?

<!DOCTYPE html>
<html lang="en-US">
  <head>
    <title>Web Chat</title>
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <script crossorigin="anonymous" src="https://cdn.botframework.com/botframework-webchat/latest/webchat.js"></script>
    <style>
      html,
      body {
        height: 100%;
      }

      body {
        margin: 0;
      }

      #webchat {
        height: 100%;
        width: 100%;
      }
    </style>
  </head>
  <body>
    <div id="webchat" role="main"></div>
    <script>
      (async function() {
        const res = await fetch('https://ced36af1b92ee6ae99db50a8734a78.5a.environment.api.powerplatform.com/powervirtualagents/bots/b8ab704c-8d06-417e-b2b5-fc65a0abf77f/directline/token?api-version=2022-03-01-preview', { method: 'GET' });
        const { token } = await res.json();

        window.WebChat.renderWebChat(
          {
            directLine: window.WebChat.createDirectLine({ token })
          },
          document.getElementById('webchat')
        );

        document.querySelector('#webchat > *').focus();
      })().catch(err => console.error(err));
    </script>
  </body>
</html>

What do you expect?

200 OK response from https://directline.botframework.com/v3/directline/conversations:

What actually happened?

403 Site Missing

Do you have any screenshots or recordings to repro the issue?

No response

Adaptive Card JSON

No response

Additional context

No response

@alessiodecastro, I've been testing this since yesterday by making a request using Postman directly to the https://directline.botframework.com/v3/directline/conversations endpoint. I received this error only once while using what I thought was perhaps a bad setup. I encountered this prior to seeing this issue. So, I created a new, clean setup and it has worked fine since that first instance.

Can you verify if you are still experiencing the issue? If you make a similar request in Postman (or a similar service), do you get the same or does the error go away?

Here's the code snippet from Postman interpreted as a JavaScript fetch request. You can reference this for easy setup in Postman or place this in a project and try running.

var myHeaders = new Headers();
myHeaders.append("Content-Type", "application/json");
myHeaders.append("Authorization", "Bearer <<YOUR DIRECTLINE SECRET>>");

var raw = JSON.stringify({
  "user": {
    "id": "dl_abc123",
    "name": "user1"
  }
});

var requestOptions = {
  method: 'POST',
  headers: myHeaders,
  body: raw,
  redirect: 'follow'
};

fetch("https://directline.botframework.com/v3/directline/conversations", requestOptions)
  .then(response => response.text())
  .then(result => console.log(result))
  .catch(error => console.log('error', error));

@alessiodecastro, I forgot that you don't have access to the DirectLine secret in PVA as you would in an SDK bot. Let me research how you could test this and I'll get back to you.

Are you still experiencing this issue, though?

@stevkan yesterday, after spending two days on this, I opened a support ticket to MSFT. They investigated in first instance and replicated the same problem, even with the official git repo samples, without finding the reason so they escaleted to the PVA product team engineers. As temporary workaround they said to specify in the renderWebChat the domain as https://europe.directline.botframework.com/v3/directline/conversations instead of the standard one. In the meanwhile they are still investigating, much probably is something depending on their side about networking propagation matter. By the way even in postman I got the same issue till yesterday, now that token endpoint url is no more available from my dev environment. Waiting responses from the product team, you can close this issue. Thanks