I am using dialogflow webhook and want to store data in conversation.
Below is what i understood from dialogflow docs
response.setHeader('Content-Type', 'application/json');
response.send(JSON.stringify({
"payload": {
"google": {
"expectUserResponse": true,
"richResponse": {
"items": [
{
"simpleResponse": {
"textToSpeech": "OKAY"
}
}
]
},
"conversationToken" : "count=1"
}
}
}))
This does not work as the JSON from the next request does not have this stored value.
You can check my complete answer here.
In short use contexts to store parameters.
Use the output context to save parameters
{
"fulfillmentText":"This is a text response",
"fulfillmentMessages":[ ],
"source":"example.com",
"payload":{
"google":{ },
"facebook":{ },
"slack":{ }
},
"outputContexts":[
{
"name":"<Context Name>",
"lifespanCount":5,
"parameters":{
"<param name>":"<param value>"
}
}
],
"followupEventInput":{ }
}
Related
I am unable to send a custom payload back to dialogflow from my nodejs webhook code for SLACK platform.
const {WebhookClient, Payload, Platforms, Suggestion} = require('dialogflow-fulfillment');
let payloadObj = new Payload(Platforms.SLACK, questionStringToSend);
agent.add(payloadObj);
Here, questionStringToSend is the JSON payload that i want to send.
Any help would be appreciated.
Structure of my JSON is below:
{
"blocks":[
{
"type":"section",
"text":{
"type":"mrkdwn",
"text":"How do you rate the company?"
}
},
{
"type":"actions",
"elements":[
{
"type":"button",
"text":{
"type":"plain_text",
"text":0
},
"value":0
},
{
"type":"button",
"text":{
"type":"plain_text",
"text":1
},
"value":1
}
]
}
]
}
While sending a response from webhook the format of json is very important Link.
Custom payload response is a json file which has a specific structure and if the structure isn't followed we won't get the expected response.
So the json file can be edited as follows:
{
"fulfillmentMessages": [
{
"payload": {
"slack": {
"attachments": [
{"blocks":[
{
"type":"section",
"text":{
"type":"mrkdwn",
"text":"How do you rate the company?"
}
},
{
"type":"actions",
"elements":[
{
"type":"button",
"text":{
"type":"plain_text",
"text":"0"
},
"value":"0",
"action_id": "button"
},
{
"type":"button",
"text":{
"type":"plain_text",
"text":"1"
},
"value":"1"
}
]
}
]
}
]
}
}
}
]
}
try this
{
"blocks": [
{
"type": "section",
"text": {
"type": "mrkdwn",
"text": "How do you rate the company?"
}
},
{
"type": "actions",
"elements": [
{
"type": "button",
"text": {
"type": "plain_text",
"text": "0"
},
"value": "0"
},
{
"type": "button",
"text": {
"type": "plain_text",
"text": "1"
},
"value": "1"
}
]
}
]
}
I've written my own library to respond to a Dialog Fulfillment webhook, but it's not working as the docs say that it should.
When my webhook is used for fulfilment the simple text response works, but suggestion chips do not. The "RESPONSE" tab in the Dialogflow console shows the response from my webhook:
{
"outputContexts": [ ],
"fulfillmentText": "Hi, how can I help you?",
"fulfillmentMessages": [
{ "text": {"text": ["Hi, how can I help you?"]} },
{ "suggestions": {"suggestions": [{"title": "Looking for a job"}]} }
],
"payload": {
"google": {
"expectUserResponse": true,
"expectedInputs": [{
"possibleIntents": [{"intent": "actions.intent.TEXT"}, {"intent": "JobSearch"}],
"speechBiasingHints": ["looking for a job"],
"inputPrompt": {
"richInitialPrompt": {
"items": [
{"simpleResponse": { "textToSpeech": "Hi, How can I help you?"}}
],
"suggestions": [{"title": "Looking for a job"}]
}
}
}
]
}
}
}
When I disable my webhook and and provide a response message and suggestions in the console the suggestions do show, but the RESPONSE tab looks more like my payload.google field:
{
"conversationToken": "[]",
"expectUserResponse": true,
"expectedInputs": [
{
"inputPrompt": {
"richInitialPrompt": {
"items": [
{"simpleResponse": {"textToSpeech": "Response from Dialogflow"}}
],
"suggestions": [{"title": "Dialogflow suggestion"}]
}
},
"possibleIntents": [{"intent": "assistant.intent.action.TEXT"}],
"speechBiasingHints": []
}
],
"responseMetadata": {
"status": {"message": "Success (200)"},
"queryMatchInfo": {"queryMatched": true, "intent": "..."}
}
}
Oh - the payload in the Dialogflow webhook response does NOT have the same format as the Conversation webhook response.
They have similarities, but also important differences.
I'm trying to end a conversation dynamically in my dialogflow action.
I've tried setting the expectedUserResponse field to false but so far the only way I've been able to get my action to leave the conversation is to have the toggle button enabled for the intent in the dialogflow setup.
I'm not using any SDK, only passing JSON back and forth in my fulfillment service.
Here's an example of the json that's unsuccessful in ending the conversation:
{
"payload": {
"google": {
"expectedUserResponse": false,
"richResponse": {
"items": [
{
"simpleResponse": {
"textToSpeech": "Okay."
}
}
]
}
}
}
}
Is there a way to do this without having the intent statically declared as an end to the conversation or using the sdk?
The attribute is expectUserResponse, without the "ed".
So this should work:
{
"payload": {
"google": {
"expectUserResponse": false,
"richResponse": {
"items": [
{
"simpleResponse": {
"textToSpeech": "Okay."
}
}
]
}
}
}
}
I am trying to send a response from my webhook to trigger the process to change to another surface, but Actions on Google always throws:
MalformedResponse 'final_response' must be set.
And that it's not very helpful.
This is the JSON I am returning:
{
"payload": {
"google": {
"expectUserResponse": true,
"conversationToken": "{\"data\":{}}",
"userStorage": "{\"data\":{}}",
"expectedInputs": [
{
"inputPrompt": {
"richInitialPrompt": {
"items": [
{
"simpleResponse": {
"textToSpeech": "PLACEHOLDER"
}
}
]
}
},
"possibleIntents": [
{
"intent": "actions.intent.NEW_SURFACE",
"inputValueData": {
"#type": "type.googleapis.com/google.actions.v2.NewSurfaceValueSpec",
"capabilities": [
{
"name": "actions.capability.SCREEN_OUTPUT"
}
],
"context": "Sure, I have some sample images for you.",
"notificationTitle": "Sample Images"
}
}
]
}
]
}
}
}
On Dialogflow I have setup 2 intents; one intent that returns the json specified here, and another intent with the event actions_intent_NEW_SURFACE, so I know what the user responded to the question to change surface.
I have been reading these sites:
https://developers.google.com/actions/assistant/surface-capabilities#multi-surface_conversations
https://dialogflow.com/docs/reference/api-v2/rest/Shared.Types/WebhookResponse
https://developers.google.com/actions/build/json/dialogflow-webhook-json#dialogflow-response-body
Action On Google, webhook response with actions.intent.NEW_SURFACE (This seems like the same problem has I have, but the OP didn't write the response.)
But none of them throw me some light on this matter.
It looks like you're trying to send a full Action SDK body as part of your Dialogflow response. While the payload.google portion of the JSON contains objects that are similar to the Action SDK response, there are some differences. You can see https://developers.google.com/actions/build/json/dialogflow-webhook-json#dialogflow-response-body for a full example of what the response should be when using a helper, but I think your response needs to be something like
{
"payload": {
"google": {
"expectUserResponse": true,
"userStorage": "{\"data\":{}}",
"richResponse": {
"items": [
{
"simpleResponse": {
"textToSpeech": "PLACEHOLDER"
}
}
]
},
"systemIntent": {
"intent": "actions.intent.NEW_SURFACE",
"inputValueData": {
"#type": "type.googleapis.com/google.actions.v2.NewSurfaceValueSpec",
"capabilities": [
"actions.capability.SCREEN_OUTPUT"
],
"context": "Sure, I have some sample images for you.",
"notificationTitle": "Sample Images"
}
}
}
}
}
I built a bot using Dialogflow and connected it to a local webhook (now accessing it through ngrok). I am able to receive the response from Dialogflow but I am unable to replay to it. I followed the JSON structure as shown here - Test response from webhook. But I am getting the following error in Dialogflow.
Webhook call failed. Error: Failed to parse webhook JSON response:
Cannot find field: messages in message
google.cloud.dialogflow.v2.Intent.Message.
Following is the reply that I sent to Dialogflow -
{
"messages":[
{
"speech":"Text response",
"type":0
}
]
}
Please tell me what should be the exact format of the reply that I should send to Dialogflow.
From v1 to v2, the response object almost change completely. For just simple text, you can use like:
{
"fulfillmentText": "Text response",
"fulfillmentMessages": [
{
"text": {
"text": ["Text response"]
}
}
],
"source": "<Text response>"
}
I faced same issue,resolved using below json on dialogflow :
I made a simple node program which accepts a post response and returns json of the format accepted by Dialogflow.You may send your request in any way you like. check on Fulfillment status tab :
The field messageswas renamed/refactored to fulfillmentMessages - "can not find" means that it is not a property in the definition.
This is some comparable result accepted by v2:
{
"fulfillmentText": "response text",
"fulfillmentMessages": [{"simpleResponses": {"simpleResponses": [ {
"textToSpeech": "response text",
"displayText": "response text"
}]}}]
}
Messages alone is not sufficient. Refer to Dialogflow V2 webhook fulfillment documentation for complete list of parameters expected and format of JSON.
Are you sure you are using V2 of the DialogFlow APIs?
Use the Webhook Playground to Get the appropriate response for either the Dialogflow API or the Actions SDK which is depricated but still works. There is also the yet newer and different API for the Google Actions Builder/SDK framework as per :
DiaglowFlow JSON Response:
{
"payload": {
"google": {
"expectUserResponse": true,
"richResponse": {
"items": [
{
"simpleResponse": {
"textToSpeech": "Webhook worked.",
"displayText": "Webhook worked."
}
}
]
}
}
}
}
Actions SDK Response:
{
"expectUserResponse": true,
"expectedInputs": [
{
"inputPrompt": {
"richInitialPrompt": {
"items": [
{
"simpleResponse": {
"textToSpeech": "Webhook worked.",
"displayText": "Webhook worked."
}
}
]
}
},
"possibleIntents": [
{
"intent": "actions.intent.TEXT"
}
]
}
]
}
Action Builder/SDK. Note that the session id needs to be returned.
{
"session": {
"id": "example_session_id",
"params": {}
},
"prompt": {
"override": false,
"firstSimple": {
"speech": "Hello World.",
"text": ""
}
},
"scene": {
"name": "SceneName",
"slots": {},
"next": {
"name": "actions.scene.END_CONVERSATION"
}
}
}