unable to connect botkit-based bot to BotFramework's webchat (401 errors)

513 views Asked by At

After successfully connecting my locally hosted (botkit-based) bot to Microsoft's Bot Framework Emulator (using a localhost address for the messaging endpoint), I'm now trying to connect it to the framework's webchat (using an ngrok's hostname for my local bot). However, I get an 'unauthorized' when webchat tries to connect. More on my bot:

Here's what I've tried so far:

In all those cases my bot's own log displays the same: "Experienced an error inside the turn handler Error: BotFrameworkAdapter.processActivity(): 401 ERROR Error: Unauthorized. Invalid AppId passed on token: blah".

The browser console shows different results for the last case compared to the website embeds as follows:

  • (website embeds), I see a 502 in the browser's console, which I believe is expected given the 401 response from the bot (as explained by other sources).
  • (Test in Web Chat'), I see several other errors in the browser web console in addition to the 502. One of those errors makes me think that perhaps 'Test in Web Chat' does not actually support non-Azure hosted bots (MsPortalFx/Base/Base.Net Base.Net: Security issue: Request to send auth token to untrusted domain 'myngrokhostname.scm.azurewebsites.net'. Only a fixed set of domains should be configured to receive auth tokens).

So here are my immediate questions:

  • Does the 'Test in web chat' feature require an Azure-hosted bot?
  • Given that I don't specify myself an appId and password when configuring the webchat channel (since it gets automatically configured), how could I be getting an error indicating that the wrong appId is being used? (note: the appId and password are part of the bot's adapter configuration as explained in the link I shared earlier; this is the only spot in which I entered them, and they were copied directly from the AzureBot configuration console)

Aside from the above questions, do you have any other suggestions on what could be wrong/missing in my environment? BTW, by now I believe I have read all of the similar posts that refer to 'unauthorized' errors while using webchat and none of them has helped so far, including those referenced in the first comment provided below. For the record, here are the posts (not mentioned in the comment) that I've also read:

2

There are 2 answers

0
pgoldweic On BEST ANSWER

After all the time spent debugging this issue, it turned out to be a simple typo in the botkit controller creation code. Instead of having it use 'adapterConfig' to set the bot's adapter to the built-in bot framework adapter, it was using 'adapter_config'. This was breaking the integration with the bot framework, as no app Id or password were being passed on. Thanks to Microsoft Support for troubleshooting help.

4
Kartik Bhiwapurkar On

• I will suggest you to please check the below Github community forum for details on your issue regarding the turn handler and the ‘BotFrameworkAdapter.processActivity():401 ERROR’ in which they state that they tried to connect through two types by local bot: -

  1. By entering the URL, appID/password
  2. To select the bot which is defined by bot file from "My bots" form in the Welcome section.

In the above two types of connections made, the 1st one always fails while the 2nd one executes successfully always. So, according to them, they are suggesting downloading the latest version of Emulator over.

https://github.com/microsoft/BotFramework-Emulator/issues/1417

Kindly refer to it as it may be helpful to you. And as far as ‘Test in webchat’ feature is concerned, it does require an Azure hosted bot because the Bot Framework Emulator that runs on the local device has the Azure Bot service endpoint link embedded in its runtime configuration for which during the execution of the emulator, we have to enter the AppID and password of the Azure Bot service to connect to.

https://learn.microsoft.com/en-us/composer/test/test-bots-in-web-chat