I have a bot deployed on Azure using Bot Framework. Nothing was changed on the code. But today the bot became completely unresponsive. Any message I try to send results invariably in a "Couldn't Send. Retry?" message. Occasionally in past I could see the bot was slower to reply to one or other message, but this time is a different thing, the bot is completely mute. On inspecting the issues for web chat channel on azure dashboard I can see that the errors are all the same "There was an error sending this message to your bot: HTTP status code GatewayTimeout". What may I be doing wrong?
Just in case it is relevant, the bot uses LUIS services and also a database both deployed in azure. Tried to access these services separately and they are working fine with good response time. Anyway, I don't think the bot program reaches the point of trying to communicate with any of them. I doesn't even reach the first IDialogContext.PostAsync() which is the very first instruction on the StartAsync() method in the root dialog. Help with this much appreciated
the errors are all the same "There was an error sending this message to your bot: HTTP status code GatewayTimeout". What may I be doing wrong?
Firstly, I do a test with the following sample, and if the request take a long time to get response, which might cause " Gateway Timeout" issue. You can turn on Application Insights with your bot application to trace the request(s) sent from your bot, and check if some requests take too long time.
Example:
private async Task MessageReceivedAsync(IDialogContext context, IAwaitable<object> result)
{
var activity = await result as Activity;
// calculate something for us to return
int length = (activity.Text ?? string.Empty).Length;
if (activity.Text.ToLower().Contains("timeout test"))
{
HttpWebRequest request = (HttpWebRequest)WebRequest.Create("http://xxxxx/api/values/xxx");
request.Method = "GET";
request.ContentType = "application/json";
//I set a 30s delay for returning response in my external api
var response = request.GetResponse();
string content = string.Empty;
using (var stream = response.GetResponseStream())
{
using (var sr = new StreamReader(stream))
{
content = sr.ReadToEnd();
}
}
activity.Text = content.ToString();
// return our reply to the user
await context.PostAsync($"API returned {activity.Text}");
}
else
{
// return our reply to the user
await context.PostAsync($"You sent {activity.Text} which was {length} characters");
}
context.Wait(MessageReceivedAsync);
}
Test result:
Secondly, if your Bot Service pricing tier is free, please check if your bot service reached 10,000 messages/month limit (for Premium channels). In this SO thread, another community member reported reaching that limit would cause " Gateway Timeout" error.
Besides, if possible, you can create a new bot service on Azure portal and then publish your bot application to that corresponding new Azure web app that you specified as messaging endpoint, and check if your bot app can work as expected on new Azure environment.
Note:
I also checked the status history of Azure services and found:
6/27 RCA - App Service - West Europe
Summary of impact: Between 16:00 UTC on 27 Jun 2018 and 13:00 UTC on 28 Jun 2018, a subset of customers using App Service in West Europe may have received HTTP 500-level response codes, timeouts or high latency when accessing App Service (Web, Mobile and API Apps) deployments hosted in this region.
6/25 RCA - Multiple Services - South Central US
Summary of impact: Between 19:40 and 20:52 UTC on 25 Jun 2018, a subset of customers in South Central US may have experienced difficulties connecting to resources and/or 500-level errors hosted in this region. Virtual Machines may have rebooted unexpectedly. Impacted services included: Storage, Virtual Machines, Key Vault, Site Recovery, Machine Learning, Cloud Shell, Logic Apps, Redis Cache, Visual Studio Team Services, Service Bus, ExpressRoute, Application Insights, Backup, Networking, API Management, App Service (Linux) and App Service.
Not sure if above issue causes the problem, if you tried all approaches that you can do to troubleshoot the issue, but the issue with your bot service is still not mitigated, you can try to create support request to report it.
Try enabling [botauthentication] in message controller. Also try to open outgoing connection also from your IIS server to internet. By the way there can be some other problems as well like :
1)Your web.config file contains an App ID that does not match the one you posted.
2)Your server's time is incorrect. Tokens have 20 minutes of validity (5 minutes before the token was issued and 15 minutes after.) Is it possible your server time is different?
3)Your bot encountered a problem retrieving list of signing keys. Check to make sure you can access these URLs:
https://api.aps.skype.com/v1/keys
https://login.botframework.com/v1/.well-known/keys
You can also follow this issue to check if you're doing it correctly https://github.com/Microsoft/BotBuilder/issues/4389
Related
There is one requirement to send an email upon unsuccessful web-jobs only. There are 16 web-jobs which are deployed and running successfully on azure portal. I have suggested to modify the code for existing web-job but client does not want to modify web-jobs. He wants to add something extra which does not require to modify web-jobs anymore. I am confused, without modifying web-jobs, how can I send an email? I searched a lot on google and stack-overflow but didn't get anything.
How can I implement this?
Few of the workarounds for getting the notification to email for WebJobs Status:
Using ErroTrigger and SendGrid extensions. you can do the Notifications sending to email for the WebJob SDK.
check this article on how to set that up which uses both extensions to send an email if an error occurred 10 times in 30 minutes window with a throttle up to 1 hour.
public static void ErrorMonitor(
[ErrorTrigger("0:30:00", 10, Throttle = "1:00:00") TraceFilter filter,
[SendGrid] SendGridMessage message)
{
message.Subject = "WebJobs Error Alert";
message.Text = filter.GetDetailedMessage(5)
}
If you aren't using the WebJob SDK, then unfortunately there aren't any events for continuous webjobs. There is only one for triggered jobs.
Also, visit this MSFT Doc and SO Thread for information on setting up the email alerts with App Services.
I have created one Node.Js application and I am using Azure application insights in it. Code is very simple. I have started app insights on top of app.js
const appInsights = require('applicationinsights');
appInsights.setup('instrument-key-here');
appInsights.defaultClient.commonProperties = {
'appName': 'Name-Of-MS'
};
appInsights.start();
import express from 'express';
I am able to see telemetry data in azure but the problem I deploy the application on the dev server (Linux)...run my application through PM2.. then I am seeing a huge volume of failed request in the portal as well.. approx 100k, 404 requests are being logged and these are not proper HTTP calls. When I detail in the portal all I see is the request URL https:/3dspace/F5Health.html .. that's it.
Below are details, I am seeing in the portal
Event time 1/24/2021, 4:48:53 PM (Local time)
Request name GET /3dspace/F5Health.html
Response code 404
Successful request false
Response time 1 ms
Request URL https:/3dspace/F5Health.html
Request Id 3e5b5c01556b9
Performance <250ms
Telemetry type request
Operation name GET /3dspace/F5Health.html
Operation Id 984d066c7222428c896260ea2e5
Parent Id 984d066c7222428c8962a0ea2e5
Application version 0.0.1
Device type PC
Operating system Linux 3.10.0-1160.6.1.el7.x86_64
Client IP address 0.0.0.0
Cloud role name Web
Cloud role instance servername.com
SDK version node:1.8.9
Sample rate 1
I am sure from where this request is being logged but it is creating a huge volume of 404 requests with the same param.
Anyone faced a similar issue. How Can I find out from where this request is being logged?
My web application is deployed in azure, which is implemented in Asp.Net Core. I want to throttle requests basing on cpu/memory/network usage percentage. For example, when the cpu usage is above 90%, the throttling component will throttle 50% of the requests.
The big question is:
How to get cpu/memory/network usage percentage in ASP.NET Core?
As far as I know, azure WebApp is a sandbox, we don't have enough permission to access the Azure web app's worker server's metrics.
The user account must either be a member of the Administrators group or a member of the Performance Monitor Users group in Windows.
Here is a workaround, we could enable the application Insight to do that. We need to configurate Application Insight for Azure WebApp. Details, you could refer to this doc.
We could use Application Insight rest api to get the current web app's metrics like process cpu usage. API Document.
We could get the application id and api key in the Application Insight portal like below image shows:
Details, you could refer to this article.
Then you could use below codes to send request to Application Insight API to get current CPU usage.
public static string GetTelemetry(string appid, string apikey)
{
string Url = "https://api.applicationinsights.io/v1/apps/{0}/metrics/performanceCounters/processCpuPercentage";
HttpClient client = new HttpClient();
client.DefaultRequestHeaders.Accept.Add(
new MediaTypeWithQualityHeaderValue("application/json"));
client.DefaultRequestHeaders.Add("x-api-key", apikey);
var req = string.Format(Url, appid);
HttpResponseMessage response = client.GetAsync(req).Result;
if (response.IsSuccessStatusCode)
{
return response.Content.ReadAsStringAsync().Result;
}
else
{
return response.ReasonPhrase;
}
}
Result:
I have deployed a chatbot with LUIS and QnA Maker. It works perfectly locally when I run it on Emulator. It loads up the adaptive cards at start of the chat and I get correct replies from LUIS.
However when I deploy the bot on Azure and test it on Web chat it gives the following error:
There was an error sending this message to your bot: HTTP status code InternalServerError
This is how my web.config looks like:
<configuration>
<appSettings>
<!-- update these with your BotId, Microsoft App Id and your Microsoft App Password-->
<add key="BotId" value="BotLuis" />
<add key="MicrosoftAppId" value="9f9564ef-d627-450f-b943-98b7338c0f31" />
<add key="MicrosoftAppPassword" value="myapp-password" />
</appSettings>
I get the values for AppID and AppPassword from the Applications setting of the web bot I created on Azure. I know they are correct since I used these values to setup locally using Emulator.
I deploy the code from github to Azure. My bot loads up just fine (The adaptive cards show) on azure web chat but after that any input I give to it, whether it is interactive card or chat command, I get the above error.
The application Insight shows the following exception:
POST to BotLuis failed: POST to the bot's endpoint failed with HTTP status 500
Problem Id:System.Exception at Microsoft.Bot.ChannelConnector.BotAPI+d__31.MoveNext
The developers tool console shows this when I interact with the bot:
https://webchat.botframework.com/v3/directline/conversations/3NgflndFbpzCRDtnMdZpjf-g/activities 502 (Bad Gateway)
if you paste the above link in a browser this is what you will get:
{
"error": {
"code": "BadArgument",
"message": "Missing token or secret"
}
}
I am lost at this point. I can understand the problem but I don't know how to go forward. Am I supposed to add the messaging endpoint of my bot in my code somewhere?
A link to github repo of the code:here
Bot State Service retired on March 31st, 2018.
Therefore your sample is missing state storage when you run it on Azure, while it will work locally.
To make your sample work, simply add the following lines to your Global.asax.csfile.
protected void Application_Start()
{
RegisterBotDependencies();
GlobalConfiguration.Configure(WebApiConfig.Register);
var store = new InMemoryDataStore();
Conversation.UpdateContainer(
builder =>
{
builder.Register(c => store)
.Keyed<IBotDataStore<BotData>>(AzureModule.Key_DataStore)
.AsSelf()
.SingleInstance();
builder.Register(c => new CachingBotDataStore(store,
CachingBotDataStoreConsistencyPolicy
.ETagBasedConsistency))
.As<IBotDataStore<BotData>>()
.AsSelf()
.InstancePerLifetimeScope();
});
}
Please note that this sample uses InMemory storage and is therefore not intended for production use. Following the blog post, you can easily switch over to Azure Table storage or CosmosDB.
I've cloned your repository, added these lines of code and deployed it to a new bot instance on Azure. Webchat test was successful.
Summary
Taken from above blog post.
We’ve been encouraging bot developers using the Bot Framework to use their own custom state service for a while. The default Bot Framework State service was intended for prototyping purposes only, and not designed to accommodate production bots. The state service will be deprecated on March 31, 2018 and will no longer be supported. Bot developers moving forward will be able to prototype their bots using temporary local memory storage as described in this article. Creating your own custom state service for your bot provides multiple benefits including improved latency and direct control over your bot’s conversation state and contextual user conversation state information, and we’ve provided multiple resources to guide you to do so. We appreciate the feedback we’ve been receiving from the bot developer community, which has helped us a lot in improving the Bot Framework as a whole. We also hope that we can continue helping you – the bot developer community, create better and better bot experiences for your users.
I created an app in Xamarin.Forms (Android + iOS) I want to send push notifications to.
My goal is to send single notifications from a backend c# desktop application, and have my notifications pushed to both Android and iOS devices.
To do this I'm going to use Azure Notification Hubs.
In the first stage I'm focusing on pushing notificatins to Android devices, so I followed these steps:
I created a Firebase account and registered my application.
I added code to receive notifications in my app.
I created an Azure account.
I created a Notification Hub in Azure.
I inserted my server key in GCM/FCM settings.
I created my backend.
Backend code:
private async void Send()
{
var msg = "Test message " + DateTime.Now.ToLongTimeString();
var url = "http://www.google.com";
string notificationHubName = "MyNotificationHub";
string notificationHubConnection = "Endpoint=sb://xxxxxxx.servicebus.windows.net/;SharedAccessKeyName=DefaultFullSharedAccessSignature;SharedAccessKey=xxxxxxxxxxx";
NotificationHubClient hub = NotificationHubClient.CreateClientFromConnectionString(notificationHubConnection, notificationHubName);
Dictionary<string, string> templateParams = new Dictionary<string, string>();
templateParams["messageParam"] = msg;
templateParams["urlParam"] = url;
try
{
var result = await hub.SendTemplateNotificationAsync(templateParams);
MessageBox.Show(this, "OK.", "Test message", MessageBoxButtons.OK, MessageBoxIcon.Information);
}
catch (System.Exception ex)
{
MessageBox.Show(this, "Exception: " + ex.Message + "." , "Test Message", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
This code is working and notifications are pushed to my Android devices.
Unfortunately, it seems that Azure still uses GCM instead of FCM to deliver notifications.
I received the following mail from Google:
Final reminder: Upgrade GCM to Firebase Cloud Messaging by May 29
Hi Roberto, You are receiving this message because you are an owner of a Firebase project that sent a message via the Google Cloud Messaging (GCM) endpoint in the last 28 days. Last year we announced that the GCM server and client APIs are deprecated. To prevent a disruption in your service, you must redirect your Cloud Messaging server requests to the Firebase Cloud Messaging (FCM) endpoint at fcm.googleapis.com/fcm/ before May 29, 2019.
We also recommend that you upgrade your client SDKs from GCM to the latest version of Firebase Cloud Messaging. Although existing app installations that use GCM methods will continue to function, GCM methods will not work when your app targets future Android versions (after Android Q).
What do I need to do?
The project listed below has used GCM in the past month. To continue sending messages for this project, update server endpoints and upgrade any apps associated with this project to the FCM SDK. In some cases, the endpoints below may be hostnames that were previously deprecated. However, you should still migrate away from them by May 29, 2019.
• GXXXXXXXXXApp (gXXXXXXXXXapp): about 76 requests to android.googleapis.com in the past 28 days
Moreover, if I try to send a test message from Azure portal, this is the result:
I'm worried that after May 29 my app will stop receiving notification.
How can I force FCM instead of GCM?
Thank you!