Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

"Cannot post activity. Unauthorized" When testing from Bot Emulator

While testing the EchoBot template from Azure in Bot Emulator I keep getting "Cannot post activity. Unauthorized." How can I protect against this? I am new to .NET, so don't understand the how authentication is working here. I can see the configuration settings being loaded, but I don't see how they get supplied or applied in the default EchoBot template from Azure.

I have found I only get Unauthorized, if I have the "MicrosoftAppID" and "MicrosoftAppPassword" defined in the appsettings.json. If I comment these out it works fine.

    [HttpPost]
    public async Task PostAsync()
    {
        // Delegate the processing of the HTTP POST to the adapter.
        // The adapter will invoke the bot.
        await Adapter.ProcessAsync(Request, Response, Bot);
    }

So I would like to understand how to avoid having to comment these lines out when testing the code locally. PostAsync returns the 401.

like image 687
Mohit Avatar asked Oct 19 '19 12:10

Mohit


People also ask

Why can't my bot post activity?

This Cannot post activity. Unauthorized might happen while bot debugging. One easy check need to be done before testing locally: Either remove your credentials (MicrosoftAppId / MicrosoftAppPassword) from appsettings.json file or provide them to Bot Emulator. Otherwise first message to your bot will throw this error.

Is it possible to talk to a bot in an emulator?

Bot is currently running in Azure. If you connect to the bot in the emulator, it gives you 401 Unauthorized If you use the same AppID and password in the emulator for a Node.js bot running locally, the authentication works and you can talk to the Node.js bot in the emulator.

How do you debug a bot framework?

Debug with the emulator. The Bot Framework Emulator is a desktop application that allows bot developers to test and debug their bots, either locally or remotely. Using the emulator, you can chat with your bot and inspect the messages that your bot sends and receives.

Why can't I get my App ID and password in Bot emulator?

If you haven't register it on Azure, you won't get ID and password. In this case, you must left the Microsoft App Id and Password json string as blank. Something like this: In the Bot Emulator, don't give any credentials. Just provide your app URL and click Connect. By this way you can get rid of the error. Hope this helps.


Video Answer


1 Answers

Have you tried adding your Microsoft App ID and Microsoft App Password inside of the Emulator ?

It should work fine after you add those when you test the bot in the emulator, check picture below

enter image description here

like image 199
Marc Asmar Avatar answered Sep 20 '22 08:09

Marc Asmar