首页 > 解决方案 > 我如何对 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 的示例吗?

标签: c#google-apidialogflow-esdialogflow-es-fulfillment

解决方案


我创建了一个 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);

此代码适用于我的目标。


推荐阅读