简体   繁体   English

如何在 PHP 中从对话框流到 API 获取自定义负载响应

[英]How to get custom payload response from dialogflow to API in PHP

Getting only text response for the intent but the custom payload response is missing in api response.仅获取意图的文本响应,但 api 响应中缺少自定义负载响应。

Dialogflow raw response is Image Dialogflow 原始响应是图像

{
"allRequiredParamsPresent": true,
"fulfillmentText": "Thanks Dhruva, are you ?",
"fulfillmentMessages": [
  {
    "text": {
      "text": [
        "Thanks Dhruva, are you ?"
      ]
    }
  },
  {
    "payload": {
      "richContent": [
        [
          {
            "type": "chips",
            "options": [
              {
                "text": "permanent employee"
              },
              {
                "text": "probation employee"
              }
            ]
          }
        ]
      ]
    }
  }
]
}

Api receiving only text not custom payload Image Api 仅接收文本而不接收自定义有效载荷图像

Took a reference from this post but was unable to fix either, any help or point to the right direction will be appreciated thanks.从这篇文章中获取了一个参考,但也无法修复,任何帮助或指向正确方向的任何帮助将不胜感激,谢谢。

This is what I did to get the custom payload in a php associative array这就是我在 php 关联数组中获取自定义有效负载所做的工作

        $textInput = new TextInput();
        $textInput->setText($request->query("message","message that has custom payload response"));
        $textInput->setLanguageCode("en-US");

        //Putting it in query input
        $queryInput = new QueryInput();
        $queryInput->setText($textInput);
        $response = $sessionClient->detectIntent($session, $queryInput);
        $queryResult = $response->getQueryResult();

        //Beginning of solution
        $fulfillmentMessages = $queryResult->getFulfillmentMessages();
        $customPayloads = []; The result array

        foreach ($fulfillmentMessages as $fulfillmentMessage) {
            /* @var $fulfillmentMessage Message*/
            if($fulfillmentMessage->hasPayload()) {
                $customPayloads[] = json_decode($fulfillmentMessage->getPayload()
                    ->serializeToJsonString(),1);
            }
        }

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM