microsoft / BotFramework-Services

Microsoft Bot Framework Services
Creative Commons Attribution 4.0 International
38 stars 11 forks source link

Facebook channel creating internal server HTTP 500 error #93

Closed seanbetts closed 5 years ago

seanbetts commented 5 years ago

BotFramework Version: 4.4 in JavaScript

Bug Description

When connecting to my chatbot using Facebook Messenger, it's generating an internal server HTTP 500 error. This happens whenever a message is sent from Facebook Messenger (i.e. received by the chatbot).

Steps to Reproduce

  1. Connect to chatbot from Facebook Messenger
  2. Inspect log files

Actual Experience

The chatbot works as expected but the error message is appearing in the log files and shows up as an issue in the Facebook channel in the Azure portal.

Additional Context

Here are the error details:

[onTurnError]: TypeError: Cannot read property 'role' of undefined BotFrameworkAdapter.processActivity(): 500 ERROR - Error: BotFrameworkAdapter.sendActivity(): missing conversation id.<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">IIS Detailed Error - 500.0 - Internal Server Error

HTTP Error 500.0 - Internal Server Error

The page cannot be displayed because an internal server error has occurred.

Most likely causes:

  • IIS received the request; however, an internal error occurred during the processing of the request. The root cause of this error depends on which module handles the request and what was happening in the worker process when this error occurred.
  • IIS was not able to access the web.config file for the Web site or application. This can occur if the NTFS permissions are set incorrectly.
  • IIS was not able to process configuration for the Web site or application.
  • The authenticated user does not have permission to use this DLL.
  • The request is mapped to a managed handler but the .NET Extensibility Feature is not installed.

Things you can try:

  • Ensure that the NTFS permissions for the web.config file are correct and allow access to the Web server's machine account.
  • Check the event logs to see if any additional information was logged.
  • Verify the permissions for the DLL.
  • Install the .NET Extensibility feature if the request is mapped to a managed handler.
  • Create a tracing rule to track failed requests for this HTTP status code. For more information about creating a tracing rule for failed requests, click here.

Detailed Error Information:

Module   iisnode
Notification   ExecuteRequestHandler
Handler   iisnode
Error Code   0x00000000
Requested URL   https://mihndbotdev:80/index.js
Physical Path   D:\home\site\wwwroot\index.js
Logon Method   Anonymous
Logon User   Anonymous

More Information:

This error means that there was a problem while processing the request. The request was received by the Web server, but during processing a fatal error occurred, causing the 500 error.

View more information »

Microsoft Knowledge Base Articles:

stevkan commented 5 years ago

Hi @seanbetts, are you able to post what the activity looks like that is being received by the bot? Also, has your bot been working fine under Facebook and only recently produced this error? Or, did you recently build it out for FB?

seanbetts commented 5 years ago

Hi @stevkan. My bot has been working fine under Facebook until recently. Here's an example of the activity that is bing received by the bot:

var welcomeCardFB = {
    channelData: {
        attachment: {
            type: 'template',
            payload: {
                template_type: 'generic',
                sharable: true,
                image_aspect_ratio: 'square',
                elements: [
                    {
                        title: '👋 Hello ' + userName + '!',
                        image_url: 'https://mihndbotblob.blob.core.windows.net/resources/MiHNDbot-logo.jpg',
                        subtitle: "I'm designed to help people learn about Mental Health and NeuroDiversity",
                        default_action: {
                            type: 'web_url',
                            url: 'https://www.mihnd.co.uk',
                            webview_height_ratio: 'tall'
                        },
                        buttons: [
                            {
                                type: 'postback',
                                title: 'Mental Health',
                                payload: 'WHAT_IS_MENTAL_HEALTH'
                            }, {
                                type: 'postback',
                                title: 'NeuroDiversity',
                                payload: 'WHAT_IS_NEURODIVERSITY'
                            }, {
                                type: 'postback',
                                title: 'Get Help',
                                payload: 'GET_HELP'
                            }] }] } } } };

return welcomeCardFB;
};`
stevkan commented 5 years ago

Apologies for the delay. I'm assuming you are sending that card from the bot? Can you capture and post an actual activity object? Also, do you have a date and time when this error occurred?

I should add that a 500 error usually denotes a problem with the bot's code.

stevkan commented 5 years ago

So, I recreated the card and received it back as an activity which I have included below. The conversation id is normally recorded under conversation and the role under recipient. For one reason or another, I suspect your bot lost the context and, subsequently, didn't have an id which meant it couldn't apply a value to role. This resulted in the the error detailing your missing conversation id and undefined role.

If you can provide the date/time of the error, I can try and see if there was a service hiccup at that time that might have resulted in your bot failing. But, again, 500 errors are usually internal related.

{
  "direction": "incoming",
  "activity": {
    "channelData": {
      "attachment": {
        "type": "template",
        "payload": {
          "template_type": "generic",
          "sharable": true,
          "image_aspect_ratio": "square",
          "elements": [
            {
              "title": "👋 Hello Steve!",
              "image_url": "https://mihndbotblob.blob.core.windows.net/resources/MiHNDbot-logo.jpg",
              "subtitle": "I'm designed to help people learn about Mental Health and NeuroDiversity",
              "default_action": {
                "type": "web_url",
                "url": "https://www.mihnd.co.uk",
                "webview_height_ratio": "tall"
              },
              "buttons": [
                {
                  "type": "postback",
                  "title": "Mental Health",
                  "payload": "WHAT_IS_MENTAL_HEALTH"
                },
                {
                  "type": "postback",
                  "title": "NeuroDiversity",
                  "payload": "WHAT_IS_NEURODIVERSITY"
                },
                {
                  "type": "postback",
                  "title": "Get Help",
                  "payload": "GET_HELP"
                }
              ]
            }
          ]
        }
      }
    },
    "channelId": "facebook",
    "serviceUrl": "https://facebook.botframework.com/",
    "conversation": {
      "isGroup": false,
      "id": "15196xxxxxxxxx37873"
    },
    "from": {
      "id": "2050867055237873",
      "name": "v-xxxxxxxxx-bot"
    },
    "recipient": {
      "id": "1519649474831492",
      "name": "Steve",
      "role": "user"
    },
    "replyToId": xxxxxxxxx",
    "type": "message",
    "timestamp": "2019-08-09T00:08:03.517Z"
  }
}
seanbetts commented 5 years ago

Hi @stevkan, thanks for getting back to me. The error was being caused by an issue with my Facebook credentials and it’s all fixed now! Sorry, I should have closed the ticket earlier.