eristemena / dialogflow-fulfillment-webhook-php

Dialogflow agent fulfillment PHP library supporting v1 & v2
MIT License
104 stars 47 forks source link

custom payload not rendering in fulfillment message #4

Open Sarps opened 6 years ago

Sarps commented 6 years ago

When I create a custom payload programmatically and render it, it ends up being outside of the fulfillmentMessages array.

$this->agent->reply(\Dialogflow\RichMessage\Payload::create([
            "type" => "web_url",
            "url" => "There are 24 shops in Lisda.",
            "title" => "http://localhost:8000/maps",
 ]));
{"payload":{"unspecified":{"type":"web_url","url":"http:\/\/localhost:8000\/maps","title":"Click to view map."}},"fulfillmentMessages":[{"text":{"text":["There are 24 shops in Lisda."]}}],"fulfillmentText":"There are 24 shops in Lisda.","outputContexts":[]}

Due to that dialogflow places the payload in data object instead of messages object.

{"speech":"There are 24 shops in Lisda.","source":"","messages":[{"type":0,"speech":"There are 24 shops in Lisda."}],"data":{"unspecified":{"type":"web_url","title":"Click to view map.","url":"http://localhost:8000/maps"}}}

Which is not what I get when I add the payload manually to the intent response inside dialogflow.

"fulfillment":{"messages": [{"type":"custom_payload","platform":"google","payload":{"unspecified":{...}}},,{"type":4,"payload":{"unspecified":{"type":"web_url","url":"http://localhost:8000/maps","title":"Click to view map."}}}], "speech":""}

Please is there any way that I could force the payload into the fulfillmentMessages array. Thank you for your good works. This package has really helped a lot.

eristemena commented 6 years ago

What is the request source you're getting?

Currently custom payload only supports the following request source: "google", "facebook", "kik", "line", "skype", "slack", "telegram", "viber". Other than that the key will be set to "unspecified". That seems what happened with yours.

Furthermore, when you're integrating with certain platform, don't preview them in Dialogflow console, cause it will also set the key to "unspecified".

Sarps commented 6 years ago

Thanks for the quick response. I am not worried about the key, I can handle that as I am using a nodejs client. My issue is that the payload is outside the fulfillmentMessages array. Just like how the text response is inside fulfillmentMessages, I was hoping the payload would also be in there, considering the fact that it is a reponse and all responses are supposed to be in the fulfillmentMessages array. Thanks, once again.

eristemena commented 6 years ago

Oh sorry, are you talking about payload object inside fulfillmentMessages as per Dialogflow specification here?

Sarps commented 6 years ago

yh, exactly

eristemena commented 6 years ago

I can't reproduce the JSON response you mentioned in the first comment, either by adding it manually using DIalogflow console or using Dialogflow official NodeJS library.

Can you explain more what is the use case here? And what is web_url type? is it a Facebook messaging template? if so, why does your JSON contain google in the platform?

isbkch commented 6 years ago

@Sarps I'm getting a similar issue, have you been able to fix yours ?

basiteaal commented 5 years ago

I think this issue should be closed due to inactivity.