如何从DialogFlowV2 Webhook发送不同的语音和显示文本?

时间:2018-07-26 04:46:51

标签: android dialogflow fulfillment

我最近从DialogFlowV1更新为DialogFlowV2

我发现displayText中没有不同的speechV2参数。

如何从webhook实现中发送不同的speechdisplayText参数,以便我可以使用DialogFlow Android客户端使用这些值。

从我从V1升级到V2的那一天开始,我发现displayText参数在Android的ai.api.sdk

中返回 null

这是我从Webhook发送的充实响应

{
  "fulfillmentText": "My FulfillmentText",
  "fulfillmentMessages": [
    {
      "text": {
        "text": [
          "Sample response 1",
          "Sample response 2"
        ]
      }
    }
  ]
}

在上述响应结构中我必须进行哪些更改?

1 个答案:

答案 0 :(得分:2)

您需要在v2 api中的speech中传递fulfillmentText文本,在displayText中传递fulfillmentMessages

{
  "fulfillmentText": "This will be speech.",
  "fulfillmentMessages": [
    {
      "text": {
        "text": [
          "This will be text to be displayed on screen."
        ]
      }
    }
  ]
}

如果您没有从Webhook中传递fulfillmentMessages,则fulfillmentText将显示在屏幕上。

响应的基本结构在this page上给出。

doc image

发送fulfillmentText的示例代码(python):

import json
req = req_you_get_from_webhook_call
res = json.dumps({
        'fulfillmentText': 'response from the webhook',
    })
return res