Microsoft Bot (webchat channel): 500 Internal Server error: failed to send message - botframework

We have embedded a Bot on a web page through the web chat channel, if the Bot is idle for 10 minutes or so and then a question is asked, the Bot does not respond to it, however when the same question is asked again immediately it responds as expected.
On investigating the network capture, we observed the response received when the question was asked for the first time was 500: Internal Server Error with message as "failed to send message"

Are you running the bot in Azure? If so, make sure you have "AlwaysOn" enabled; otherwise the web app will be unloaded if it's idle for a period of time. Check this for a similar problem.
Always On. By default, web apps are unloaded if they are idle for some period of time. This lets the system conserve resources. In Basic or Standard mode, you can enable Always On to keep the app loaded all the time. If your app runs continuous web jobs, you should enable Always On, or the web jobs may not run reliably.
You can read more about the web sites configuration here.

Related

Offline-directline: My webchat app keeps sending GET requests to /directline/conversations/ endpoint. Is this normal?

I had a local bot which I wanted to test in WebChat client instead of Emulator. After researching for a while and failing to connect normally, I stumbled upon a package called offline-directline which helped me connect my local bot successfully. My directline runs on 4000, webchat runs on 3000 and local bot runs on 3979.
I took a peak in the network tab later and I see my client keeps making GET requests to /directline/conversations/ endpoint. At first I thought it happens when I am sending messages in my WebChat client but it keeps sending them repeatedly. Around 50 GET requests in a minute.
I am not sure if this is a normal behavior. Would really appreciate an input. Thank you.

Keeping the bot alive

We are building a bot using the MS Bot Framework. Sometimes when the bot is not used, it takes too much time to respond and we get a [500] Internal Server Error. We see this issue when we try to access the bot on our app (we are using Direct Line to interact with the bot).
I've read other answers about making sure the Microsoft Azure setting for application activity is set to "Always On", and we have done this. But as Always on is pinging the root of our bot web app, I think it may not be enough to keep the bot / directline alive...
And I don't have any rewrite rules from http to https preventing the ping request to be successful..
Anybody had this issue?
UPDATE to ask a specific question : How can we make sure that our bot is ALWAYS alive if all the settings explained above do not work ? Should we ping our bot thru the directline framework ?
One way to do it would be to send a ping every 15 minutes. The default code even gives you a place to handle the ping in the message controller
else if (message.Type == ActivityTypes.Ping)
{
}
please also take a look at this post as it may work for you and is a very simple solution with no code.
I had to create an azure function that pings my service, as I was having this same problem. I have Always On for all my services, and still find the bot going to sleep. With the ping service, it establishes a new conversation, sends the utterance, and then closes after receiving the response. This has seemed to work, but is only a week into practice. Note, I am pinging every five minutes.

Using SignalR to push to clients from a long running process

Firstly, here is state of my application:
I have a request coming in from a client (angularjs app) into my API (web api 2). This request is processed and a record is stored in a database. A response is then sent back to the client.
Currently, I have a windows service polling and processing this record(s).
Processing this record can be long running. As a side effect to processing this record, there might be notifications generated to be sent back to one or more clients.
My question is how do I architect this, such that I can utilise SignalR to be able to push the notifications back to the client.
My stumbling block:
I can register and store (in-memory backed by a db) the client's SignalR connectionid along with the application's own user identifier. This way I can match a generated notification with a signalr client.
At the moment, I'm hosting the SignalR hubs within the IIS process. So how do I get back from the Windows Service to IIS to notify the client when a notification is generated?
Furthermore, I should say I am already using SignalR elsewhere in the application and am using a SQL Server backplane.
The issue's with the current architecture:
Any processing is done in the same web request, and notifications are sent out via SignalR before a response to the client is returned. Luckily, the processing is minimal and very quick.
I think this is not very good in terms of performance or maintenance in the long run.
Potential solutions:
Remove SignalR hubs from IIS and host them somewhere else - windows service?
Expose an endpoint on the API to for the windows service to call to push the notification once a notification is generated?
Finally, to add more ingredients to the mix: Use a service bus to remove the polling component of the windows service, and move to a pub/sub architecture. Although this is more work than I want to chew off right now.
Any ideas/recommendations/constructive criticisms are welcome.
Thanks.
Take a look at this sample for starters
Another more advanced solution can be using a backplane to manage the communications between the front end and the backend...
HTH

Why Sagepay notification reaches some of our servers but not the others

Currently we have a few test servers which connect to test.sagepay.com to process transactions. However, on 2 of the servers, we could successfully register transactions on sagepay, but then we didn't receive any sagepay notification coming back at all. However, on different servers (running on different IP addresses), it is working perfectly fine.
I've got the error code "5006 - Unable to redirect to Vendor's web site. The Vendor failed to provide a RedirectionURL". It used to work perfectly fine on those servers, and only stopped working since last Thursday although we are sure that we didn't touch those servers during that period of time at all. Besides, we do see a few occasional notifications coming in from sage which we believe are the REPEAT notifications, not the original ones. We could see all those transactions registered on our accounts, but of course all of them are failed due to the fact that we haven't got any notification coming back.
And we also do make sure that our firewall is opened for the whole range 195.170.169.* from which we expect to receive the sage notification
So my questions are:
Does Sagepay have some sort of mechanism to block some IP addresses and stop sending back notification?
Is the Sagepay-serer which sends out original notifications different from the one that sends out Repeat notifications?
I've faced the very same issue. Our script was handing https:// address over to SagePay as a NotificationURL, but https was not setup, hence the notification script could not be reached. Once I changed to http and ensured that the notification script response is correct it worked.
Also it seems that when SagePay could not reach RedirectURL it tried 8 more times.
I'm not exactly answering your questions, but perhaps it will help. I'd add this as a comment, but I can't...

MSMQ WCF life cycle on a web site

I've created a console application that listens to a queue using WCF in the past and have no problems with that implementation.
My question:
If, instead of listening to the queue on a console application, I listen to a queue through my website, when would the message be picked up? Would it be instant, as is the case with the console app? Would the message only be received when someone requests a page on the site?
Regards.
A website is not a good host container for a MSMQ client. The reason is the app pool unloads during time of low traffic.
So effectively you are correct in that you will not consume message until the app pool is loaded.
However, that does not prevent others from sending you messages, as the queue receives the messages regardless of whether your client is loaded or not. These would then be stored until the client came back to consume them (providing the queues are durable).
A windows service would be a much more appropriate container.

Resources