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

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.

Related

The custom payload for the facebook messenger integration only shows up the first time it's called and not thereafter

I built a winebot that can suggest food pairings or make recommendations.
The integration with FB Messenger works fine, and it's supposed to call a carousel after a search to show you the various options. I found that when I call on it multiple times it will only display the carousel the first time and not a new one each time.
This is the function that calls the carousel
// CREATE RICH MESSAGES FOR FACEBOOK
function create_carousel(agent, carousel_params) {
agent.context.set({
name: 'carousel_output',
lifespan: 2,
parameters: carousel_params,
});
agent.setFollowupEvent('createCarousel');
agent.add(''); //add a dummy payload
return;
}
IntentMap is set up like this:
// Run the proper function handler based on the matched Dialogflow intent name
let intentMap = new Map();
intentMap.set('createCarousel', create_carousel);
agent.handleRequest(intentMap);
The createCarousel intent is set up with an event createCarousel and an output context called carousel_output
Under the messenger tab it has a text message followed by a payload. The text message and payload both use the content of carousel_output to make a recommendation.
{
"facebook": {
"attachment": {
"type": "template",
"payload": {
"elements": [
{
"image_url": "#carousel_output.product1.image",
"default_action": {
"url": "https://google.com",
"webview_height_ratio": "tall",
"type": "web_url"
},
"subtitle": "#carousel_output.product1.subtitle",
"title": "#carousel_output.product1.title",
"buttons": [
{
"url": "https://www.winemag.com/buying-guide/brovia-2013-garblet-sue-barolo/",
"title": "#carousel_output.product1.price",
"type": "web_url"
},
{
"title": "Some Text",
"payload": "Some Text",
"type": "postback"
}
]
},
{
"image_url": "#carousel_output.product2.image",
"subtitle": "#carousel_output.product2.subtitle",
"default_action": {
"type": "web_url",
"webview_height_ratio": "tall",
"url": "https://google.com"
},
"title": "#carousel_output.product2.title",
"buttons": [
{
"type": "web_url",
"url": "https://www.wine-searcher.com/find/limerick+lane+cellars+rocky+knoll+zinfandel+russian+river+valley+sonoma+county+north+coast/2013",
"title": "#carousel_output.product2.price"
},
{
"title": "Some Text",
"payload": "Some Text",
"type": "postback"
}
]
},
{
"default_action": {
"webview_height_ratio": "tall",
"type": "web_url",
"url": "https://google.com"
},
"image_url": "#carousel_output.product3.image",
"buttons": [
{
"title": "#carousel_output.product3.price",
"type": "web_url",
"url": "https://www.wine-searcher.com/find/charles+smith+k+vintner+the+hidden+sra+wahluke+slope+washington+usa/2009"
},
{
"title": "Some Text",
"type": "postback",
"payload": "Some Text"
}
],
"title": "#carousel_output.product3.title",
"subtitle": "#carousel_output.product3.subtitle"
}
],
"template_type": "generic"
}
}
}
}
What I noticed is that when I call the intent a second or third time , the message appears but the payload does not.
I 've already tried clearing output_context and deleting it but this does not seem to affect anything. I looked through the documentation of how payloads work but nothing specifically referencing the issue.
I was wondering if this may be a limitation on facebook messenger but don't see anything in the logs that is a flag. The function runs and the context is updated each time with the right content but just doesn't display in the bot.
The logs didn't show any errors, but the problem appeared in the data provided to the payload.
The code that creates the payload pulls images 3 at a time from a list of urls. There were only 5 urls provided in the list so on the second run it killed the carousel and did not show an undefined error message or a missing data error. Works fine after adding more urls to the list.

I got the error (#10) "This message is sent outside of allowed window" when sent the message with button to open the webview in Facebook messenger

I try to send one message with button to open webview in Facebook messenger, but I got the error message:
"(#10) This message is sent outside of allowed window." ("code": 10, "error_subcode": 2018278")
My payload:
{
"recipient": {
"id": "283867206xxxxxxxxxxx"
},
"message": {
"attachment": {
"type": "template",
"payload": {
"template_type": "button",
"text": "Try the URL button!",
"buttons": [
{
"type": "web_url",
"url": "https://xxxxxxxxxx.firebaseapp.com/",
"title": "URL Button",
"webview_height_ratio": "compact"
}
]
}
}
}
}
I used the endpoint: https://graph.facebook.com/v6.0/me/messages?access_token=xxxxxxxxxxxxxxxxxx
I've been adding the https://xxxxxxxxxx.firebaseapp.com/ into the white list in the "Share Redirect Whitelist" of application setting and try with three different of the access_token of the fanpage.
Thanks for the help.
According to Facebook policy you are not allowed to respond on messages after 24 hours since the latest user's message.

storing values from fb messenger bot into dialog flow

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.

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.