簡體   English   中英

如何在 PHP 中從對話框流到 API 獲取自定義負載響應

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

僅獲取意圖的文本響應,但 api 響應中缺少自定義負載響應。

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 僅接收文本而不接收自定義有效載荷圖像

從這篇文章中獲取了一個參考,但也無法修復,任何幫助或指向正確方向的任何幫助將不勝感激,謝謝。

這就是我在 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