The reply should be handled by the dialog passed to the SendAsync
method.
In the dialog, you will usually have a method that receives the context and the message sent by the user. For example:
public async virtual Task MessageReceivedAsync(IDialogContext context, IAwaitable<IMessageActivity> result)
{
var message = await result;
}
In the StartAsync
method of the dialog you will have to set this method as the one that will be called once the user sends a message to the bot
public async Task StartAsync(IDialogContext context)
{
context.Wait(this.MessageReceivedAsync);
}
Then, is up to you to decide what to do after receiving the message.
Do you want to use a PromptDialog
, e.g. the Confirm one? You can, just instantiate the dialog, call it and get the result in the ResumeAfter<bool>
method.
PromptDialog.Confirm(context, ResumeAfterPrompt, "prompt dialogue", "retry dialog", 3);
private async Task ResumeAfterPrompt(IDialogContext context, IAwaitable<bool> result)
{
try
{
// try get user response
bool response = await result;
await context.PostAsync($"You said: {result}");
}
catch (TooManyAttemptsException)
{
// handle error
}
// wait for another message from the user. Could be the same method or a new one following the same signature.
context.Wait(this.MessageReceivedAsync);
}
Do you want to use a FormFlow? You also, just instantiate the FormDialog
and get the result in the ResumeAfter<T>
method you define.
It's always the same pattern when working with multi dialogs (Prompts and Forms are dialogs!): call the dialog, get the result in the ResumeAfter method and wait for a new user message.
All this concepts are well explained and also demonstrated in the Multi-Dialogs sample. Go through the readme and the codebase and you will understand what I explained. That sample shows prompts, a FormFlow, custom dialogs, etc. Here there are a few more details.