Microsoft bot V4 Skill Bot responds with 500(Internal error) when replied to Root bot at SendActivityAsync function - c#

I'm trying Master and Skill bot functionality by calling Microsoft Sample EchoSkillBot from Master Bot developed by me. Call reached Skill bot from Master but while Skill bot replying to Master getting the exception "InternalServerError". Additional note I'm using LUIS to route the conversations to respective Skill and QnA.
Code: (Exception thrown at this code)
await turnContext.SendActivityAsync(
MessageFactory.Text(messageText,
messageText,
InputHints.IgnoringInput),
cancellationToken);
Error:
"{"type":"https://tools.ietf.org/html/rfc7231#section-6.6.1","title":"An error occured while processing your request.","status":500,"traceId":"XXXXX"}"
"Operation returned an invalid status code 'InternalServerError'"

I found the root cause for the exception. In startup.cs I had used Bot framework adapter as
IBotFrameworkHttpAdapter in one place and other place BotFrameworkHttpAdapter. After fixing this Skill reply worked fine.
// Create the Bot Framework Adapter with error handling enabled.
//services.AddSingleton<IBotFrameworkHttpAdapter, AdapterWithErrorHandler>();
services.AddSingleton<BotFrameworkHttpAdapter, AdapterWithErrorHandler>();
services.AddSingleton<BotAdapter>(sp => sp.GetService<BotFrameworkHttpAdapter>()); //Added for Skill bot

Related

Communication between Teams and Web Chat via Bot

With https://portal.azure.com I managed to create a QnA Bot.
I also managed to send a message from the Bot Framework Emulator to MS Teams and the Test Web Chat of the bot. (Though it is very static and manually done as of now)
I get my Token from https://login.microsoftonline.com/botframework.com/oauth2/v2.0/token. With that Token I can send a message to https://smba.trafficmanager.net/emea/v3/conversations/ConversationID/activities (which is Teams) and I can send a message to https://webchat.botframework.com/v3/conversations/ConversationID/activities (which is the Test Web Chat).
Little bit offtopic: Since I'm new to Azure I wonder if everything done so far is fine or completly false?
Anyway...
My goal so far is that when writing a message in the Test Web Chat the message should also end up in MS Teams. Then from Teams I want to answer to the message like #Bot This is my Answer. This Answer in Teams should then also end up in the Test Web Chat. (So basically communication between Teams and Web Chat)
What would be the best approach to do this?
I was thinking of a backend in Azure but I don't know what would be possible to use and if it's even possible.
My idea was:
A message is sent Web Chat. In Code I would upload the Web Chat Conversation Information to Azure. Also in Teams there is now the same message that was written in Web Chat. The Conversation ID in Teams also needs to be uploaded now and the Conversation ID the Web Chat is sending to needs to be updated (this would be needed so there is no spamming of new threads/messages in Teams from one Conversation and all the messages from this Web Chat Conversation are now in one thread.) Now to answer in the Conversation of the Web Chat via Teams I would write and send the answer. Before the sending of the answer happens I would need the Conversation ID from the Web Chat. So the Bot would download the information from Azure so it knows where it has to sent the answer to.
Is this a good apporach or do you know better ones? Also what ressources in Azure could I use to achieve this?
It sounds like you are thinking about this the right way. Basically you want to pair two conversation references - one in Teams and the other in Web Chat - together and then forward the messages between the two.
BotFramework SDK v4 (C#)
I would recommend creating two functions - AddConversationReferenceAsync and GetConversationReferenceAsync. In those functions, you should manage how you store, connect, and retrieve conversation references. You can check the channel Id - activity.ChannelId - to determine how you want to handle the reference. Then in OnMessageActivityAsync you can add and retrieve the corresponding conversation references to send a proactive message to the other channel.
protected override async Task OnMessageActivityAsync(ITurnContext<IMessageActivity> turnContext, CancellationToken cancellationToken)
{
AddConversationReferenceAsync(turnContext.Activity as Activity);
var conversationReference = GetConversationReferenceAsync(turnContext.Activity as Activity);
if (conversationReference != null) {
await turnContext.Adapter.ContinueConversationAsync(_appId, conversationReference, (ITurnContext context, CancellationToken cancellationToken) => {
await context.SendActivityAsync(turnContext.Activity);
}, cancellationToken);
} else {
await turnContext.SendActivityAsync("You are not connected to anyone at the moment");
}
}
Screen Capture
I would recommend looking at the BotBuilder Proactive Messaging sample, and #tompaana built a Hunan Handoff Bot sample that connects conversations in Teams and Slack that might be helpful.
Hope this helps!

Bot Framework Bad Gateway for Double Quoted messages

I am having a very weird issue, I have a Chat Bot which is surfaced using a HTML page using DirectLine. But now whenever I post a message with DOUBLE QUOTES in it, it just gives me a 502 Bad Gateway error.
JS CODE:
BotChat.App({
bot: bot,
locale: params['locale'],
resize: 'detect',
speechOptions: speechOptions,
user: user,
botConnection: botConnection
}, document.getElementById('BotChatGoesHere'));
Chat Message:
Developer Console Error:
DEVELOPER CONSOLE NETWORK LOG:
I have been working with Bot Framework for quite sometime now, but this is the first time I am facing something like this.
Regards,
Hari
This has come up recently and is specific to the webchat and Directline channels. According to this bug on Github,
The smart quotes conversion are done by Markdown-It.
https://github.com/markdown-it/markdown-it#init-with-presets-and-options
By default, all message without textFormat will assume to be
"markdown". If you send activity of
{ type: 'message', textFormat: 'plain', text: '"What\'s up?"' }
the message will be plain text and not go thru Markdown-It. Quotes will not turn into smart quotes.

Bot state error, but not using Bot State

I'm getting an exception on the following post with my Bot Framework bot on Azure, but I'm not using Bot Builder Framework to manage State Data. I'm doing that myself in my database.
POST /v3/botstate/skype/conversations/...
There's no reference to userdata or conversationdata anywhere in my code. So why is this post happening and why am I getting this exception and how do I fix it?
I've seen some instances where if you don't explicitly declare where the state is stored it will still use the bot state service.
Have a look at the sample code here:-
https://blog.botframework.com/2017/07/26/saving-state-sql-dotnet
If you are already doing this, then please post the exception and share your code.

C# Bot framework - Resource not found Error

I've built a small basic web bot app using bot framework and want to deploy it on Azure. I've followed all the steps and it's working fine under "Test in Web Chat" of Azure Portal too, but however as I open my bot's endpoint
https://optlbot.azurewebsites.net/api/messages
I get an error saying
The requested resource does not support http method 'GET'
Can somebody please help me, I can't debug my application at all. I've also tested on emulator and there too it's working fine.
Yes, the URL https://optlbot.azurewebsites.net/api/messages works only for POST request and not a GET request, because you post a message from user to bot and not a get, you can see that in the MessagesController code.
Being said that, if you want to test your bot locally, you have to use the emulator. You can have a look at Bot emulator for the same.
Now if you want to publish the bot to the world so that others can see it and use it, so that's where the channel comes in. Consider channel as a medium by which you enable your bot for others to use with a much better user experience.
There are multiple channels available for the bot to be published in, and yes you can publish the same bot in all the channels.webchat is just one channel and the one which is enabled by default and the way to see it is :
Open your bot in the Azure Portal and click Channels blade.
Click Edit for the Web Chat channel
Under Secret keys, click Show for the first key
Copy the Secret key and the Embed code.
Click Done
So the embed code is actually an iframe which you can place in your website or share with others who want to use your bot. Or you can use the src of the iFrame too to reach the bot directly.
Again this is just one channel. You can take a look at the Configure channels documentation for steps to enable the bot in more channels like Skype, Microsoft Teams, Email, Facebook, Slack, Telegram, etc.
If you check the code of your MessagesController, you would find the following action defined in your controller, it only accept POST request and read the value of activity from the request body, it does not support http method 'GET'.
/// <summary>
/// POST: api/Messages
/// Receive a message from a user and reply to it
/// </summary>
public async Task<HttpResponseMessage> Post([FromBody]Activity activity)
{
if (activity.Type == ActivityTypes.Message)
{
await Conversation.SendAsync(activity, () => new Dialogs.RootDialog());
}
else
{
HandleSystemMessage(activity);
}
var response = Request.CreateResponse(HttpStatusCode.OK);
return response;
}

I cant connect to my Bot via directline api

I have this error message anytime I try to connect to my bot via directline:
There was an error sending this message to your bot: HTTP status code GatewayTimeout
I didn't have this error at first, it just appeared recently and I dont know what to do, please help. My AppID and Passwords are set correctly.

Categories