Search code examples
c#azurebotframework

How do I resolve a 401 on my azure web app bot?


I've been working on this problem for a week now and I've got no further and was hoping someone had encountered this before. The documentation around this is frustratingly sparse and glosses over the particular issues i'm having trouble with.

So I have a bot I wish to integrate into a teams application, but before that I wanted to test it in the emulator and ensure it works in Azures Test in Webchat feature. The Web App Bot is hosted on Azure, as is the App Bot Service, which is what I deploy to. When I test it in web chat, There is an error in my browsers console, and in the Channel there is a listed issue stating "There was an error sending this message to your bot: HTTP status code Unauthorized"

What I assume is happening is that my Web App Bot is sending a malformed request to my web app service. But I don't understand why.

enter image description here

So, looking around here and other places, it looks like the cookie cutter answers for this are a combination of check your AppId and AppPassword are correct, make sure your endpoint is correct, make sure the admin has consented, test it in the emulator, update your bot framework nugets, make sure you subscribed your bot correctly, delete and resubscribe your bot etc etc, naturally all of these I've done.

I'm sure the Id and Password, endpoint, and consent are all correct, as I can connect to the bot fine in the emulator.

enter image description here

What I'm not clear on is the consent process. I think I've consented to everything I need to, but it might be worth double checking.

I've also tried remote debugging to see if it hits my code, and it does, but the postAsync() controller just throws out the request

[HttpPost, HttpGet]
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);
}

Is there anything I need to configure, or any thing I can look into here? Azure can be a confusing place so it would be nice to have some advice from someone more knowledgeable.

So that's my question. Why am I not authorised to test this in Test Web Chat on Azure? And why do I get the same errors when I include the bot ID in my teams manifest?


Solution

  • For those who stumble onto this thread, the answer was that I just had to delete my app service and deploy it again.

    I originally created the service manually, and then used continuous deployment to deploy onto it, but I found that just deleting the app service, and having visual studio create the service for me, the bot suddenly began authorizing.

    As far as I know, no configuration was different, so it must've been something to do with setup. Marking as solved.