How to make a carousel using Google.Cloud.Dialogflow.V2 Carousel for dialogflow? - dialogflow-es

Im trying to build a webhook for dialogflow with help from nuget package Google.Cloud.Dialogflow.V2.
Im running the code with .Net Core 2.1.
I get the fullfilmentText to show in dialogflow, but cant make the carousel to show up.
What am I doing wrong?
Here is my method:
[HttpPost]
public ContentResult Post([FromBody] WebhookRequest webhookRequest)
{
var dialogflowResponse = new WebhookResponse { FulfillmentText = "FulfillmentText" };
var carousel = new Intent.Types.Message.Types.CarouselSelect.Types.Item
{
Title = "My title",
Description = "This is a description",
Image = new Intent.Types.Message.Types.Image
{
ImageUri = "https://placekitten.com/200/300",
AccessibilityText = "cat"
},
Info = new Intent.Types.Message.Types.SelectItemInfo
{
Key = "Cats"
}
};
carousel.Info.Synonyms.Add("Synonym 1");
carousel.Info.Synonyms.Add("Synonym 1");
dialogflowResponse.FulfillmentMessages.Add(new Intent.Types.Message {
CarouselSelect = new Intent.Types.Message.Types.CarouselSelect()
});
dialogflowResponse.FulfillmentMessages.First().CarouselSelect.Items.Add(carousel);
return dialogflowResponse;
}
Generates followiing Json:
{
"fulfillmentText": "FulfillmentText",
"fulfillmentMessages": [
{
"carouselSelect": {
"items": [
{
"info": {
"key": "Cats",
"synonyms": [
"Synonym 1",
"Synonym 1"
]
},
"title": "My title",
"description": "This is a description",
"image": {
"imageUri": "https://placekitten.com/200/300",
"accessibilityText": "cat"
}
}
]
}
}
]
}

i ran into the same problem with the java api. Only the basic rich messages (card, quick replies, ...) are working. BasicCard, Suggestions, Carousel, ... doesn't show up in any channel.
I got it to work if i added some of the following custom payload to skype channel:
{
"skype": {
"type": "message",
"attachmentLayout": "carousel",
"text": "Please select your food.",
"attachments": [{
"contentType": "application/vnd.microsoft.card.hero",
"content": {
"title": "Sushi",
"subtitle": "Very fresh shrimp or tuna.",
"images": [{
"url": "https://i.ibb.co/87LmvT3/mdi.png"
}
],
"buttons": [{
"type": "imBack",
"title": "1 piece",
"value": "sushi,1"
}, {
"type": "imBack",
"title": "2 piece",
"value": "sushi,2"
}, {
"type": "imBack",
"title": "more",
"value": "sushi,3+"
}
]
}
}, {
"contentType": "application/vnd.microsoft.card.hero",
"content": {
"title": "Tenpura",
"subtitle": "Japanese first-class vegitables.",
"images": [{
"url": "https://i.ibb.co/87LmvT3/mdi.png"
}
],
"buttons": [{
"type": "imBack",
"title": "1 piece",
"value": "tenpura,1"
}, {
"type": "imBack",
"title": "2 piece",
"value": "tenpura,2"
}, {
"type": "imBack",
"title": "more",
"value": "tenpura,3+"
}
]
}
}
]
}}
I hope it helps!

Related

Why does Alexa SDK throw an error when migrating from Dialogflow

I'm trying to migrate my action form Dialogflow, and the most important thing is the intent schema. But after uploading the .json file, the error Intent name must not be empty. Error code: MissingIntentName is thrown. Here is Intent schema.json
{
"intents": [
{
"intent": "SelectedSubjectsYes"
},
{
"intent": "UserIsOk",
"slots": [
{
"name": "okslot",
"type": "OK"
}
]
},
{
"intent": "SelectedSubjectsNo"
},
{
"intent": "UserIsNotOk",
"slots": [
{
"name": "not_okslot",
"type": "NOT_OK"
}
]
},
{
"intent": "DefaultWelcomeIntent"
},
{
"intent": "HowAreYou?"
},
{
"intent": "SelectedSubjects",
"slots": [
{
"name": "subjectslot",
"type": "SUBJECT"
}
]
}
]
}
I've in no way edited it, so why the error? Thanks in advance.
The JSON structure for interaction model is sightly different. This is how it should look now.
{
"interactionModel": {
"languageModel": {
"invocationName": "Your invocation name",
"intents": [
{
"name": "SelectedSubjectsYes",
"slots": [],
"samples": [
"provide sample for SelectedSubjectsYes intent",
"sample for SelectedSubjectsYes intent"
]
},
{
"name": "UserIsOk",
"slots": [
{
"name": "okslot",
"type": "OK"
}
],
"samples": [
"provide other samples for UserIsOk",
"I'm {okslot}",
"{okslot}"
]
},
{
"name": "SelectedSubjectsNo",
"slots": [],
"samples": [
"provide sample for SelectedSubjectsNo intent",
"sample for SelectedSubjectsNo intent"
]
},
{
"name": "UserIsNotOk",
"slots": [
{
"name": "not_okslot",
"type": "NOT_OK"
}
],
"samples": [
"provide other samples for UserIsNotOk",
"i'm {not_okslot}",
"{not_okslot}"
]
},
{
"name": "HowAreYou?",
"slots": [],
"samples": [
"provide sample for HowAreYou intent",
"sample for HowAreYou intent"
]
},
{
"name": "SelectedSubjects",
"slots": [
{
"name": "subjectslot",
"type": "SUBJECT"
}
],
"samples": [
"provide other samples for SelectedSubjects",
"i choose {subjectslot}"
]
}
],
"types": [
{
"name": "OK",
"values": [
{
"name": {
"value": "ok"
}
},
{
"name": {
"value": "yes"
}
}
]
},
{
"name": "NOT_OK",
"values": [
{
"name": {
"value": "not ok"
}
},
{
"name": {
"value": "nope"
}
}
]
},
{
"name": "SUBJECT",
"values": [
{
"name": {
"value": "Physics"
}
},
{
"name": {
"value": "Biology"
}
}
]
}
]
}
}
}
Rather than converting from Dialog flow, it's pretty easy to design one in Alexa skill builder. Also, it is recommended to use predefined AMAZON.YesIntent and AMAZON.NoIntent for "yes" or "no" utterances.

Dialogflow v2 API - cards not shown in the simulator

I've a webhook for fulfillment.
Below is the code that's responding back
let result_obj = {
"fulfillmentText": "This is a text response",
"fulfillmentMessages": [
{
"text": {
"text": [
"this is test"
]
}
},
{
"card": {
"title": "card title",
"subtitle": "card text",
"imageUri": "https://assistant.google.com/static/images/molecule/Molecule-Formation-stop.png",
"buttons": [
{
"text": "button text",
"postback": "https://assistant.google.com/"
}
]
}
}
]
}
Below is the result from dialogflow GUI
Below is what I get when I run from the simulator or from the Google Assistant application on the Android phone
Both the simulator and phone are not showing the cards. Am I missing something obvious here?
For rich responses like cards to show on Google Assistant you have to use the payload part of response JSON, here is an example:
{
"fulfillmentText": "This is a text response",
"fulfillmentMessages": [],
"source": "example.com",
"payload": {
"google": {
"expectUserResponse": true,
"richResponse": {
"items": [
{
"simpleResponse": {
"textToSpeech": "This is a Basic Card:"
}
},
{
"basicCard": {
"title": "card title",
"image": {
"url": "https://www.google.com/images/branding/googlelogo/2x/googlelogo_color_272x92dp.png",
"accessibilityText": "Google Logo"
},
"buttons": [
{
"title": "Button Title",
"openUrlAction": {
"url": "https://www.google.com"
}
}
],
"imageDisplayOptions": "WHITE"
}
}
]
}
}
},
"outputContexts": [],
"followupEventInput": {}
}
Check out this github repo for all rich-responses' JSON formats.

webhook doesn't receive event from m.me link

I've been trying to pass parameter using m.me link, but when tester/ developer account of my app tried this feature, my webhook didn't receive any event.
My bot already has a get started button and the page is published.
what im trying to ask is why couldn't i get any event and how to solve this problem?
let message = {
"attachment": {
"type": "template",
"payload": {
"template_type": "generic",
"elements": [
{
"title": "Share me 😊",
"subtitle": "share to your friend",
"image_url": "https://gallery.yopriceville.com/var/resizes/Free-Clipart-Pictures/Sun-and-Moon-PNG/Transparent_Sun_with_Shades_PNG_Clipart_Picture.png?m=1434276589",
"buttons": [
{
"type": "element_share",
"share_contents": {
"attachment": {
"type": "template",
"payload": {
"template_type": "generic",
"elements": [
{
"title": "Add to connect to your friend",
"subtitle": "connect",
"image_url": output.profile_pic,
"default_action": {
"type": "web_url",
"url": `http://m.me/${page_id}?ref=invited_by_${recipientId}`
},
"buttons": [
{
"type": "web_url",
"url": `http://m.me/${page_id}?ref=invited_by_${recipientId}`,
"title": `ADD ${output.first_name}`
}
]
}
]
}
}
}
}
]
}
]
}
}
};

Adaptive Cards doesn't work in MBF's Emulator running in Ubuntu 16.04

I am trying to implement AdaptiveCard into one of my dialogs using node.js. However once I run the emulator I get the following message instead of rendered AdaptiveCard:
[File of type 'application/vnd.microsoft.card.adaptive'].
Can anyone tell me what can be the problem?
I am running on Ubuntu 16.04, MBF Emulator v.3.5.31-alpha, microsoft-adaptivecards v.0.6.1.
Here is code from inside of one of my dialogs:
var msg = new builder.Message(session)
.addAttachment({
contentType: "application/vnd.microsoft.card.adaptive",
content: {
type: "AdaptiveCard",
body: [
{
"type": "TextBlock",
"text": msg_text,
},
{
"type": "Input.ChoiceSet",
"id": "myColor4",
"isMultiSelect": true,
"value": "1",
"style": "expanded",
"choices": [
{
"title": "Red",
"value": "1",
"isSelected": true
},
{
"title": "Green",
"value": "2"
},
{
"title": "Blue",
"value": "3",
"isSelected": true
}
]
}
],
"actions": [
{
"type": "Action.Submit",
"title": "Sent",
"data": {
"myProperty": 12
}
}
],
}
});
session.send(msg);
This is detailed response, it contains all elements of the AdaptiveCard that I declared(but still it does not render):
{
"type": "message",
"attachments": [
{
"contentType": "application/vnd.microsoft.card.adaptive",
"content": {
"type": "AdaptiveCard",
"body": [
{
"type": "TextBlock",
"text": "What color do you want?"
},
{
"type": "Input.ChoiceSet",
"id": "myColor4",
"isMultiSelect": true,
"value": "1",
"style": "expanded",
"choices": [
{
"title": "Red",
"value": "1",
"isSelected": true
},
{
"title": "Green",
"value": "2"
},
{
"title": "Blue",
"value": "3",
"isSelected": true
}
]
}
],
"actions": [
{
"type": "Action.Submit",
"title": "Sent",
"data": {
"myProperty": 12
}
}
]
}
}
],
"locale": "en-US",
"localTimestamp": "2017-09-17T19:21:17+02:00",
"from": {
"id": "default-bot",
"name": "Bot"
},
"recipient": {
"id": "default-user"
},
"inputHint": "acceptingInput",
"id": "heam84b9dn5b",
"replyToId": "71j1d6mbmk3l",
"channelId": "emulator",
"timestamp": "2017-09-17T17:21:17.379Z",
"conversation": {
"id": "fdikc23llm5"
}
}

List_card in AoG passing item title to the next query instead of key

In an app, I'm returning messages of type list_card with option key for an intent.
Here is the json of a sample query:
{
"id": "275212ef-cf97-4576-afa7-facfbc044ada",
"timestamp": "2017-07-17T17:36:03.655Z",
"lang": "en",
"result": {
"source": "agent",
"resolvedQuery": "who is Sneha",
"action": "cp.name_search",
"actionIncomplete": false,
"parameters": {
"keyword": "Sneha"
},
"contexts": [
{
"name": "cpname_search-followup",
"parameters": {
"keyword.original": "Sneha",
"keyword": "Sneha"
},
"lifespan": 2
},
{
"name": "cpuid_search-followup",
"parameters": {
"keyword.original": "Sneha",
"keyword": "Sneha"
},
"lifespan": 1
}
],
"metadata": {
"intentId": "86bd1a17-8e9a-4956-b270-5fb4ac952f5f",
"webhookUsed": "true",
"webhookForSlotFillingUsed": "false",
"webhookResponseTime": 135,
"intentName": "cp.name_search"
},
"fulfillment": {
"speech": "Searching...",
"source": "agent",
"messages": [
{
"type": "simple_response",
"platform": "google",
"textToSpeech": "Here are the search results. \nWant anything else?"
},
{
"type": "list_card",
"platform": "google",
"title": "Search results",
"items": [
{
"optionInfo": {
"key": "uid 72",
"synonyms": []
},
"title": "Sneha Vasista",
"description": "Srinivas Institute of Technology",
"image": {
"url": "//www.curlpad.com/assets/img/custom_images/user.png"
}
},
{
"optionInfo": {
"key": "uid 2053",
"synonyms": []
},
"title": "Sneha Bhat",
"description": "Canara Engineering College",
"image": {
"url": "//www.curlpad.com/assets/img/custom_images/user.png"
}
},
{
"optionInfo": {
"key": "uid 2114",
"synonyms": []
},
"title": "Sneha Sajan",
"description": "P.A College of Engineering",
"image": {
"url": "//www.curlpad.com/assets/img/custom_images/user.png"
}
},
{
"optionInfo": {
"key": "uid 2320",
"synonyms": []
},
"title": "Sneha ",
"description": "sdit",
"image": {
"url": "//www.curlpad.com/assets/img/custom_images/user.png"
}
},
{
"optionInfo": {
"key": "uid 2363",
"synonyms": []
},
"title": "Sneha ",
"description": "Srinivas School of Engineering, Mukka",
"image": {
"url": "//www.curlpad.com/assets/img/custom_images/user.png"
}
}
]
},
{
"type": "0",
"speech": "Here are the search results."
}
]
},
"score": 1
},
"status": {
"code": 200,
"errorType": "success"
},
"sessionId": "e6aa9e52-a9e1-481a-adb5-476c5b386e02"
}
Now the problem is, when I tap the list item in AoG simulator, it passes title of item to next query.
But while testing in Api.ai simulator, it behaves well and passes that key to the next query.
What can be the problem here?
Any hints?
If you're using API.AI, then it will appear in the Intent as an actions_intent_OPTION Event.
One good solution is to have the Intent that sends the list with an OutputContext. Then create a particular Fallback Intent with actions_intent_OPTION as Event and your desired action for that Context which should handle both the voice and press responses.
And you will find your option_key at ["originalRequest"]["data"]["inputs"][0]["arguments"][0]["textValue"] instead of parameter.
You can also see the response value in the actions_intent_option context.
What you need to do is set up a fallback intent directly under your current intent.
For example, if you display the list from the default welcome intent, you can do the following.
Click "Add follow-up intent" and choose fallback.
Don't forget to set the action and enable webhook in the fallback intent.
Now, you should be able to retrieve your answer from the fallback intent using the following code.
const param = app.getContextArgument('actions_intent_option','OPTION').value;

Resources