0

Getting only text response for the intent but the custom payload response is missing in api response.

Dialogflow raw response is Image

{
"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

Took a reference from this post but was unable to fix either, any help or point to the right direction will be appreciated thanks.

1 Answers1

0

This is what I did to get the custom payload in a php associative array

        $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);
            }
        }