IBM Watson Assistant / Conversation : The output displays the last search - ibm-cloud

I have developed cloud functions and am using 'generic output' with image response types, as well as text. However when I search for a product (which uses my cloud function), the last result appears.
For example:
Me: Buy Classic now
Bot: Name: Classic, Price: 4.99, Description: Classic description
But when I search for another product
Me: Buy Extra now
the bot will display
Bot: Name: Classic, Price: 4.99, Description: Classic description
Only until another search instance does it refresh and display the correct result.
{
"context": {
"name": "",
"counter": 0
},
"output": {
"generic": [
{
"values": [
{
"text": "Found Products"
}
],
"response_type": "text",
"selection_policy": "sequential"
},
{
"title": "<? $result.body.items[0].name ?>",
"source": "http://**********/pub/media/catalog/product<? $result.body.items[0].custom_attributes[5].value ?>",
"description": "$<? $result.body.items[0].price ?>",
"response_type": "image"
},
{
"title": "Select one of the following options",
"options": [
{
"label": "Order a subscription",
"value": {
"input": {
"text": "Order a subscription"
}
}
},
{
"label": "More Details",
"value": {
"input": {
"text": "More Details"
}
}
}
],
"response_type": "option"
}
]
},
"actions": [
{
"name": "/**********#gmail.com_dev/getProducts2",
"type": "server",
"parameters": {
"url": "<?entities.products[0].literal?>"
},
"credentials": "$my_creds",
"result_variable": "context.result"
}
]
}

Found the answer. I put the output text in a child node instead of the parent node. No need to remove any context variable.

Related

Sending WhatsApp interactive message of list type fails when sent with image header

I am able to send interactive message with "button" type and 3 buttons with image header.
But sending interactive message with "list" type and same image header fails with error:
{
"meta": {
"api_status": "stable",
"version": "2.39.4"
},
"errors": [
{
"code": 1008,
"title": "Required parameter is missing",
"details": "Failed building interactive message. Invalid Header."
}
]
}
Is it possible that "list" interactive messages doesn't support "image" header without stating it in documentation?
Successful "button" interactive payload (image URL changed):
{
"to": "972000000000",
"type": "interactive",
"interactive": {
"body": {
"text": "Select a branch for the takeaway by writing the name/number"
},
"action": {
"buttons": [
{
"reply": {
"id": "MQ==",
"title": "1"
},
"type": "reply"
},
{
"reply": {
"id": "Mg==",
"title": "2"
},
"type": "reply"
}
]
},
"type": "button",
"header": {
"image": {
"link": "https://www.google.com/images/branding/googlelogo/2x/googlelogo_light_color_272x92dp.png"
},
"type": "image"
}
}
}
Successful "button" interactive message result:
Failed "list" interactive payload (image URL changed):
{
"to": "972000000000",
"type": "interactive",
"interactive": {
"body": {
"text": "Select a branch for the takeaway by writing the name/number"
},
"action": {
"button": "Options",
"sections": [
{
"rows": [
{
"id": "MQ==",
"title": "1"
},
{
"id": "Mg==",
"title": "2"
},
{
"id": "Mw==",
"title": "3"
},
{
"id": "NA==",
"title": "4"
},
{
"id": "NQ==",
"title": "5"
},
{
"id": "Ng==",
"title": "6"
},
{
"id": "Nw==",
"title": "7"
},
{
"id": "OA==",
"title": "8"
},
{
"id": "OQ==",
"title": "9"
},
{
"id": "MTA=",
"title": "10"
}
]
}
]
},
"type": "list",
"header": {
"image": {
"link": "https://www.google.com/images/branding/googlelogo/2x/googlelogo_light_color_272x92dp.png"
},
"type": "image"
}
}
}
Well, it does state it in the docs. I'm just blind:
Kinda weird though "image" header not supported for "list".

How to do Generic Template of messenger Facebook with IBM Watson Assistant Dialog

I have a working Assistant from IBM Watson I want to show multiple choices as Image, Description, and Link combinations this feature is available for messenger under Generic Template but I cant find an option at dialog responses that can get me do this image
{
"output": {
"generic": [
{
"values": [
{
"text": "I got that"
}
],
"response_type": "text",
"selection_policy": "sequential"
}
],
"facebook": {
"message": {
"attachment": {
"type": "template",
"payload": {
"template_type": "generic",
"elements": [
{
"title": "Welcome!",
"image_url": "https://petersfancybrownhats.com/company_image.png",
"subtitle": "We have the right hat for everyone.",
"default_action": {
"type": "web_url",
"url": "https://petersfancybrownhats.com/view?item=103",
"webview_height_ratio": "tall"
},
"buttons": [
{
"type": "web_url",
"url": "https://petersfancybrownhats.com",
"title": "View Website"
},
{
"type": "postback",
"title": "Start Chatting",
"payload": "DEVELOPER_DEFINED_PAYLOAD"
}
]
}
]
}
}
}
}
}
}
I have used this JSON at the dialog node with no success
If any one is facing the same problem you should do it as output.integrations.facebook not output.facebook
so the object will be mothing like that
{
"output": {
"generic": [
{
"values": [
{
"text": "I got that"
}
],
"response_type": "text",
"selection_policy": "sequential"
}
],
"facebook": {
"message": {
"attachment": {
"type": "template",
"payload": {
"template_type": "generic",
"elements": [
{
"title": "Welcome!",
"image_url": "https://petersfancybrownhats.com/company_image.png",
"subtitle": "We have the right hat for everyone.",
"default_action": {
"type": "web_url",
"url": "https://petersfancybrownhats.com/view?item=103",
"webview_height_ratio": "tall"
},
"buttons": [
{
"type": "web_url",
"url": "https://petersfancybrownhats.com",
"title": "View Website"
},
{
"type": "postback",
"title": "Start Chatting",
"payload": "DEVELOPER_DEFINED_PAYLOAD"
}
]
}
]
}
}
}
}
}
}

Pass callback_id without attachments in Slack

I'm using Slack Api to send message.
So, I have this block message:
{
"blocks": [
{
"type": "divider"
},
{
"type": "section",
"text": {
"type": "mrkdwn",
"text": "Do you have access ?"
}
},
{
"type": "actions",
"elements": [
{
"type": "button",
"text": {
"type": "plain_text",
"emoji": true,
"text": "Yes"
},
"style": "primary",
"value": "click_me_123"
},
{
"type": "button",
"text": {
"type": "plain_text",
"emoji": true,
"text": "Skip"
},
"style": "danger",
"value": "click_me_123"
}
]
}
]
}
As you see, this is block message and it have no any attachments. So, it doesn't send any callback_id when click button Yes or No. But I need send callback_id when click button Yes or No. How can do that?
Or another hack. Anyway to remove border left of attachments?
Thanks.
Am assuming you are looking to have a way to let your code parse the choices when the button is pressed. You need to assign the unique value that you can parse and determine the choice. Something like
{
"type": "actions",
"elements": [
{
"type": "button",
"text": {
"type": "plain_text",
"emoji": true,
"text": "Yes"
},
"style": "primary",
"value": "yes"
},
{
"type": "button",
"text": {
"type": "plain_text",
"emoji": true,
"text": "Skip"
},
"style": "danger",
"value": "skip"
}
]
}

Google Assistant flow with multiple actions_intent_OPTION handlers

I have webhooks configured through Dialogflow for a template chatbot UI starter project I'm making on Github. I have a bot integrated through Facebook Messenger and Google Assistant. All of Facebook works fine because the actions send back strings and it's easy to handle. But when Google Assistant tries to handle items of "#type": "type.googleapis.com/google.actions.v2.OptionValueSpec", actions_intent_OPTION is needed on the event in Dialogflow to handle the response. If I have just one in my app, it works fine, but when I add a second list item / carousel item of type OptionValueSpec, the flow chokes. I have details on the attached image. My guess is actions_intent_OPTION is needed to handle the list, but when I put that on multiple intents on the events section, the flow doesn't know how to handle it.
Comparison of Facebook Messenger (working) to Google Assistant (with bug)
Detailed full flow view of Google Assistant
Responses sent to Dialogflow that subsequently get sent to Google Actions...
Exact responses related to the UI pics above.
// working as expected
{
"richResponse": {
"items": [{
"simpleResponse": {
"textToSpeech": "Hey there! This is a guided tour of common components between Facebook Messenger and Google Assistant."
}
},
{
"simpleResponse": {
"textToSpeech": "You can start coding the sample project at github.com/ianrichard."
}
}
],
"suggestions": [{
"title": "Show me demos!"
},
{
"title": "Show code & docs"
}
]
}
}
// working as expected
{
"richResponse": {
"items": [{
"simpleResponse": {
"textToSpeech": "Animated GIFs are always fun to add to the mix!"
}
},
{
"basicCard": {
"image": {
"url": "https://somewebsite.com/colbert.gif",
"accessibilityText": "Stephen Colbert at the beginning of the show being happy."
}
}
}
],
"suggestions": [{
"title": "What about a card?"
}]
}
}
// working as expected
{
"richResponse": {
"items": [{
"simpleResponse": {
"textToSpeech": "Absolutely!"
}
},
{
"simpleResponse": {
"textToSpeech": "Named for a winding stretch of Hill Country highway, Devil’s Backbone is a Belgian-style tripel. Featuring a beautiful pale-golden color, this ale’s spicy hops and Belgian yeast work together to create a distinctive flavor and aroma. Don’t let the light color fool you, this one has a dark side too. Traditional Belgian brewing techniques add strength without increasing heaviness."
}
},
{
"basicCard": {
"image": {
"url": "https://somewebsite.com/devils-backbone.jpg",
"accessibilityText": "Devil’s Backbone"
},
"title": "Devil’s Backbone",
"subtitle": "Belgian-Style Tripel",
"buttons": [{
"title": "Read More",
"openUrlAction": {
"url": "https://realalebrewing.com/beers/devils-backbone/"
}
}]
}
}
],
"suggestions": [{
"title": "How about a list?"
}]
}
}
// working as expected
{
"richResponse": {
"items": [{
"simpleResponse": {
"textToSpeech": "Absolutely!"
}
},
{
"simpleResponse": {
"textToSpeech": "Who’s your favorite GOT character!?"
}
}
]
},
"systemIntent": {
"intent": "actions.intent.OPTION",
"data": {
"#type": "type.googleapis.com/google.actions.v2.OptionValueSpec",
"listSelect": {
"items": [{
"optionInfo": {
"key": "tyrion"
},
"title": "Tyrion Lannister",
"description": "Peter Dinklage",
"image": {
"url": "https://somewebsite.com/got-tyrion.jpg",
"accessibilityText": "Tyrion Lannister"
}
},
{
"optionInfo": {
"key": "daene"
},
"title": "Daenerys Targaryen",
"description": "Emilia Clarke",
"image": {
"url": "https://somewebsite.com/got-daenerys.jpg",
"accessibilityText": "Daenerys Targaryen"
}
},
{
"optionInfo": {
"key": "jon"
},
"title": "Jon Snow",
"description": "Kit Harington",
"image": {
"url": "https://somewebsite.com/got-jon.jpg",
"accessibilityText": "Jon Snow"
}
}
]
}
}
}
}
// if two events with the same actions_intent_OPTION are defined, it goes straight to the end and the list option handler is never invoked
{
"richResponse": {
"items": [{
"simpleResponse": {
"textToSpeech": "The end"
}
},
{
"simpleResponse": {
"textToSpeech": "Well, that’s the end of the demo. Hope you enjoyed!"
}
}
],
"suggestions": [{
"title": "Start over"
}]
}
}
// otherwise, it will show the last carousel
{
"richResponse": {
"items": [{
"simpleResponse": {
"textToSpeech": "I drink and I know things!"
}
},
{
"simpleResponse": {
"textToSpeech": "What are you going to buy your wife from Tiffany?"
}
}
]
},
"systemIntent": {
"intent": "actions.intent.OPTION",
"data": {
"#type": "type.googleapis.com/google.actions.v2.OptionValueSpec",
"carouselSelect": {
"items": [{
"optionInfo": {
"key": "sunglasses"
},
"title": "Aviator Sunglasses",
"description": "$360",
"image": {
"url": "https://somewebsite.com/tiffany-glasses.jpg",
"accessibilityText": "Aviator Sunglasses"
}
},
{
"optionInfo": {
"key": "ring"
},
"title": "Infinity Ring",
"description": "$200",
"image": {
"url": "https://somewebsite.com/tiffany-ring.jpg",
"accessibilityText": "Infinity Ring"
}
},
{
"optionInfo": {
"key": "earrings"
},
"title": "Soleste Earrings",
"description": "$5,600",
"image": {
"url": "https://somewebsite.com/tiffany-earrings.jpg",
"accessibilityText": "Soleste Earrings"
}
},
{
"optionInfo": {
"key": "pendant"
},
"title": "Infinity Pendant",
"description": "$250",
"image": {
"url": "https://somewebsite.com/tiffany-necklace.jpg",
"accessibilityText": "Infinity Pendant"
}
},
{
"optionInfo": {
"key": "watch"
},
"title": "East West Mini",
"description": "$7,500",
"image": {
"url": "https://somewebsite.com/tiffany-watch.jpg",
"accessibilityText": "East West Mini"
}
}
]
}
}
}
}
// but the carousel option handler isn't processed correctly :( - keeps repeating this same thing.
{
"richResponse": {
"items": [{
"simpleResponse": {
"textToSpeech": "What!? None of them?"
}
},
{
"simpleResponse": {
"textToSpeech": "What are you going to buy your wife from Tiffany?"
}
}
]
},
"systemIntent": {
"intent": "actions.intent.OPTION",
"data": {
"#type": "type.googleapis.com/google.actions.v2.OptionValueSpec",
"carouselSelect": {
"items": [{
"optionInfo": {
"key": "sunglasses"
},
"title": "Aviator Sunglasses",
"description": "$360",
"image": {
"url": "https://somewebsite.com/tiffany-glasses.jpg",
"accessibilityText": "Aviator Sunglasses"
}
},
{
"optionInfo": {
"key": "ring"
},
"title": "Infinity Ring",
"description": "$200",
"image": {
"url": "https://somewebsite.com/tiffany-ring.jpg",
"accessibilityText": "Infinity Ring"
}
},
{
"optionInfo": {
"key": "earrings"
},
"title": "Soleste Earrings",
"description": "$5,600",
"image": {
"url": "https://somewebsite.com/tiffany-earrings.jpg",
"accessibilityText": "Soleste Earrings"
}
},
{
"optionInfo": {
"key": "pendant"
},
"title": "Infinity Pendant",
"description": "$250",
"image": {
"url": "https://somewebsite.com/tiffany-necklace.jpg",
"accessibilityText": "Infinity Pendant"
}
},
{
"optionInfo": {
"key": "watch"
},
"title": "East West Mini",
"description": "$7,500",
"image": {
"url": "https://somewebsite.com/tiffany-watch.jpg",
"accessibilityText": "East West Mini"
}
}
]
}
}
}
}
Intent References
FINALLY works! Thanks #Prisoner!
In Dialogflow...
First list, define the output context
Second list, define the input context and output context
Question after the second list, define the input context
In your webhook...
(The missing piece of the puzzle that made it work)
Set the output context for the list options
{
"speech": "",
"displayText": "",
"data": { "google": { ... } },
"contextOut": [
{
"name": "carouselExample",
"lifespan": 0,
"parameters": null
}
]
}
Broadly speaking, the problem is that Dialogflow doesn't know where in the conversation you are when it gets the action_intent_OPTION event. For that event, it doesn't try to do Entity matching, but the issue of conversational context is a problem in general (what happens, for example, if you have two different option carousels which have overlapping answers?).
The solution is twofold:
When you send back the response that includes the option information, you should also set an outgoing Context. You can include other information in this Context, but in your case it sounds mostly like you just want to keep track of where you are in the conversation.
You can then differentiate the two Intents with the option event by specifying which context each should be triggered for. Dialogflow will match both the event and the context to determine the best Intent to use.

Gupshup consume post to create Embedding form

im working with Gupshup and I want to add subview in my chat.
To make this I create this vars:
var url="https://api.gupshup.io/sm/api/facebook/smartmsg/form/create";
var header = {"apikey":"xxxxxxxxxxxxxxxxxxx","Content-Type": "application/x-www-form-urlencoded","Accept":"application/json"};
var param={"formJSON":{
"title": "This is a test.",
"autoClose": false,
"message": "Thank You",
"callback-url": "https://www.gupshup.io/developer/bot/Cotizador/public",
"fields": [{
"type": "fbid",
"name": "fbname",
"label": "fbName"
}, {
"type": "input",
"name": "name",
"label": "Name",
"validations": [{
"regex": "^[A-Z a-z]+$",
"msg": "Only alphabets are allowed in this field"
}, {
"regex": "^[A-Z a-z]{6,}$",
"msg": "Minimum 6 characters required"
}]
}, {
"type": "radio",
"name": "gender",
"label": "Gender",
"options": [
"Male",
"Female"
],
"validations": [{
"regex": "",
"msg": ""
}]
}, {
"type": "select",
"name": "account",
"label": "AccountType",
"options": [
"current",
"savings"
],
"validations": [{
"regex": "",
"msg": ""
}]
}, {
"type": "checkbox",
"name": "interest",
"label": "Interests",
"options": [
"Cooking",
"Reading"
],
"validations": [{
"regex": "",
"msg": ""
}]
}],
"users": [
"Testing"
]
}}
And call post with:
context.simplehttp.makePost(url,JSON.stringify(param),header,parser);
And my call back
function parser(context, event) {
context.console.log("Handler https")
var result= JSON.parse(event.getresp);
if(result=="success"){
context.sendResponse("We have successfully stored your data");
}else{
context.sendResponse("We dont shoot");
}
}
But when, make the request post, but don't show me response in chat or in callback. What im doing wrong?
Sohan from Gupshup here.
The result from the API that you are using is this:
[{
"embedlink": "https://api.gupshup.io/sm/api/facebook/smartmsg/embed/66438dde-ec76-4d6e-a0d0-8cfc0c730e57",
"expired": false,
"fb-button": {
"title": "This is a test.",
"type": "web_url",
"url": "https://api.gupshup.io/sm/api/facebook/smartmsg/embed/66438dde-ec76-4d6e-a0d0-8cfc0c730e57",
"webview_height_ratio": "tall"
},
"id": "66438dde-ec76-4d6e-a0d0-8cfc0c730e57",
"signed-for": {
"display": "Testing",
"subdisplay": "Testing"
},
"smid": "1009"
}]
Thus when you do:
var result= JSON.parse(event.getresp);
if(result=="success"){
context.sendResponse(result) will display the entire JSON that you see above. To display the 'expired' field you can use result.expired.
Check this document for more information.