botframework - 如何将提示值从主对话框传递给调度程序?
问题描述
`命名空间 Microsoft.BotBuilderSamples { 公共类 DispatchBot : ActivityHandler { 私有 ILogger _logger; 私有 IBotServices _botServices;
public DispatchBot(IBotServices botServices, ILogger<DispatchBot> logger)
{
_logger = logger;
_botServices = botServices;
}
protected override async Task OnMessageActivityAsync(ITurnContext<IMessageActivity> turnContext, CancellationToken cancellationToken)
{
// First, we use the dispatch model to determine which cognitive service (LUIS or QnA) to use.
var recognizerResult = await _botServices.Dispatch.RecognizeAsync(turnContext, cancellationToken);
// Top intent tell us which cognitive service to use.
var topIntent = recognizerResult.GetTopScoringIntent();
// Next, we call the dispatcher with the top intent.
await DispatchToTopIntentAsync(turnContext, topIntent.intent, recognizerResult, cancellationToken);
}
protected override async Task OnMembersAddedAsync(IList<ChannelAccount> membersAdded, ITurnContext<IConversationUpdateActivity> turnContext, CancellationToken cancellationToken)
{
const string WelcomeText = "I am here to make your bot experience much more easier";
foreach (var member in membersAdded)
{
if (member.Id != turnContext.Activity.Recipient.Id)
{
await turnContext.SendActivityAsync(MessageFactory.Text($"Hi {member.Name}, I am your IT assistant at your service . {WelcomeText}"), cancellationToken);
}
}
}
private async Task DispatchToTopIntentAsync(ITurnContext<IMessageActivity> turnContext, string intent, RecognizerResult recognizerResult, CancellationToken cancellationToken)
{
switch (intent)
{
case "l_us_bot":
await ProcessHomeAutomationAsync(turnContext, recognizerResult.Properties["luisResult"] as LuisResult, cancellationToken);
break;
case "t_abs-bot":
await ProcessSampleQnAAsync(turnContext, cancellationToken);
break;
default:
_logger.LogInformation($"Dispatch unrecognized intent: {intent}.");
await turnContext.SendActivityAsync(MessageFactory.Text($"Dispatch unrecognized intent: {intent}."), cancellationToken);
break;
}
}
private Activity CreateResponse(IActivity activity, Attachment attachment)
{
var response = ((Activity)activity).CreateReply();
response.Attachments = new List<Attachment>() { attachment };
return response;
}
private async Task ProcessHomeAutomationAsync(ITurnContext<IMessageActivity> turnContext, LuisResult luisResult, CancellationToken cancellationToken)
{
_logger.LogInformation("ProcessHomeAutomationAsync");
// Retrieve LUIS result for Process Automation.
var result = luisResult.ConnectedServiceResult;
var topIntent = result.TopScoringIntent.Intent;
var entity = result.Entities;
if (topIntent == "welcome")
{
await turnContext.SendActivityAsync(MessageFactory.Text("Hi,This is your IT assistant"), cancellationToken);
}
if (topIntent == "None")
{
await turnContext.SendActivityAsync(MessageFactory.Text("Sorry I didnt get you!"), cancellationToken);
}
if (topIntent == "DateTenure")
{
// Here i want to call my dialog class
}
}
}
private async Task ProcessSampleQnAAsync(ITurnContext<IMessageActivity> turnContext, CancellationToken cancellationToken)
{
_logger.LogInformation("ProcessSampleQnAAsync");
var results = await _botServices.SampleQnA.GetAnswersAsync(turnContext);
if (results.Any())
{
await turnContext.SendActivityAsync(MessageFactory.Text(results.First().Answer), cancellationToken);
}
else
{
await turnContext.SendActivityAsync(MessageFactory.Text("Sorry, could not find an answer in the Q and A system."), cancellationToken);
}
}
}
`我有一个描述的场景:当用户打招呼时,机器人会显示自适应卡片(每张卡片上都有 Action.Submit)。----假设卡片为: 1. 订票 2. 需要帮助
3. 每当用户单击任何选项时取消,我都会得到相同的用户单击值。喜欢
如果用户选择“需要帮助”。我得到相同的价值..
然后我像任何问题(查询)一样从用户那里获得输入。
然后此查询将转到调度程序的特定意图,但不会从调度程序转到意图并显示错误(对象引用未设置为对象的实例)
所以我该怎么做?
供参考,我已经通过此链接“如何检索用户在自适应卡中输入的 c# 代码以及如何在提交按钮单击时调用下一个意图”
它应该在用户输入后从调度程序机器人中获取价值。
解决方案
推荐阅读
- splunk - 如何优化以下 Splunk 查询?
- java - slf4j 在计划任务线程中不起作用
- android - 每次调用 onCreate 方法时都不会调用 ViewModel 方法
- python - 显示 pandas 列 - 从宽到长
- python - 从嵌套列表中删除不需要的文本
- php - 如何在电子邮件 Codeigniter 中循环收件人
- amazon-s3 - 如何处理包含“.”的存储桶路径 使用 gsutil
- javascript - 检测特定的嵌入脚本并将其删除?
- c++ - 如何在 Qt 的 .pro 中链接库 adshlp.h?
- json - 如何将我的会话或我的 GAN 模型保存到 js 文件中