如何处理用户操作

我想使用 c# 处理 Bot 框架中的用户操作。我正在向用户显示一些输入作为选择。这里用户可能不想要任何选择。所以他们可以直接输入一些命令退出。如果用户键入退出,而不是选择选项(退出未列在选项中),我需要处理退出。默认情况下,Bot 不允许输入未列出的内容。

希望这可以通过 Node JS(处理用户操作)来完成。我想实现以下相同的功能。

有人可以帮助我吗?任何建议,将不胜感激。


噜噜哒
浏览 187回答 1
1回答

饮歌长啸

如果用户键入退出,而不是选择选项(退出未列在选项中),我需要处理退出。默认情况下,Bot 不允许输入未列出的内容。您可以尝试实现全局消息处理程序,以便在用户使用特定单词回复对话时执行代码Exit。以下代码片段供您参考。GlobalMessageHandlersBotModule:public class GlobalMessageHandlersBotModule : Module{&nbsp; &nbsp; protected override void Load(ContainerBuilder builder)&nbsp; &nbsp; {&nbsp; &nbsp; &nbsp; &nbsp; base.Load(builder);&nbsp; &nbsp; &nbsp; &nbsp; builder&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; .Register(c => new ExitScorable(c.Resolve<IDialogTask>()))&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; .As<IScorable<IActivity, double>>()&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; .InstancePerLifetimeScope();&nbsp; &nbsp; }}退出可评分:public class ExitScorable : ScorableBase<IActivity, string, double>{&nbsp; &nbsp; private readonly IDialogTask task;&nbsp; &nbsp; public ExitScorable(IDialogTask task)&nbsp; &nbsp; {&nbsp; &nbsp; &nbsp; &nbsp; SetField.NotNull(out this.task, nameof(task), task);&nbsp; &nbsp; }&nbsp; &nbsp; protected override async Task<string> PrepareAsync(IActivity activity, CancellationToken token)&nbsp; &nbsp; {&nbsp; &nbsp; &nbsp; &nbsp; var message = activity as IMessageActivity;&nbsp; &nbsp; &nbsp; &nbsp; if (message != null && !string.IsNullOrWhiteSpace(message.Text))&nbsp; &nbsp; &nbsp; &nbsp; {&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; if (message.Text.ToLower().Equals("exit", StringComparison.InvariantCultureIgnoreCase))&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; {&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; return message.Text;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; }&nbsp; &nbsp; &nbsp; &nbsp; }&nbsp; &nbsp; &nbsp; &nbsp; return null;&nbsp; &nbsp; }&nbsp; &nbsp; protected override bool HasScore(IActivity item, string state)&nbsp; &nbsp; {&nbsp; &nbsp; &nbsp; &nbsp; return state != null;&nbsp; &nbsp; }&nbsp; &nbsp; protected override double GetScore(IActivity item, string state)&nbsp; &nbsp; {&nbsp; &nbsp; &nbsp; &nbsp; return 1.0;&nbsp; &nbsp; }&nbsp; &nbsp; protected override async Task PostAsync(IActivity item, string state, CancellationToken token)&nbsp; &nbsp; {&nbsp; &nbsp; &nbsp; &nbsp; this.task.Reset();&nbsp; &nbsp; }&nbsp; &nbsp; protected override Task DoneAsync(IActivity item, string state, CancellationToken token)&nbsp; &nbsp; {&nbsp; &nbsp; &nbsp; &nbsp; return Task.CompletedTask;&nbsp; &nbsp; }}
打开App,查看更多内容
随时随地看视频慕课网APP