Created
June 3, 2017 19:23
-
-
Save treethought/9735618a83664e6f1377a5e6a4141cd8 to your computer and use it in GitHub Desktop.
An example of an API.AI webhook rich response for Actions on Google integration
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Providing the following resposne to API.AI from a webhook produces a rich response list | |
# API.AI parses the messages and sends an appropriately formmated response to Actions.abs | |
# However, the API and Actions appear to be on different api versions currently.abs | |
# Therefore, in API.AI when a user selects a list object, the object's "key" is sent to API.AI | |
# as a user query to trigger thenext intent. In Actions, the items title is sent | |
list_response_data = { | |
"contextOut": [], | |
"data": { | |
"google": { | |
"expect_user_response": true, | |
"is_ssml": true, | |
"permissions_request": null | |
} | |
}, | |
"messages": [ | |
{ | |
"speech": "Output speech", # this is the message required Api.AI's web interface | |
"type": 0 | |
}, | |
# Below are the Actions Rich Messages | |
{ | |
"displayText": "This is displayed on screen", | |
"platform": "google", | |
"textToSpeech": "Google Assistant speaks this", | |
"type": "simple_response" | |
}, | |
{ | |
"platform": "google", | |
"title": "Awesome List", | |
"type": "list_card" | |
"items": [ | |
{ | |
"description": "Choose me for item 1", | |
"image": { | |
"accessibilityText": "Item 1 image fallback", | |
"url": "http://image1.example.png" | |
}, | |
"optionInfo": { | |
"key": "item_one", # sent to API.AI as query | |
"synonyms": [ | |
"first", | |
"number one", "one", | |
"top" | |
] | |
}, | |
"title": "Item One" # sent to Actions as query | |
}, | |
{ | |
"description": "Choose me for item 2", | |
"image": { | |
"accessibilityText": "Item 2 image fallback", | |
"url": "http://image2.example.png" | |
}, | |
"optionInfo": { | |
"key": "item_two, # sent to API.AI as query" | |
"synonyms": [ | |
"second", | |
"number two", "two", | |
"bottom" | |
] | |
}, | |
"title": "Item Two" # sent to Actions as query | |
} | |
] | |
} | |
], | |
"source": "webhook", | |
"speech": "Output speech" | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Is there a way I can direct the user to a specific URL once he clicks on Item Two?