我想知道是否有人知道在调用任何Luis Intent方法时始终调用自定义方法的方法。基本上我正在尝试在Bot从LuisDialog获取数据时向用户添加加载器消息。
答案 0 :(得分:3)
如果你有一个RootDialog将消息转发给LuisDialog,你可以显示一个"加载器消息"在RootDialog或LuisDialog的StartAsync方法中。另一种选择是覆盖LuisDialog的MessageReceived,并在调用base.MessageReceived之前发送加载器消息。
[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;
await context.PostAsync("RootDialog.MessageReceivedAsync");
await context.Forward(new LuisTestDialog(), AfterLuisDialog, activity);
}
private async Task AfterLuisDialog(IDialogContext context, IAwaitable<object> result)
{
await context.PostAsync("RootDialog.AfterLuisDialog");
}
}
[LuisModel("xxx", "xxx")]
[Serializable]
public class LuisTestDialog : LuisDialog<object>
{
public async override Task StartAsync(IDialogContext context)
{
await context.PostAsync("LuisTestDialog.StartAsync");
await base.StartAsync(context);
}
[LuisIntent("")]
[LuisIntent("None")]
public async Task None(IDialogContext context, LuisResult result)
{
await context.PostAsync("LuisTestDialog.None");
context.Done(true);
}
protected async override Task MessageReceived(IDialogContext context, IAwaitable<IMessageActivity> item)
{
await context.PostAsync("LuisTestDialog.MessageReceived");
await base.MessageReceived(context, item);
}
}
以上将导致以下消息:
答案 1 :(得分:0)
我有两个想法。
我希望这会有所帮助。