c# - 我如何对 Fulfillment Messages 进行交互以将消息逐个返回给客户端
问题描述
我正在使用 Dialogflow 在 Microsoft Bot Framework 上进行集成,当我使用 FulfillmentText 时,我的代码工作正常,但我需要使用 FulfillmentMessages,因为我的代码中有很多消息返回,我尝试了此代码,但“retorno”变量接收 json格式返回,我如何交互所有消息逐行返回以响应我的客户?
foreach (Intent.Types.Message msg in queryResult.FulfillmentMessages)
{
retorno = msg.Text;
Console.WriteLine($"Fulfillment text: {retorno}");
}
您有任何使用 Microsoft Bot Framework 和 Google.Cloud.Dialogflow.V2 API 的示例吗?
解决方案
我创建了一个 IActivity 数组,并在每条消息中使用 foreach 将文本逐个添加到“respostas”数组中。最后我使用了“await turnContext.SendActivitiesAsync(retorno, cancelToken);” 因为我可以传递 IActivity 数组:
IActivity[] respostas;
respostas = new IActivity[1];
int cnt = 0;
foreach (Intent.Types.Message msg in queryResult.FulfillmentMessages)
{
foreach (string msgstr in msg.Text.Text_)
{
retorno = retorno + msgstr.ToString() + "\r\n";
respostas[cnt] = MessageFactory.Text(msgstr.ToString(), msgstr.ToString());
cnt++;
}
Console.WriteLine($"Fulfillment text: {retorno}");
}
await turnContext.SendActivitiesAsync(retorno, cancellationToken);
此代码适用于我的目标。
推荐阅读
- wix - 如何仅在安装和修改时执行条件自定义操作?
- angular - 如何在 RxJS 6 和 Angular 6 出错后保持 observable 存活
- laravel - laravel migration 指定的key太长;最大密钥长度为 767 字节
- r - 如何使用 dplyr 创建总频率表
- xaml - 将控件模板与 Xamarin 表单选项卡式页面一起使用
- angular - 在本地 iis 上提供 .net core 和 angular 5 应用程序
- node.js - PUT 请求在服务器端不起作用(节点 js)
- registry - 此提供程序未实现 IDynamicPropertyCmdletProvider 接口
- windows - 微软蓝牙低功耗广告
- integration - Zoho CRM 和 Moodle 的集成