[Question] Why am I getting error: "There was an error sending this message to your bot: HTTP status code GatewayTimeout"?
See original GitHub issueBot Info
- Bot handle: sbcbot
- App ID: 5b1d7f0b-6905-4afa-a8a7-ada6e5fc4284
- SDK Platform: .NET
- Active Channels: Skype, Web chat
- Deployment Environment: IIS
Issue Description
I have developed a bot which is using the qna maker to answer some questions. I have deployed it on the IIS server. But when I try to chat with it on the bot framework’s web chat it says “couldn’t send retry”, with issue “There was an error sending this message to your bot: HTTP status code InternalServerError”. the bot works perfectly on localhost without the MAID and Password, but doesn’t work with them in the Webconfig. I’ve tried validating the credentials using curl, and they are correct. I am not able to use ngrok as it gives me an error “Failed to start ngrok: panic: runtime error: invalid memory address or nil pointer dereference…”. It doesn’t give any reply on skype chat as well. My SDK and emulator are up to date. I doubt there is something wrong with the settings in the IIS, but there are no turorials/blogs that can show the whole process step by step. This is an issue as I am new to IIS. Any help would be really appreciated. Additionally, I have added “POST” verb to the website.
Code Example
I am not sure if there’s something wrong with my code, but here’s the main part
public class MessagesController : ApiController
{
public async Task<HttpResponseMessage> Post([FromBody]Activity activity)
{
if (activity.Type == ActivityTypes.Message)
{
ConnectorClient connector = new ConnectorClient(new Uri(activity.ServiceUrl));
var responseString = String.Empty;
var responseMsg = "";
//De-serialize the response
QnAMakerResult QnAresponse;
// Send question to API QnA bot
if (activity.Text.Length > 0)
{
var query = "hi"; //User Query
var knowledgebaseId = "knowledge base id created";
var qnamakerSubscriptionKey = "subscription key";
//Build the URI
Uri qnamakerUriBase = new Uri("https://westus.api.cognitive.microsoft.com/qnamaker/v1.0");
var builder = new UriBuilder($"{qnamakerUriBase}/knowledgebases/{knowledgebaseId}/generateAnswer");
//Add the question as part of the body
var postBody = $"{{\"question\": \"{activity.Text}\"}}";
//Send the POST request
using (WebClient client = new WebClient())
{
//Set the encoding to UTF8
client.Encoding = System.Text.Encoding.UTF8;
//Add the subscription key header
client.Headers.Add("Ocp-Apim-Subscription-Key", qnamakerSubscriptionKey);
client.Headers.Add("Content-Type", "application/json");
responseString = client.UploadString(builder.Uri, postBody);
}
try
{
QnAresponse = JsonConvert.DeserializeObject<QnAMakerResult>(responseString);
responseMsg = QnAresponse.Answer;
}
catch
{
throw new Exception("Unable to deserialize QnA Maker response string.");
}
}
// return our reply to the user
if (responseMsg == Convert.ToString("No good match found in the KB"))
{
await Conversation.SendAsync(activity, () => new Dialogs.RootDialog());
}
else
{
Activity reply = activity.CreateReply(responseMsg);
await connector.Conversations.ReplyToActivityAsync(reply);
}
}
else
{
HandleSystemMessage(activity);
}
var response = Request.CreateResponse(HttpStatusCode.OK);
return response;
}
private Activity HandleSystemMessage(Activity message)
{
if (message.Type == ActivityTypes.DeleteUserData)
{
// Implement user deletion here
// If we handle user deletion, return a real message
}
else if (message.Type == ActivityTypes.ConversationUpdate)
{
// Handle conversation state changes, like members being added and removed
// Use Activity.MembersAdded and Activity.MembersRemoved and Activity.Action for info
// Not available in all channels
}
else if (message.Type == ActivityTypes.ContactRelationUpdate)
{
// Handle add/remove from contact lists
// Activity.From + Activity.Action represent what happened
}
else if (message.Type == ActivityTypes.Typing)
{
// Handle knowing tha the user is typing
}
else if (message.Type == ActivityTypes.Ping)
{
}
return null;
}
}
Expected Behavior
When the user starts conversation by typing “Hi”, the bot should post a reply.
Issue Analytics
- State:
- Created 6 years ago
- Comments:7 (3 by maintainers)
I see you’re using the connector client to send a reply. Try calling
MicrosoftAppCredentials.TrustServiceUrl(activity.ServiceUrl);
beforeconnector.Conversations.ReplyToActivityAsync(..)
What error occurs when the appid and password are in the webconfig?
For the ngrok issue, how are you starting ngrok? Does it work from the command line? https://github.com/Microsoft/BotFramework-Emulator/issues/301
@EricDahlvang Hi, I tried the above command in ngrok, but still shows an error in the session status. It keeps looping between the messages “reconnecting (x509: certificate signed by unknown authority)”, “reconnecting (invalid character ‘<’ looking for beginning of value)”, and “reconnecting (dial tcp [2600:1f16:59e:b200:21d7:7eb7:fd6f:f0a9]:443: connectex: A socket operation was attempted to an unreachable network.)”.