facebook messenger send message api without the user initiating the chat - facebook

I have a facebook page, and a website too. I need to add a button to my website, like "SEND THIS ARTICLE ON MESSENGER". When the user clicks on it, I need to send the article data to the user on messenger.
How can I achieve that?

To achieve your goal, You must have to use SEND TO MESSENGER Button.
Ref.: https://developers.facebook.com/docs/messenger-platform/discovery/send-to-messenger-plugin/
Full process to implement:
1. Need to integrate Facebook Div in your site
2. Add Facebook script
3. Once Any User press the button than You got the webhook event from the facebook which contatin the PSID.
4. Through this PSID You can sent the messege to that id.
If you are sending message using curl than following is the code
curl -X POST -H "Content-Type: application/json" -d '{
"recipient": {
"id": "<PSID>"
},
"message": {
"text": "hello, world!"
}
}' "https://graph.facebook.com/v2.6/me/messages?access_token=<FB_PAGE_TOKEN>";

Related

Facebook Messenger open callback

Is there any way to get callback When users open messenger ?
Currently I am developing Facebook chat bot, for existing user on Facebook page
I want to show get started button, that's why i need some callback when user open
messenger
You don't need a callback to have Get Started button. All you need for this is to register the button with your app.
To do so, you send a curl as following:
curl -X POST -H "Content-Type: application/json" -d '{ \
"get_started":{ \
"payload":"<GET_STARTED_PAYLOAD>" \
} \
}' "https://graph.facebook.com/v2.8/me/messenger_profile?access_token=<PAGE_ACCESS_TOKEN>"
You may change GET_STARTED_PAYLOAD to any text you like - that is what Facebook is going to send to your webhook if the user clicks GET STARTED.
More information here and here.

How to add 'Get Started' button in facebook messenger chat bot?

I tried using this
curl -X POST -H "Content-Type: application/json" -d '{ "get_started": {"payload": "qr"} }' "https://graph.facebook.com/v2.6/me/messenger_profile?access_token=myPageAccessToken"
In response I also got { "result": "success" }
But the bot does not show any button.
First, make sure that your account facebook who try to use your bot since only admins/developers/testers of the app can see it when the app is in development.
Second, if you use Android, you need to clear the Messenger data/cache under Android Settings -> Apps, this will also clear your login and you need to login again.
For further information, you could check this out:
https://stackoverflow.com/a/42662751/6874563
It was working fine, All I had to do was, deleting the existing conversion.
In my case, get started button only appears, when there's no message exists in past.

Facebook messenger bot Persistent Menu button

I need to have a Facebook Messenger Bot persistent menu item "Send Message" which should not trigger a postback. Instead place the cursor on the messenger textbox. Is there a way to create the menu item without having the menu item type as "postback" or "web_url"
"Send a Message" menu item appears automatically on mobile device when a persistent menu is created. Its not needed on web.
Check the code from https://developers.facebook.com/docs/messenger-platform/messenger-profile/persistent-menu
curl -X POST -H "Content-Type: application/json" -d '{
"persistent_menu":[
{
"locale":"default",
"composer_input_disabled":true,
"call_to_actions":[
{...
Change composer_input_disabled to false.

Facebook Messenger Platform welcome screen not showing

My bot is working and able to reply to messages, but now I'm trying to add functionality for responding to a postback from the "Get Sarted" button.
I can't get the "Get Started" button to show up, though.
This previous answer suggests deleting the conversation on desktop and opening a new one, but this doesn't work: it just creates an empty conversation, without the welcome message or "Get Started" button. The documentation linked in that answer is also no longer available.
So how do I get this view to show up, so I can create and test my response to a user clicking the "Get Started" button?
You need to set up the "Get Started" button before it shows up:
curl -X POST -H "Content-Type: application/json" -d '{
"setting_type":"call_to_actions",
"thread_state":"new_thread",
"call_to_actions":[
{
"payload":"USER_DEFINED_PAYLOAD"
}
]
}' "https://graph.facebook.com/v2.6/me/thread_settings?access_token=PAGE_ACCESS_TOKEN"

Facebook and Parse: Code 251, Error: Parse::InvalidSessionError

I'm trying to set up a chrome extension that uses a Facebook Access token to login to Parse using the JS api. As a proof of concept I tried following the example here with curl, but when I put in my access_token and expiration_date, the POST call returns {"code":251,"error":"Parse::InvalidSessionError"}
Specifically, I'm calling this from the OSX shell.
curl -X POST
-H "X-Parse-Application-Id: [my app id]" \
-H "X-Parse-REST-API-Key: [my rest api key]" \
-H "X-Parse-Revocable-Session: 1" \
-H "Content-Type: application/json" \
-d '{
"authData": {
"facebook": {
"id": "[my id as a string]",
"access_token": "[my token as a string]",
"expiration_date": "2015-10-26T07:45:16.579Z"
}
}
}' \
https://api.parse.com/1/users
I've googled around a bit, including reading the following posts, but after changing my settings on my Facebook app multiple times and re-authenticating, it is still throwing the same error.
Using FB user to login on parse. Error code: 251, Invalid Sesion Error
Parse Facebook login fails with error code 251
For the record, I've tried changing my "App Secret embedded in the client" Facebook setting to false, as well as my "Native or desktop app?" to both yes and no (I'm fairly sure it should be set to yes, as I'm using the desktop app FB login flow.) I've also added my facebook app to my parse app, and enabled Facebook integration on parse, as well as double checking my parse app and rest api keys.
Please let me know what else I should try, or what other information you need to assess this.
Two things were wrong with the way I was approaching this.
I was creating the "Expires_at" field by adding the "Expires_in" field (returned using this FB login flow) to the current time as calculated by my browser. In retrospect this was silly, as the expiration time is supposed to be exact, and network latency will change the calculated time by a bit.
I was using the wrong facebook ID for my request - there are two types of IDs now, and you need to use the correct one. See this link..