Search code examples
c#azurebotframework

Bot working on Emulator but not on Azure (InternalServerError)


Using:

  • SDK Language: C#
  • SDK Version: 4.1.5
  • Enviroment: Localhost, Azure
  • Channel: webchat

Issue Description

When testing the bot in Bot Framework Emulator V4, it does work as expected as it can be seen in the next figure:

Figure 1: Bot working on emulator

After Deploying it in Azure following this instructions, bot stops working (neither sending or receiving messages) and got this alerts in the webchat channel section:

Figure 2: Alerts at the channel section

I've found these similar issues:

https://github.com/Microsoft/BotFramework-Emulator/issues/296

https://github.com/Microsoft/BotBuilder/issues/3329

But in my case both AppId and Password are defined and the other solution simply doesn't work at all. I even managed to find the error codes on the azure platform, but I was unable to find the details or get where the error is coming from...

Figure 3: AppInsights Error panel

Code Overview

public async Task OnTurnAsync(ITurnContext turnContext, CancellationToken cancellationToken = default(CancellationToken))
    {
        bool reintentar = false;
        //tried this but didn't work
        //MicrosoftAppCredentials.TrustServiceUrl("http://botrps.azurewebsites.net");         

        //obtener el contexto de los dialogos
        var dc = await _dialogs.CreateContextAsync(turnContext, cancellationToken);

        if (turnContext.Activity.Type == ActivityTypes.Message && turnContext.Activity.From.Id != turnContext.Activity.Recipient.Id)
        {
            //bot operations on users messages
        }    

        //if active dialog
        await dc.ContinueDialogAsync(cancellationToken);

        //else, start greeting dialog
        if (turnContext.Activity.Type == ActivityTypes.ConversationUpdate &&
            turnContext.Activity.MembersAdded[0].Id != turnContext.Activity.Recipient.Id)
        {
            await dc.BeginDialogAsync("dialogo", null, cancellationToken);
        }

        await _accessors.ConversationState.SaveChangesAsync(turnContext, false, cancellationToken);

        // Guarda los cambios realizados en el Contexto, si hay alguno
        await _accessors.UserState.SaveChangesAsync(turnContext, false, cancellationToken);
    }

Solution

  • As said by tdurnford in the comment section, it was necessary to add to the .bot configuration the production enpoint service. The resulting bot file:

    {
      "name": "BotMod2",
      "services": [
        {
          "type": "endpoint",
          "name": "development",
          "endpoint": "http://localhost:3978/api/messages",
          "appId": "",
          "appPassword": "",
          "id": "1"
        },
        {
          "appId": "**********************",
          "appPassword": "**********************",
          "endpoint": "https://**********************.azurewebsites.net/api/messages",
          "type": "endpoint",
          "name": "production",
          "id": "2"
        },
        {
          "appId": "**********************",
          "authoringKey": "**********************",
          "version": "0.1",
          "region": "westus",
          "type": "luis",
          "name": "**********************",
          "id": "3"
        },
        {
          "type": "qna",
          "name": "**********************",
          "kbId": "**********************",
          "hostname": "https://**********************.azurewebsites.net/qnamaker",
          "endpointKey": "**********************",
          "subscriptionKey": "**********************",
          "id": "4"
        }
      ],
      "padlock": "",
      "version": "2.0"
    }