Get fb page scoped user id for messenger app - facebook

I recently discovered a facebook marketing app that sends message (on messenger) after the user leaves a comment on a particular post from a page (as an autoresponder), given that the user does not interact with messenger application (For never and not logging using facebook at this app).
Using Webhook events, I can get the user ID that post the comment, but this ID is different from page scoped ID (PSID) used to send the message.
Does anyone have any idea or a trick to do this?

Let check if the id you get on the webhook is app-scoped id, you can you this method to get the page-scoped id: https://developers.facebook.com/docs/messenger-platform/identity/id-matching/

Use the Feed Webhook event to get comment_id,
Use comment_id to send message through private_replies.

Related

Can I transform a user-id to PSID? - Facebook API Graph

Context: I'm building a webhook with NodeJS to get events from Facebook Page with my Facebook App. These events are: feed, mention (when a user tags the page on his wall) and message. I can get all events without problem. In all events I need to identify the user who write. When the users write a post or message in the page I get an ID (PSID) but when the user write a post on his wall tagging the page I can't get PSID, this is obvious because he isn't in the page scope. The only I get from this event is user-id from post-id.
I have tried the following:
I used this endpoint GET: /<user-id>/ids_for_pages as indicated in the documentation. This doesn't work for me because I would need that the pages are in my business administrator and this isn't possible because I need this webhook to manage many pages to many companies.
I used this endpoint GET: /<psid>?fields=name,id for events of type feed and messages (from Messenger) into the page but this gives me only PSID again.
Note: In my DB I save long-lived token of my page, ASID of the site owner and Page ID when my user does the login in the UI.
My questions:
Is possible transform user-id to PSID?
Can I get user-id through the PSID?
If you have a better idea to unify IDs when is the same user, I would like to know it. If this isn't possible I would also like know it.
My Goal: Each user event goes to the same case for the same user in my API, for this reason if the user is the same when tags the page and/or write a message in the page the idea is to identify him like same user and not like new case.

Facebook Bot: Message Mentioner

I'm trying to build a bot that would message anyone who mentions (#PageName) it. I have set up the mention webhook for my bot so that whenever anyone mentions my page in a comment or post, I receive a notification. Unfortunately, Facebook doesn't make it easy to message the person who mentioned my page, since there are different page IDs and messenger IDs. I am able to fetch the user ID from the mention by fetching the from field from the graph API, but is it possible to convert this user ID to a messenger ID so that I may actually message the user?

Graph API Facebook : user id

I am working on a business application which is using facebook and I need to send a private message to a connected user friend.
For getting all the user friends, I am using me/taggable_friends. In this way I have all the user friends but I can't retrieve the real friend user id. I need to know this field for sending a private message (or request or notification).
Regarding the FB documentation, this feature is only available for the "games" product but it's look like strange.
Maybe i'm doing something wrong but I don't understand how should I proceed.
Thank's for your answers.
taggable_friends can (and should) only be used for tagging friends, you donĀ“t even get an ID with it, only a tagging token (see Facebook docs).
For sending private messages, the best (and only) way is to use the Send Dialog of the JavaScript SDK: https://developers.facebook.com/docs/sharing/reference/send-dialog
The user has to input the target friend and the message on his own, which is a requirement for the message anyway. It always has to be 100% user generated.
The Chat API is deprecated and should not be used anymore: https://developers.facebook.com/docs/chat
On iOS, if you want to send a private message to another Facebook user, you should use the Message Dialog: https://developers.facebook.com/docs/ios/share#message-dialog
This lets a user share a message with any of their FB friends, then return to your app. You can ensure the message contains a link which the recipients will be able to click on.

How can I reply to a private message on a fan page using the Facebook Graph API in a Facebook app?

How can I reply to a private message on a fan page using the Facebook Graph API in a Facebook app?
I am able to retrieve private Messages from a fan page
I am able to reply as a user using chat API (User to User only)
I have valid tokens
I have read_mailbox, read_page_mailboxes permissions, and the following permissions to the page too:
ADMINISTER,
EDIT_PROFILE,
CREATE_CONTENT,
MODERATE_CONTENT,
CREATE_ADS,
BASIC_ADMIN
I am doing it as described here.
Some claim to have gotten around this. How have they managed this?
The documentation you linked to answers this question quite clearly.
From the docs:
**How to Reply**
Note that a page can only reply to a user's message. It cannot initiate a private message with a user. Also, a page can respond not more than twice to a user's message before the user has replied back.
You can reply to a user's message by issuing an HTTP POST to /CONVERSATION_ID/messages with the following parameters. A conversation ID look like t_id.216477638451347.
Parameter Description Type Required
message The body of reply string Y

Facebook api feed : how post message in a single user wall?

I use facebook SDK javascript to post a message from a website to my wall on facebook.
When I post, I can choose the users who can read my message.
Can I change the script to send a message directly to one or any users automatically?
To send a private message through facebook API is not intended behavior. to prevent spam it is assumed. This can be overcome by sending an email to facebook_username#facebook.com and it will appear as an instant message to the user. This is NOT an intended solution however and it is EXPRESSLY discouraged in the facebook docs.