Facebook Bot: Message Mentioner - facebook

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?

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 Chatbot delete messages by id

does anybody know if it is possible to delete messages by id.
For example I have an update for my content so that the user must not see any outdated messages. Didn't find anything in the graph API...
Message docs
thx
franzus
Facebook does not allow you to delete messages using the Messenger API, or the Graph API
I am not aware or, nor have found documentation for, a method that does DELETE operations (or UPDATE for that matter) on a FB Message.
The Messenger Docs provide methods for sending messsages, subscribing a page to your application's webhook, retrieving user profile information, and setting various options for your bot.

Get fb page scoped user id for messenger app

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.

How to monitor new likes on Facebook page with WebHooks?

I have some questions regarding the Facebook WebHooks.
1)I would like to get notified every time a fb page gets a new like/post etc. I understand this is the feed field. I assume I have to be the facebook page admin for this?
2)What is the exact body of the update object that I will receive in this case? Will it contain information about the liker? Say his/hers email?

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.