Articles → MICROSOFT BOT FRAMEWORK → Prompt Dialog In Microsoft Bot Framework
Prompt Dialog In Microsoft Bot Framework
Purpose
Example
- Create a new class "PromptDemo".
- Inherit it with the "IDialog" interface.
- Implement the "StartASync" method and enter the welcome message.
- Create a method "GetNameAsync" to get the name from the user.
- Create a call back method "ResumeGetName".
using Microsoft.Bot.Builder.Dialogs;
using Microsoft.Bot.Connector;
using System;
using System.Threading.Tasks;
namespace Bot_Application1.Dialogs { [Serializable]
public class PromptDemo: IDialog < object > {
public async Task StartAsync(IDialogContext context) {
await context.PostAsync("Welcome to gyansangrah.com.");
context.Wait(GetNameAsync);
}
private Task GetNameAsync(IDialogContext context, IAwaitable < IMessageActivity > activity) {
PromptDialog.Text(
context: context, resume: ResumeGetName, prompt: "Please enter your name", retry: "Please enter the name again");
return Task.CompletedTask;
}
private async Task ResumeGetName(IDialogContext context, IAwaitable < string > result) {
string name = await result;
await context.PostAsync($ "Thank you {name}");
}
}
}
Output
Click to Enlarge