Search code examples
azurebotframeworkazure-language-understanding

ChatBot not working after Deploying on Azure - Internal server error


I have deployed a chatbot with LUIS and QnA Maker. It works perfectly locally when I run it on Emulator. It loads up the adaptive cards at start of the chat and I get correct replies from LUIS.

However when I deploy the bot on Azure and test it on Web chat it gives the following error:

There was an error sending this message to your bot: HTTP status code InternalServerError

This is how my web.config looks like:

 <configuration>
  <appSettings>
    <!-- update these with your BotId, Microsoft App Id and your Microsoft App Password-->
    <add key="BotId" value="BotLuis" />
    <add key="MicrosoftAppId" value="9f9564ef-d627-450f-b943-98b7338c0f31" />
    <add key="MicrosoftAppPassword" value="myapp-password" />
  </appSettings>

I get the values for AppID and AppPassword from the Applications setting of the web bot I created on Azure. I know they are correct since I used these values to setup locally using Emulator.

I deploy the code from github to Azure. My bot loads up just fine (The adaptive cards show) on azure web chat but after that any input I give to it, whether it is interactive card or chat command, I get the above error.

The application Insight shows the following exception:

POST to BotLuis failed: POST to the bot's endpoint failed with HTTP status 500 Problem Id:System.Exception at Microsoft.Bot.ChannelConnector.BotAPI+d__31.MoveNext

The developers tool console shows this when I interact with the bot:

https://webchat.botframework.com/v3/directline/conversations/3NgflndFbpzCRDtnMdZpjf-g/activities 502 (Bad Gateway)

if you paste the above link in a browser this is what you will get:

{
 "error": {
 "code": "BadArgument",
 "message": "Missing token or secret"
        }
}

I am lost at this point. I can understand the problem but I don't know how to go forward. Am I supposed to add the messaging endpoint of my bot in my code somewhere?

A link to github repo of the code:here


Solution

  • Bot State Service retired on March 31st, 2018. Therefore your sample is missing state storage when you run it on Azure, while it will work locally.

    To make your sample work, simply add the following lines to your Global.asax.csfile.

    protected void Application_Start()
    {
        RegisterBotDependencies();
    
        GlobalConfiguration.Configure(WebApiConfig.Register);
    
        var store = new InMemoryDataStore();
    
        Conversation.UpdateContainer(
                   builder =>
                   {
                       builder.Register(c => store)
                                 .Keyed<IBotDataStore<BotData>>(AzureModule.Key_DataStore)
                                 .AsSelf()
                                 .SingleInstance();
    
                       builder.Register(c => new CachingBotDataStore(store,
                                  CachingBotDataStoreConsistencyPolicy
                                  .ETagBasedConsistency))
                                  .As<IBotDataStore<BotData>>()
                                  .AsSelf()
                                  .InstancePerLifetimeScope();
    
    
                   });
    }
    

    Please note that this sample uses InMemory storage and is therefore not intended for production use. Following the blog post, you can easily switch over to Azure Table storage or CosmosDB.

    I've cloned your repository, added these lines of code and deployed it to a new bot instance on Azure. Webchat test was successful.

    Summary

    Taken from above blog post.

    We’ve been encouraging bot developers using the Bot Framework to use their own custom state service for a while. The default Bot Framework State service was intended for prototyping purposes only, and not designed to accommodate production bots. The state service will be deprecated on March 31, 2018 and will no longer be supported. Bot developers moving forward will be able to prototype their bots using temporary local memory storage as described in this article. Creating your own custom state service for your bot provides multiple benefits including improved latency and direct control over your bot’s conversation state and contextual user conversation state information, and we’ve provided multiple resources to guide you to do so. We appreciate the feedback we’ve been receiving from the bot developer community, which has helped us a lot in improving the Bot Framework as a whole. We also hope that we can continue helping you – the bot developer community, create better and better bot experiences for your users.