botframework-sdk icon indicating copy to clipboard operation
botframework-sdk copied to clipboard

BotError : Failed to send activity: bot returned an error. httpStatusCode: 500

Open tinuCoder opened this issue 8 years ago • 18 comments

Bot Info

SDK Platform: .NET SDK Version: 3.12.2.4 Emulator Version: 3.5.35 Active Channels: Directline v3

Issue Description

calls made to https://directline.botframework.com/v3/directline/conversations/conversationId/activities is providing error code 502(Bad gateway)

image

image

Code Example

    BotChat.App({
        botConnection: botapp.botConnection,
        user: botapp.user,
        bot: bot,
        resize: 'detect'
    }, document.getElementById("divbot"));

Reproduction Steps

trying to test the service from rest client (postman)

  1. Generating Token from "https://directline.botframework.com/v3/directline/tokens/generate"
  2. Passing the generated token in "https://directline.botframework.com/v3/directline/conversations"
  3. Passing the generated conversationId from step2 in "https://directline.botframework.com/v3/directline/conversations/conversationId/activities" The output result is

image

Expected Behavior

It should give 200 ok

Actual Results

image

community need your expert advice on this. In real tight schedule to deliver this chunk. Need your support.

tinuCoder avatar Feb 12 '18 11:02 tinuCoder

@pankajdmishra Please post the code example, not images of the code.

EricDahlvang avatar Feb 12 '18 19:02 EricDahlvang

I am facing similar error. Just hosted the sample bot framework code on azure and worked on direct line api. Doesn't work.

shahsaurabh0605 avatar Feb 12 '18 20:02 shahsaurabh0605

@shahsaurabh0605 What exactly "doesn't work"? Please be more specific, and explain the errors or issues you've run into so we can assist you.

EricDahlvang avatar Feb 12 '18 20:02 EricDahlvang

Issue is clearly mentioned by @pankajdmishra . I follow the 3 steps:

  1. Generating Token from "https://directline.botframework.com/v3/directline/tokens/generate"
  2. Passing the generated token in "https://directline.botframework.com/v3/directline/conversations"
  3. Passing the generated conversationId from step2 in "https://directline.botframework.com/v3/directline/conversations/conversationId/activities"

And get the similar error on postman:

36095200-a9488d86-100a-11e8-9270-391923caa260

shahsaurabh0605 avatar Feb 12 '18 20:02 shahsaurabh0605

  1. Generate a Token from https://directline.botframework.com/v3/directline/tokens/generate

image

  1. Passing the generated token in https://directline.botframework.com/v3/directline/conversations

image

  1. Passing the generated conversationId from step2 in https://directline.botframework.com/v3/directline/conversations/conversationId/activities

image

EricDahlvang avatar Feb 12 '18 21:02 EricDahlvang

I've seen the BotError before, but only if the bot is not actually running at the Messaging Endpoint:

image

EricDahlvang avatar Feb 12 '18 21:02 EricDahlvang

I have hosted the bot on azure, say with the name "x-bot". Then is "https://x-bot.azurewebsites.net/api/messages" the correct messaging endpoint setup?

shahsaurabh0605 avatar Feb 12 '18 22:02 shahsaurabh0605

@shahsaurabh0605 Yes, that would most likely be the correct endpoint

EricDahlvang avatar Feb 12 '18 22:02 EricDahlvang

Also if you'll see on portal upon checking the channels for direct line its showing errors PFB

image

@EricDahlvang need your expert advice here....

tinuCoder avatar Feb 13 '18 05:02 tinuCoder

@pankajdmishra I'm sorry, but I'm not really understanding what you are attempting to do. If you are experiencing errors in your bots code, you can try debugging the bot locally: https://blog.botframework.com/2017/10/19/debug-channel-locally-using-ngrok/

Also, please try starting with one of the simple samples: https://github.com/Microsoft/BotBuilder-Samples Once you have a working example, you can build on it.

EricDahlvang avatar Feb 13 '18 18:02 EricDahlvang

Hi @shahsaurabh0605 Were you able to resolve this in any case?

tinuCoder avatar Feb 15 '18 05:02 tinuCoder

@pankajdmishra yes. Actual problem was not setting the correct endpoint. I hosted the bot on localhost and with ngrok got the correct endpoint. Refer here:- https://blogs.msdn.microsoft.com/jamiedalton/2016/07/29/ms-bot-framework-ngrok/

Thanks a lot @EricDahlvang

shahsaurabh0605 avatar Feb 15 '18 05:02 shahsaurabh0605

@pankajdmishra The code you've provided in HandleUserMessage should function, if your bot is configured properly. I just tested it, and it worked.

As I had suggested previously, please try debugging locally: https://blog.botframework.com/2017/10/19/debug-channel-locally-using-ngrok/

Also, please try starting with one of the simple samples: https://github.com/Microsoft/BotBuilder-Samples. Once you have a working example, you can build on it.

EricDahlvang avatar Feb 19 '18 18:02 EricDahlvang

Hi @EricDahlvang

Thanks alot. I tried debugging my code using ngrok. Steps i performed using ngrok are as below

  1. I executed ngrok cmd
  2. runned following command (ngrok http 3979 -host-header="localhost:3979")
  3. got a forwarding uri. I changed my endpoint on azure portal with this forwarding URI pfb. image
  4. I runned my code locally in debug mode.
  5. Using webchat control from, azure portal i posted few queries and it worked fine. I got expected response when i used ngrok for debugging.

there was no failure. Now the question is, was there a issue with my endpoint? below screen shots shows configuration of my bot.

image This is the service URL for my bot app.

image this is my BotId

Endpoint that i previously had before ngrok was https://sofeachatbot-stage.azurewebsites.net/api/messages

was this endpoint correct? If not than how to rectify which is the correct endpoint to configure?

Thanks in advance.

tinuCoder avatar Feb 21 '18 12:02 tinuCoder

Hi,

I resolved this issue. Very stupid mistake done by me. While creating the bot i changed Password from WebAppBot --> Settings, "manage" PFB


image

And didn't updated the App service of the bot with the new password. In App service of your bot App Service --> Application settings change the password as well. PFB


image

Else this will always through 502 error.

Thanks alot @EricDahlvang and @shahsaurabh0605 for all your support.

Appreciated 👍

Closing this issue

tinuCoder avatar Feb 25 '18 10:02 tinuCoder

@tinuCoder @EricDahlvang Even after updating the MicrosoftAppPassword in Application Settings of App service, I am still having this issue. In postman, { "error": { "code": "BotError", "message": "Failed to send activity: bot returned an error" }, "httpStatusCode": 417 }

And, the Status in postman is : 502 Bad Gateway

klamgade avatar Jan 04 '19 03:01 klamgade

1. Generate a Token from https://directline.botframework.com/v3/directline/tokens/generate

image

1. Passing the generated token in https://directline.botframework.com/v3/directline/conversations

image

1. Passing the generated conversationId from step2 in https://directline.botframework.com/v3/directline/conversations/conversationId/activities

image

Hello @EricDahlvang i am following the exact steps that you pointed out.

  1. running locally developed with v4 sdk
  2. Bot connector service configured with the ngrok fwrd url
  3. have a directline channel configured
  4. successfully getting the token and conversationid, with the exception that conversation id is always appended with a -c. example :

{
    "conversationId": "JQfgEvc7if86Qt1CwuV414-c",
    "token": "token that was returned",
    "expires_in": 1800,
    "streamUrl": "wss://directline.botframework.com/v3/directline/conversations/JQfgEvc7if86Qt1CwuV414-c/stream?watermark=-&t=GaM9ExIOdJk.dAA.SgBRAGYAZwBFAHYAYwA3AGkAZgA4ADYAUQB0ADEAQwB3AHUAVgA0ADEANAAtAGMA.eIj5E3vp1AE.GEB8PJfGae4.5rT75D232c9Ht5wDOpuNT5LlEUmvhuLXkqnxUnLRCsU",
    "referenceGrammarId": "88a91a98-2ddc-8a5d-ab4d-f76f2b5c876c"
}
  1. When i execute following https://directline.botframework.com/v3/directline/conversations/JQfgEvc7if86Qt1CwuV414-c/activities i always get internal server error
{
  "error": {
    "code": "ServiceError"
  }
}

Following is my request object

{
    "type": "message",
    "from": {
        "id": "user1"
    },
    "text": "hello"
}

Please help me identify the issue.

Thanks, Prerak

pkaushik23 avatar Apr 02 '19 17:04 pkaushik23

For anyone else facing the same issue, here is the advice. The issue is, only the token which was received against 'start conversation' can be used to 'send an activity'. refer this SO answer and read Q3

Thanks.

pkaushik23 avatar Apr 02 '19 18:04 pkaushik23