Botframework-webchat: Getting 401 when user sends a message on webchat

Created on 15 Feb 2021  路  2Comments  路  Source: microsoft/BotFramework-WebChat

I am getting 401 errors for every message that the user sends thorugh webchat.

My code it's very similar to
https://github.com/microsoft/BotFramework-WebChat/tree/master/samples/04.api/a.welcome-event

The only differnce is that for now I am getting the token in the browser something like this:

let response = await fetch('https://directline.botframework.com/v3/directline/tokens/generate', { method: 'POST', headers: { 'Authorization': 'Bearer MY SECRET' } });
let { token } = await response.json();
The bot sends the welcome message but when the user sends any message I get the following message on webchat:
_Response status code does not indicate success: 401 (PermissionDenied)._
I am not getting any error in the console.

Screenshots

image

Version

I am using the CDN.

Describe the bug

Webchat connects successfully to my bot, the welcome message is displayed but any message sent from the user returns a 401 error on webchat.

Steps to reproduce

This is my code:

(async function () {

    let response = await fetch('https://directline.botframework.com/v3/directline/tokens/generate', 
    { 
        method: 'POST',
        headers: { 
        'Authorization': 'Bearer MY_SERCRET'
        }
    });
    let { token } = await response.json(); 

    const store = window.WebChat.createStore({}, ({ dispatch }) => next => action => {
      if (action.type === 'DIRECT_LINE/CONNECT_FULFILLED') {
        //Sending an event to the menu is displayed
        dispatch({
          type: 'WEB_CHAT/SEND_EVENT',
          payload: {
            name: 'webchat/join',
            value: {message: 'Hi'}
          }
        });
      }

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

    document.querySelector('#webchat > *').focus();

})().catch(err => console.error(err));

Expected behavior

I expect that the user can have a conversation with the bot.

Additional context

Using the Iframe version to host the webchat works fine. I use direct line to connect to Twilio and works fine, my bot is developed with Composer.

[Bug]

Bot Services Bug customer-reported

Most helpful comment

I am closing this since redeploying my bot fixed the issue.

All 2 comments

I forgot to mention that I also tried specifying a user id when requesting the token and also calling renderWebChat but got the same result (401 error).
I also connected my javascript code to the MockBot and it works fine, so I think that I am missing some configuration either on webchat or on my bot.

This is my direct line configuration:
image

I am closing this since redeploying my bot fixed the issue.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

electrobabe picture electrobabe  路  4Comments

Kellym-Kainos picture Kellym-Kainos  路  4Comments

naveen-vijay picture naveen-vijay  路  4Comments

compulim picture compulim  路  3Comments

corinagum picture corinagum  路  3Comments