Search code examples
azurebotframework

Bot Emulator Error: POST 400 directline.postActivity


I'm trying to run a default EchoBot in the Bot Emulator, and after configuring the endpoint, AppID, and App Password, I get a POST 400 directline.postActivity error.

I'm running Bot Emulator Framework v4.4.1, and the C# v4.4.4 EchoBot sample provided by Microsoft. When I go to build the project in Visual Studio, it outputs to port 3978 on localhost. After entering the endpoint, id, and password into the emulator, it begins to connect. However, the bot doesn't respond to any inputted text. Here is the log from the emulator:

[11:05:36]Emulator listening on http://localhost:50550
[11:05:36]ngrok not configured (only needed when connecting to remotely     hosted bots)
[11:05:36]Connecting to bots hosted remotely
[11:05:36]Edit ngrok settings
[11:05:37]
[11:05:37]POSTdirectline.conversationUpdate
[11:05:37]
[11:05:37]POSTdirectline.conversationUpdate
[11:05:37]POST200directline.startConversation
[11:05:40]-> messagehell0
[11:05:40]POST400directline.postActivity
[11:05:43]-> messagefdal
[11:05:43]POST400directline.postActivity

JSON Inspector for startConversation: 
{
  "conversationId": "33eb05b0-8b91-11e9-be8e-6726cb4f7972|livechat",
  "expires_in": 2147483647,
  "streamUrl": "",
  "token": "http://localhost:3978"
}

JSON Inspector for first message:
{
  "channelData": {
    "clientActivityID": "15601791407590.8nf8jwqjc2v"
  },
  "channelId": "emulator",
  "conversation": {
    "id": "33eb05b0-8b91-11e9-be8e-6726cb4f7972|livechat"
   },
  "entities": [
    {
      "requiresBotState": true,
      "supportsListening": true,
      "supportsTts": true,
      "type": "ClientCapabilities"
    }
  ],
  "from": {
    "id": "4866b179-bf7b-460e-8903-bda849861d88",
    "name": "User",
    "role": "user"
  },
  "id": "363766b0-8b91-11e9-be8e-6726cb4f7972",
  "localTimestamp": "2019-06-10T11:05:40-04:00",
  "locale": "en-US",
  "recipient": {
    "id": "33ea6970-8b91-11e9-ab08-9bfc690fe455",
    "name": "Bot",
    "role": "bot"
  },
  "serviceUrl": "http://localhost:50550",
  "text": "hell0",
  "textFormat": "plain",
  "timestamp": "2019-06-10T15:05:40.763Z",
  "type": "message"
}

JSON Inspector for first response:
{
  "channelData": {
    "clientActivityID": "15601791407590.8nf8jwqjc2v"
  },
  "channelId": "webchat",
  "entities": [
    {
      "requiresBotState": true,
      "supportsListening": true,
      "supportsTts": true,
      "type": "ClientCapabilities"
    }
  ],
  "from": {
    "id": "4866b179-bf7b-460e-8903-bda849861d88",
    "name": "User",
    "role": "user"
  },
  "locale": "en-US",
  "text": "hell0",
  "textFormat": "plain",
  "timestamp": "2019-06-10T15:05:40.760Z",
  "type": "message"
}

{
  "error": {
    "code": "ServiceError",
    "message": "response.text is not a function"
  }
}

I've tried having a configured endpoint that matches what the emulator states it is configured to, but that only results in an infinite connecting message that doesn't even allow me to input any text to the bot. I've also tried reinstalling the emulator, but that has not changed anything.

EDITED

Also, the emulator is configured to bypass ngrok for local addresses, and the local override is set to localhost. These are the default settings, and toggling the bypass option or changing the local override does not solve the problem.

I've tried getting ride of the AppId and AppPassword from the appsettings.json file, both by commenting them out and by leaving them as empty strings, neither of which solved the problem.

I've also uninstalled and reinstalled Visual Studio, the BotFramework SDK, the template, and the Bot Emulator to see if that would fix anything, but they have not..

One final note, I've tried following the Microsoft BotFramework tutorial about using the emulator, and any attempt yields this result.

UPDATE

After reinstalling Bot Framework Emulator v4.4.2, the problem is still there, but there is a new error message:

[14:03:32]Emulator listening on http://localhost:61486
[14:03:32]ngrok not configured (only needed when connecting to remotely 
hosted bots)
[14:03:32]Connecting to bots hosted remotely
[14:03:32]Edit ngrok settings
[14:03:32]The bot's Microsoft App Id or Microsoft App Password is 
incorrect.
[14:03:32]POSTdirectline.conversationUpdate
[14:03:32]The bot's Microsoft App Id or Microsoft App Password is 
incorrect.
[14:03:32]POSTdirectline.conversationUpdate
[14:03:32]POST200directline.startConversation

I have made sure that they do indeed match, yet I still get this error.


Solution

  • Are you behind a proxy ? I have the exact same problem. I am behind a proxy server . The same code works really well on my mac at home. But on a Windows PC at work it doesnt. I dont know if this helps ! I think the error is generic but the bottomline is that it is unable to fetch a JWTToken from login.microsoftonline.com.