How to make bot to response the right answer from intent [duplicate] - c#

This question already has an answer here:
How to use LUIS None Intent in c# without train utterance at LUIS
(1 answer)
Closed 5 years ago.
I'm using luis.ai and botframework :
My problem is that , when i try to send message ( that are not part of utterance, so unknown input i don't get the message : $"Sorry, I did not understand '{result.Query}'. Please try again"; ...but every time appear welcome message , from greetings intent.
I don't know why happen this .
Could you please help me ?
Here is my code : MessagController.cs
using System.Net;
using System.Net.Http;
using System.Threading.Tasks;
using System.Web.Http;
using Microsoft.Bot.Builder.Dialogs;
using Microsoft.Bot.Connector;
namespace FirstBotApplication
{
//[BotAuthentication]
public class MessagesController : ApiController
{
/// <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 AllTheBot());
}
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;
}
}
}
luis.cs
using Microsoft.Bot.Builder.Dialogs;
using Microsoft.Bot.Builder.Luis;
using Microsoft.Bot.Builder.Luis.Models;
using Microsoft.Bot.Connector;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Threading.Tasks;
using System.Web;
namespace FirstBotApplication
{
// [LuisModel("Please Enter Your LUIS Model ID", "Please Enter Your LUIS
Subscription Key")]
[Serializable]
[LuisModel("xxxxxxx", "xxxxxxxxxxxx")]
public class AllTheBot : LuisDialog<object>
{
// internal static string results;
public async Task None(IDialogContext context, LuisResult result)
{
string message = $"Sorry, I did not understand '{result.Query}'. Please try again";
await context.PostAsync(message);
context.Wait(this.MessageReceived);
}
[LuisIntent("grettings")]
[LuisIntent("intentfr")]
public async Task Greeting(IDialogContext context, IAwaitable<IMessageActivity> activity, LuisResult result)
{
//await context.PostAsync
//("Yes, you can leave your baggage at the Left Baggage counters located in all terminals. This service is available 24 hours daily at:"
//+ Environment.NewLine + "\n\n Terminal 1" +Environment.NewLine + " - Departure Transit Lounge West, Level 2" + Environment.NewLine + " - Level 3, Public Area"
//+ Environment.NewLine + "\n\n Terminal 2" +Environment.NewLine + " - Departure Transit Lounge Central, Level 2" + Environment.NewLine + " - Arrival Hall North, Level 1, Public Area"
//+ Environment.NewLine + "\n\n Terminal 3" + Environment.NewLine + " - Departure Transit Lounge North, Level 2" + Environment.NewLine + " - Departure Transit Lounge North, Level 2"
await context.PostAsync("Welcome :) ");
context.Wait(MessageReceived);
// results = "BaggageStorage";
}
[LuisIntent("test")]
public async Task test(IDialogContext context, IAwaitable<IMessageActivity> activity, LuisResult result)
{
await context.PostAsync("Do you want to test our bot ? We suggest to type : hi or who are you, help etc..");
context.Wait(MessageReceived);
}
[LuisIntent("thankyou")]
public async Task thankyou(IDialogContext context, IAwaitable<IMessageActivity> activity, LuisResult result)
{
await context.PostAsync("I want to thank you for your time.");
context.Wait(MessageReceived);
}
[LuisIntent("exit")]
[LuisIntent("Utilities.Stop")]
public async Task exit(IDialogContext context, IAwaitable<IMessageActivity> activity, LuisResult result)
{
await context.PostAsync("Thank you for your time ! You are welcome again here :) ");
context.Wait(MessageReceived);
}
}
}

Your None method is not decorated with the "None" and Empty intents. Update your method so it looks like the following:
[LuisIntent("None")]
[LuisIntent("")]
public async Task None(IDialogContext context, LuisResult result)
{
string message = $"Sorry, I did not understand '{result.Query}'. Please try again";
await context.PostAsync(message);
context.Wait(this.MessageReceived);
}

Related

Luis choosing between two intent

If the luis highest intent score for a conversation is 0.15, and the second is 0.14, would it be possible for the bot to ask the user if they meant the first intent or the second intent? If yes how to do so? I've been searching in the documentation samples and there doesn't seem to be any solution except just making more and more utterances so this does not happen; is that correct?
If the luis highest intent score for a conversation is 0.15, and the second is 0.14, would it be possible for the bot to ask the user if they meant the first intent or the second intent? If yes how to do so?
Yes, we can achieve this requirement. The following sample code work for me, you can refer to it.
[Serializable]
public class MyLuisDialog : LuisDialog<object>
{
public MyLuisDialog() : base(new LuisService(new LuisModelAttribute("xxxxxxx",
"xxxxxxx",
domain: "westus.api.cognitive.microsoft.com")))
{
}
//modify Luis request to make it return all intents instead of just the topscoring intent
protected override LuisRequest ModifyLuisRequest(LuisRequest request)
{
request.Verbose = true;
return request;
}
protected override async Task DispatchToIntentHandler(IDialogContext context, IAwaitable<IMessageActivity> item, IntentRecommendation bestIntent, LuisResult result)
{
if (bestIntent.Intent == "FindFood" || bestIntent.Intent == "BuyFood")
{
if (result.Intents[0].Score - result.Intents[1].Score < 0.1)
{
bestIntent.Intent = "FindOrBuyFood";
bestIntent.Score = 1;
}
}
await base.DispatchToIntentHandler(context, item, bestIntent, result);
}
[LuisIntent("Greeting")]
public async Task GreetingIntent(IDialogContext context, LuisResult result)
{
await this.ShowLuisResult(context, result);
}
//...
//other intent handlers
//...
[LuisIntent("FindFood")]
[LuisIntent("BuyFood")]
public async Task FoodIntent(IDialogContext context, LuisResult result)
{
await this.ShowLuisResult(context, result);
}
[LuisIntent("FindOrBuyFood")]
public async Task FindOrBuyFoodIntent(IDialogContext context, LuisResult result)
{
var food = "food";
if (result.Entities.Count() > 0)
{
food = result.Entities[0].Entity;
}
List<string> options = new List<string>() { $"Find {food}", $"Buy {food}" };
PromptDialog.Choice(
context: context,
resume: ChoiceReceivedAsync,
options: options,
prompt: "Hi. Please Select one option :",
retry: "Please try again.",
promptStyle: PromptStyle.Auto
);
}
private async Task ChoiceReceivedAsync(IDialogContext context, IAwaitable<object> result)
{
var option = await result;
//your code logic here
await context.PostAsync($"You selected the '{option}'");
context.Wait(MessageReceived);
}
private async Task ShowLuisResult(IDialogContext context, LuisResult result)
{
await context.PostAsync($"You have reached {result.Intents[0].Intent} intent.");
context.Wait(MessageReceived);
}
}
Test Result:

Ingtegrating LUIS with c# bot framework - ERROR

I'm trying to integrate Luis.ai to C# bot framework. The code runs but when I send a message to the bot it shows this error:
"sorry my bot code is having an issue"
When it should reply depending on the entry using the intents, I only have 2 intents "None" and "perfil".
This is my log:
This is my class Perfil.cs:
using Microsoft.Bot.Builder.Dialogs;
using Microsoft.Bot.Builder.Luis;
using Microsoft.Bot.Builder.Luis.Models;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using System.Web;
namespace SistemaExperto.Dialogs
{
[LuisModel(modelID: "e6168727-2f3e-438b-b46a-88449f4ab52f", subscriptionKey: "ed5f1bda20ac42649123b8969d30e1aa")]
[Serializable]
public class Perfil : LuisDialog<string>
{
[LuisIntent("None")]
public async Task None(IDialogContext context, LuisServiceResult result)
{
await context.PostAsync("I'm sorry I don't have that information");
await context.PostAsync("Try again");
}
[LuisIntent("perfil")]
public async Task perfil(IDialogContext context, LuisServiceResult result)
{
await context.PostAsync("My name is Alex");
}
}
}
This is my Controller MessageController.cs:
using System.Net;
using System.Net.Http;
using System.Threading.Tasks;
using System.Web.Http;
using Microsoft.Bot.Builder.Dialogs;
using Microsoft.Bot.Connector;
namespace SistemaExperto
{
[BotAuthentication]
public class MessagesController : ApiController
{
/// <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.Perfil());
}
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;
}
}
}
I test the code that you provided and replace with my LUIS app modelID&subscriptionKey, if it reach perfil intent, the code work as expected.
If the LuisDialog cannot resolve the method (intent) to execute based on the message received, I get the exception:
The given key was not present in the dictionary.
To solve the issue, I add [LuisIntent("")] on top of the None method.
[LuisModel(modelID: "{your_modelID}", subscriptionKey: "{your_ subscriptionKey}")]
[Serializable]
public class Perfil : LuisDialog<object>
{
[LuisIntent("")]
[LuisIntent("None")]
public async Task None(IDialogContext context, LuisResult result)
{
await context.PostAsync("I'm sorry I don't have that information");
await context.PostAsync("Try again");
}
[LuisIntent("perfil")]
public async Task perfil(IDialogContext context, LuisResult result)
{
await context.PostAsync("My name is Alex");
}
}
Test Result:
Reach perfil intent:
Exception error:

QnA & LUIS Chatbot C#

I am trying to implement a QnaMakerDialog after LUIS recognizes that it is a QnA Intent. In my Dialogs folder, I have two files: BasicLuisDialog.cs and BasicQnAMakerDialog.cs. In my Controller, it calls BasicLuisDialog, and I want to call the QnAMakerDialog within that. Here is my full BasicLuisDialog code:
using System;
using System.Configuration;
using System.Threading.Tasks;
using System.Web.Http;
using Microsoft.Bot.Connector;
using Microsoft.Bot.Builder.Dialogs;
using System.Web.Http.Description;
using System.Net.Http;
using System.Diagnostics;
using Microsoft.Bot.Builder.Luis;
using Microsoft.Bot.Builder.Luis.Models;
using System.Threading;
using Microsoft.Bot.Sample.QnABot;
namespace Microsoft.Bot.Sample.LuisBot
{
[Serializable]
public class BasicLuisDialog : LuisDialog<object>
{
public BasicLuisDialog() : base(new LuisService(new LuisModelAttribute("asdf", "asdf")))
//replace asdf with keys
{
}
[LuisIntent("None")]
public async Task NoneIntent(IDialogContext context, LuisResult result)
{
await context.PostAsync($"You have reached the none intent. You said: {result.Query}"); //
context.Wait(MessageReceived);
}
[LuisIntent("Weather.GetCondition")]
public async Task ConditionIntent(IDialogContext context, LuisResult result)
{
await context.PostAsync($"You have reached the Condition intent. You said: {result.Query}"); //
context.Wait(MessageReceived);
}
[LuisIntent("Weather.GetForecast")]
public async Task ForecastIntent(IDialogContext context, LuisResult result)
{
await context.PostAsync($"You have reached the ForecastIntent intent. You said: {result.Query}"); //
context.Wait(MessageReceived);
}
[LuisIntent("GetQnA")]
public async Task GetQnA(IDialogContext context, IAwaitable<IMessageActivity> activity, LuisResult result)
{
var msg = await activity;
var cts = new CancellationTokenSource();
var faq = new BasicQnAMakerDialog();
await context.Forward(faq, AfterFAQDialog, msg, CancellationToken.None);
}
private async Task AfterFAQDialog(IDialogContext context, IAwaitable<object> result)
{
context.Wait(MessageReceived);
}
}
}
I get the error:
Dialogs\BasicLuisDialog.cs(51,23): error CS0246: The type or namespace name 'BasicQnAMakerDialog' could not be found (are you missing a using directive or an assembly reference?)
Code for BasicQnAMakerDialog.cs:
using System;
using System.Configuration;
using Microsoft.Bot.Builder.CognitiveServices.QnAMaker;
namespace Microsoft.Bot.Sample.QnABot
{
[Serializable]
public class BasicQnAMakerDialog : QnAMakerDialog
{
public BasicQnAMakerDialog() : base(new QnAMakerService(new QnAMakerAttribute("asdf", "asdf","No good match in FAQ",0.2,3)))
{
}
protected override async Task DefaultWaitNextMessageAsync(IDialogContext context, IMessageActivity message, QnAMakerResults results)
{
Console.WriteLine("KB Question: " + results.Answers.First().Questions.First());
Console.WriteLine("KB Answer: " + results.Answers.First().Answer);
await base.DefaultWaitNextMessageAsync(context, message, results);
}
}
}
Add a using for the namespace where the BasicQnAMakerDialog.cs is at.
using Microsoft.Bot.Sample.QnABot

How to switch between two luis.ai dialog with different languages

i have created a bot in bot framework using also luis.ai.
In my luis account i have created two app with different language culture. One app in english and other in french. Both have their intents.
In my code i call one time english dialog, and other time french luis dialog .
My problem is that when i start conversation in english facebook channel ( messenger ) i get the right answer. Inside this bot and channel when i type in french , my bot don't call french dialog .
When i start conversation in french version of facebook ...the bot can't recognize the right dialog ...but catch an error : "Ooops! There are some problems with our system
I try to type english utterance and then i get : Ooops! Too many attemps :(. But don't worry, I'm handling that exception and you can try again!
My idea is that : when i'm inside facebook in english language and click : Get Started ...my conversation to start in english dialog ( AlltheBot.cs). If i type french word like : salut, demarrer the bot can forward to french dialog ( FrenchLuis.cs) . And the other way around, when i'm in facebook in french version my conversation when i click on Demarrer to start in french , and then if i type hello to forward in english dialog.
My code is here :
MessageController.cs
namespace MultiDialogsBot
{
using System.Net;
using System.Net.Http;
using System.Threading.Tasks;
using System.Web.Http;
using Microsoft.Bot.Builder.Dialogs;
using Microsoft.Bot.Connector;
using FirstBotApplication.Dialogs;
using System.Linq;
using System;
[BotAuthentication]
public class MessagesController : ApiController
{
/// <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 RootDialog());
}
else
{
this.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
IConversationUpdateActivity update = message;
var client = new ConnectorClient(new Uri(message.ServiceUrl),
new MicrosoftAppCredentials());
if (update.MembersAdded != null && update.MembersAdded.Any())
{
foreach (var newMember in update.MembersAdded)
{
if (newMember.Id != message.Recipient.Id && newMember.Id
!= message.Conversation.Id)
{
var reply = message.CreateReply();
reply.Text = $"Welcome" + " " +
message.Recipient.Name + " ! You are a new member! If you want to see
help menu , type : help";
client.Conversations.ReplyToActivityAsync(reply);
}
}
}
// 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;
}
}
}
RootDialog.cs
namespace FirstBotApplication.Dialogs
{
using System;
using System.Collections.Generic;
using System.Threading;
using System.Threading.Tasks;
using Microsoft.Bot.Builder.Dialogs;
using Microsoft.Bot.Connector;
[Serializable]
public class RootDialog : IDialog<object>
{
public async Task StartAsync(IDialogContext context)
{
context.Wait(this.MessageReceivedAsync);
}
public virtual async Task MessageReceivedAsync(IDialogContext context,
IAwaitable<IMessageActivity> result)
{
var message = await result;
if (message.Text.ToLower().Contains("Get Started") ||
message.Text.ToLower().Contains("hello") ||
message.Text.ToLower().Contains("hi"))
{
context.Call(new AllTheBot (), this.ResumeAfterOptionDialog);
}
else if (message.Text.ToLower().Contains("Démarrer") ||
message.Text.ToLower().Contains("salut") ||
message.Text.ToLower().Contains("french"))
{
context.Call(new FrenchLuis(), this.ResumeAfterOptionDialog);
}
else
{
await context.PostAsync($"Ooops! There are some problems with our system");
}
}
private async Task ResumeAfterOptionDialog(IDialogContext context,
IAwaitable<object> result)
{
await context.PostAsync($"Ooops! Too many attemps :(. But don't
worry, I'm handling that exception and you can try again!");
}
}
}
FrenchLuis.cs
using Microsoft.Bot.Builder.Dialogs;
using Microsoft.Bot.Builder.Luis;
using Microsoft.Bot.Builder.Luis.Models;
using Microsoft.Bot.Connector;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Threading.Tasks;
using System.Web;
namespace FirstBotApplication
{
// [LuisModel("Please Enter Your LUIS Model ID", "Please Enter Your
LUIS
Subscription Key")]
[Serializable]
[LuisModel("aaaaaaa", "xxxxxxxxx")]
public class FrenchLuis : LuisDialog<object>
{
internal static string results;
// internal static string results;
[LuisIntent("None")]
[LuisIntent("")]
public async Task None(IDialogContext context, LuisResult result)
{
string message = $"Désolé je n'ai pas compris '{result.Query}'.
Veuillez reformuler votre question";
await context.PostAsync(message);
context.Wait(this.MessageReceived);
context.Done(true);
}
//french luis.ai
[LuisIntent("demarrerintent")]
public async Task demarrerintent(IDialogContext context,
IAwaitable<IMessageActivity> activity, LuisResult result)
{
await context.PostAsync("Bienvenue :) ");
context.Done(true);
}
[LuisIntent("denous")]
public async Task denous(IDialogContext context,
IAwaitable<IMessageActivity> activity, LuisResult result)
{
await context.PostAsync(" Nous sommes .....");
context.Done(true);
}
[LuisIntent("quisommes")]
public async Task quisommes(IDialogContext context, IAwaitable<IMessageActivity> activity, LuisResult result)
{
await context.PostAsync("Je suis un robot");
context.Done(true);
// context.Wait(MessageReceived);
}
}}
AllTheBot.cs
using Microsoft.Bot.Builder.Dialogs;
using Microsoft.Bot.Builder.Luis;
using Microsoft.Bot.Builder.Luis.Models;
using Microsoft.Bot.Connector;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Threading.Tasks;
using System.Web;
namespace FirstBotApplication
{
[LuisModel("bbbbbb", "xxxxxxx")]
[Serializable]
public class AllTheBot : LuisDialog<object>
{
internal static string results;
// internal static string results;
[LuisIntent("None")]
[LuisIntent("")]
public async Task None(IDialogContext context, LuisResult result)
{
string message = $"Sorry, I did not understand '{result.Query}'.
Please reformulate your question";
await context.PostAsync(message);
context.Done(true);
// context.Wait(this.MessageReceived);
}
[LuisIntent("grettings")]
[LuisIntent("intentfr")]
public async Task Greeting(IDialogContext context,
IAwaitable<IMessageActivity> activity, LuisResult result)
{
await context.PostAsync("Welcome ");
context.Done(true);
}
[LuisIntent("test")]
public async Task test(IDialogContext context,
IAwaitable<IMessageActivity> activity, LuisResult result)
{
await context.PostAsync("Do you want to test our bot ? We suggest to
type : hi or who are you, help etc..");
context.Wait(MessageReceived);
}
}}
I had a look to your project and got a few problems. You should go step by step to eliminate the problems as you are mixing many things (Dialog management, LUIS calls etc.)
RootDialog.cs
1st point:
message.Text.ToLower().Contains("Démarrer")
and
message.Text.ToLower().Contains("Get Started")
Those two tests can't be valid, as you are comparing something in lowercase and a word with an uppercase.
Moreover, there are better clever ways to get the events of Facebook Messenger 'Get Started' button click, but that's not the point here.
2nd point:
private async Task ResumeAfterOptionDialog(IDialogContext context, IAwaitable<object> result)
{
await context.PostAsync($"Ooops! Too many attemps :(. But don't worry, I'm handling that exception and you can try again!");
}
Your text here is quite strange for a dialog resume!
AllTheBot.cs and FrenchLuis.cs
When you call your 2 LuisDialog, you are never passing the value of the message to those dialogs, is this normal?
You should use context.Forward instead of context.Call: in that way your message will automatically be forwarded to the child dialog.
Global behaviour
I don't think you are going to the right way for managing languages. Why don't you use a valid Language Detection system to check which language is the content you received from the user?
The Text Analytics API from Microsoft Cognitive Services is here for this: https://azure.microsoft.com/en-gb/services/cognitive-services/text-analytics/
Dialog management in your case
I made a sample of the implementation of 2 dialogs management (without LUIS here) to show you what's working:
[Serializable]
public class Dialog44592511 : IDialog<object>
{
public async Task StartAsync(IDialogContext context)
{
context.Wait(MessageReceivedAsync);
}
public virtual async Task MessageReceivedAsync(IDialogContext context, IAwaitable<IMessageActivity> result)
{
var message = await result;
if (message.Text.ToLower().Contains("Get Started") ||
message.Text.ToLower().Contains("hello") ||
message.Text.ToLower().Contains("hi"))
{
await context.Forward(new Dialog44592511_EN(), this.ResumeAfterOptionDialog, message);
}
else if (message.Text.ToLower().Contains("Démarrer") || message.Text.ToLower().Contains("salut") || message.Text.ToLower().Contains("french"))
{
await context.Forward(new Dialog44592511_FR(), this.ResumeAfterOptionDialog, message);
}
else
{
await context.PostAsync($"Ooops! There are some problems with our system");
}
}
private async Task ResumeAfterOptionDialog(IDialogContext context, IAwaitable<object> result)
{
await context.PostAsync($"Resume!");
}
}
[Serializable]
public class Dialog44592511_FR : IDialog<object>
{
public async Task StartAsync(IDialogContext context)
{
context.Wait(MessageReceivedAsync);
}
private async Task MessageReceivedAsync(IDialogContext context, IAwaitable<object> result)
{
var activity = await result as Activity;
await context.PostAsync($"Vous êtes dans le dialogue FR");
context.Done<object>(null);
}
}
[Serializable]
public class Dialog44592511_EN : IDialog<object>
{
public async Task StartAsync(IDialogContext context)
{
context.Wait(MessageReceivedAsync);
}
private async Task MessageReceivedAsync(IDialogContext context, IAwaitable<object> result)
{
var activity = await result as Activity;
await context.PostAsync($"You are in the EN dialog");
context.Done<object>(null);
}
}
Don't hesitate to edit your question for more details
Instead of doing context.Call, you should use context.Forward, which will forward the message to the dialog.
With the context.Call you are just calling the dialog and leaving it ready to receive a new message.
You should review the different ways to initiate dialogs, explained here.

Bot Framework Forward Type Arguments Error

I am getting this following error
when trying to use the MS Bot Framework Example to call a different dialog. This is my code:
using System;
using System.Threading;
using System.Threading.Tasks;
using Microsoft.Bot.Builder.Dialogs;
using Microsoft.Bot.Connector;
namespace ReadMeBot.Dialogs
{
[Serializable]
public class RootDialog : IDialog<object>
{
public Task StartAsync(IDialogContext context)
{
context.Wait(MessageReceivedAsync);
return Task.CompletedTask;
}
private async Task MessageReceivedAsync(IDialogContext context, IAwaitable<object> result)
{
var activity = await result as Activity;
if (activity != null && activity.Text.ToLower().Contains("what is"))
{
await
context.Forward(new InternetSearchDialog(), this.ResumeAfterInternetSearchDialog, activity, CancellationToken.None);
}
// calculate something for us to return
int length = (activity.Text ?? string.Empty).Length;
// return our reply to the user
await context.PostAsync($"You sent {activity.Text} which was {length} characters. Thank you!");
context.Wait(MessageReceivedAsync);
}
private async Task ResumeAfterInternetSearchDialog(IDialogContext context, IAwaitable<string> result)
{
}
}
}
How can I solve this? I googled around and nobody seems to have this issue. What am I doing wrong?
Since you are forwarding to another dialog, you don't need to wait in this dialog. You'll want to call context.Wait in the resume though.
Things should work as expected if you change your code to something like this:
[Serializable]
public class RootDialog : IDialog<object>
{
public Task StartAsync(IDialogContext context)
{
context.Wait(MessageReceivedAsync);
return Task.CompletedTask;
}
private async Task MessageReceivedAsync(IDialogContext context, IAwaitable<object> result)
{
var activity = await result as Activity;
if (activity != null && activity.Text.ToLower().Contains("what is"))
{
await
context.Forward(new InternetSearchDialog(), this.ResumeAfterInternetSearchDialog, activity, CancellationToken.None);
}
else
{
// calculate something for us to return
int length = (activity.Text ?? string.Empty).Length;
// return our reply to the user
await context.PostAsync($"You sent {activity.Text} which was {length} characters. Thank you!");
context.Wait(MessageReceivedAsync);
}
}
private async Task ResumeAfterInternetSearchDialog(IDialogContext context, IAwaitable<string> result)
{
context.Wait(MessageReceivedAsync);
}
}

Categories