storing values from fb messenger bot into dialog flow - facebook

i am trying to build a simple bot using dialog flow and fb messenger. i have requirement to show two buttons to the end user to pick a cake type. i am able to show the options using the below custom response:
{
"facebook": {
"attachment": {
"type": "template",
"payload": {
"template_type": "button",
"text": "What kind of cake would you like?",
"buttons": [
{
"type": "postback",
"payload": "witheggs",
"title": "Contain Eggs"
},
{
"type": "postback",
"payload": "noeggs",
"title": "Eggless"
}
]
}
}
}
}
once user tap one of the two buttons then how do i set it to some variable in dialog flow and then ask next set of question?

I don't know what language you're using but here's what you're looking for:
The payload part is returned by api.ai as resolvedQuery when the user clicks any button.
For example, if the user clicks on Contain Eggs, api.ai will return witheggs through the resolvedQuery node of the json.
Does that help? Feel free to ask if there's anything else.

Related

message template are not working in kore.ai

I want to display list to the user with kore.ai, currently, I am using telegram but the template is not working it is just showing the code.
var message={
"type": "template",
"payload":
{
"template_type": "button",
"text": "What do you want to do next?",
"buttons":
[{
"type": "web_url",
"title": "Show Website",
"url": "https://petersapparel.parseapp.com"
},
{
"type": "postback",
"title": "Start Chatting",
"payload": "USER_DEFINED_PAYLOAD"
}
]
}
}
print(JSON.stringify(message));
Expected result:
Some templates are channel specific which means not every end channel supports each and every templates . Please try with different channels such as Web or Facebook messenger, your template will be supported.
You will need to make sure that the template structure is supported by the channel.
The channels usually have the template structures defined on their technical documentation.
Please select the appropriate channel on the bot builder and then use the template structure as they have defined.

Facebook Messenger button error: "Action Unsuccessful There was an error delivering your message..."

I've checked the other questions about this error and the only solutions offered are "subscribe to the messaging_postbacks at Messenger -> Settings -> Webhooks -> Edit events.
You can see here that I have done this since the original setup of my bot, and I have even re-subscribed to it since:
But I am still getting this error:
I am logging any request that comes into my webhook and there is no activity, even though clicking the button, shows the payload value in blue as if I typed and sent it as a message. Then the popup "Action Unsuccessful" shows, and my bot doesn't receive anything.
Here is the response to FB with the button attachment elements:
{
"recipient": {
"id": "xxxxxxxxxxx"
},
"message": {
"attachment": {
"type": "template",
"payload": {
"template_type": "list",
"top_element_style": "compact",
"elements": [{
"title": "transfer",
"subtitle": null,
"image_url": "http://xxxxxxx",
"buttons": [{
"type": "postback",
"title": "transfer",
"payload": "transfer"
}]
}, {
"title": "hourly",
"subtitle": null,
"image_url": "http://xxxxxxxx",
"buttons": [{
"type": "postback",
"title": "hourly",
"payload": "hourly"
}]
}]
}
}
}
}
The Page Access Token just needed to be updated in the webhook. Probably to apply the latest permissions that include messaging_postbacks.
Go back to developer app dashboard. Select Messenger >> Settings.
Scroll down to the "Token Generation" section:
Select your page from the dropdown, and copy the new access token for use in your webhook.
Found a lot of similar questions and no clear answers. So I hope this saves someone the days of headache it caused me.

Continue a conversation after Browsing carousel in DialogFlow/Actions

So I have been experimenting with different Response types for DialogFlow through Actions: Actions Responses and Webhook/Fulfillment.
And so far, I have been able to generate proper responses for types like List, Basic Card, Suggestion Chips successfully. What I need now is a list-based response that lets the user open a link in a browser when touched as well as "not" generate a chat bubble. "Browsing carousel" fits the criteria: Browsing Carousel.
I have successfully created and simulated the output with 2 sample items. The issue is when the user wants to continue the conversation. As per the Guidance section in the help above, the browsing carousel:
By default, the mic remains closed after a browse carousel is sent. If you want to continue the conversation afterwards, we strongly recommend adding suggestion chips below the carousel.
From this what I understood is that the user has to invoke the App again by saying "Ok Google, talk to [app]". This doesn't seem very user-friendly as the user expects to return back to the conversation she was having with the agent after she has looked through the links from the carousel. Please note, I have simulated the flow using the Google Actions Simulator on Console.Actions page.
As soon as I invoke the intent with the Browsing Carousel, it is shown to me with the sample Items. But when I enter/say the next command to continue the conversation, the agent simply returns with:
We're sorry, but something went wrong. Please try again.
And the REQUEST/REQUEST window as well as the ERRORS/DEBUG are empty. I have logged calls to the Webhook and there is no call received.
The question: Is there a way to give the user the ability to browse an informative link from a response "list" (not Basic Card) and return to the conversation without ending it.
Here is the response for Browsing Carousel from RESPONSE window in Actions > Simulator (note I've removed non-relevant parts):
{
"conversationToken": "[token info]",
"expectUserResponse": true,
"expectedInputs": [
{
"inputPrompt": {
"richInitialPrompt": {
"items": [
{
"simpleResponse": {
"textToSpeech": "You have the following 2 options:",
"displayText": "You have the following 2 options:"
}
},
{
"carouselBrowse": {
"items": [
{
"title": "Test 1",
"description": "Desc 2",
"image": {
"url": "[some url]"
},
"openUrlAction": {
"url": "[some url]"
}
},
{
"title": "Test 2",
"description": "Desc 2",
"image": {
"url": "[some url]"
},
"openUrlAction": {
"url": "[some url]"
}
}
]
}
}
],
"suggestions": [
{
"title": "Continue"
},
{
"title": "End"
}
]
}
}
}
],
"responseMetadata": {
"status": {
"message": "Success (200)"
},
"queryMatchInfo": {
"queryMatched": true
}
}
}
For all those who are using the Simulator to test the Browsing Carousel and seeing that it stops responding after the output, please use a device instead to test it. When you use a device to render the output and use the Carousel response, it doesn't kill the conversation but turns off the mic. This is the intended behavior. One can introduce Suggestion chips to assist the user to continue the conversation.
Updated: Also make sure each Webhook Intent call has a proper response with Simple Response. As long as the response has required textual and audio information correctly setup, the Simulator will not fail.

Sending a button response to fb messenger via api.ai

I have started playing with diaglofFlow a.k.a api.ai with fb messenger integration.
I defined an intent which current returns 3 responses. 2 text responses and 1 custom payload.
the 2 text responses comes just fine but the custom payload which is suppose to return a button is not.
the custom payload looks like
{
"recipient": {
"id": "1234"
},
"message": {
"attachment": {
"type": "template",
"payload": {
"template_type": "button",
"text": "What do you want to do next?",
"buttons": [
{
"type": "web_url",
"url": "https://www.messenger.com",
"title": "Visit Messenger"
}
]
}
}
}
}
Also, please note that the recipient id is something i am not sure how it should be provided. the fb documentation says it should be number of the recipient. I do not know how i am going to get that?
actually this works
{
"facebook": {
"attachment": {
"type": "template",
"payload": {
"template_type": "button",
"text": "What do you want to do next?",
"buttons": [
{
"type": "web_url",
"url": "https://www.messenger.com",
"title": "Visit Messenger"
}
]
}
}
}
}
recipient.id is the user's Page-scoped ID. You receive it in the sender.id prop of webhook events when the user initiates a conversation.
https://developers.facebook.com/docs/messenger-platform/introduction/integration-components#psid

Persistent menu not showing in Facebook Messenger chat bot

As I don't know why suggested, using Postman.
Per docs, have succesfully POSTed the configuration to facebook APIs:
which is not supposed to be anyways locale specific. Even I don't see here
Localization: Developers can now provide text in multiple languages (or entirely different menus) for each local your bot's users may come from.
Like my brother, I have tried almost everything so far
This looks like some crazy bug. Is there some work around to add a simplest persistent menu?
Wasted 2 hours on this issue. Until I realised you have to delete the conversation then refresh facebook with ignore cache (ctrl+shift+r in chrome) and then it will show.
The FB API document states that the API link to hit for applying persistent menu to the page specific bot is:
https://graph.facebook.com/v2.6/me/messenger_profile?access_token=<PAGE_ACCESS_TOKEN>
Notice the me after version number i.e v2.6 in this specific case. However, this did not worked for a lot of people
There is small change in the API link to hit:
graph.facebook.com/v2.6/Page ID/messenger_profile?access_token=PAGE ACCESS TOKEN
Notice that me is replaced with the fb Page Id.
And the sample payload can still be the same:
{
"get_started": {
"payload": "Get started"
},
"persistent_menu": [
{
"locale": "default",
"composer_input_disabled": false,
"call_to_actions": [
{
"title": "Stop notifications",
"type": "nested",
"call_to_actions": [
{
"title": "For 1 week",
"type": "postback",
"payload": "For_1_week"
},
{
"title": "For 1 month",
"type": "postback",
"payload": "For_1_month"
},
{
"title": "For 1 year",
"type": "postback",
"payload": "For_1_year"
}
]
},
{
"title": "fresh jobs",
"type": "postback",
"payload": "fresh jobs"
},
{
"title": "More",
"type": "nested",
"call_to_actions": [
{
"title": "like us",
"type": "web_url",
"url": "https://www.facebook.com/nordible/"
},
{
"title": "blog",
"type": "web_url",
"url": "http://xameeramir.github.io/"
}
]
}
]
}
]
}
Notice that it is mandatory to configure get_started button before setting up the persistent_menu.