Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

creating a link that will open facebook messenger and send a message

i'm creating a registration code for users to a facebook messenger bot i am writing. instead of asking them to open a chat with my bot, and type in the registration code, i would like to provide them a link that will open their facebook messenger on a chat window with my bot, and send the registration code automatically.

i saw a link that opens the chat window (https://m.facebook.com/messages/compose?ids=USER_ID) but can't get it to send a message too.

if you know how to do that, or have an alternative suggestion, i would appreciate the help.

like image 263
Adam Itshar Avatar asked Mar 08 '17 22:03

Adam Itshar


People also ask

Can you create a link for Messenger?

Messenger Links use a Page's username to create a short and memorable link (m.me/username) that, when clicked, opens a conversation with the business in Messenger. Messenger Codes work in the same way.

How do I share my Messenger link?

Open Messenger and tap your profile picture in the top left corner of the screen. Scroll down to find your username link. Tap your username link and then tap Share Link from the list of options that appears. Select how you want to share your username link (text, email, etc.)


2 Answers

Check out the new referral webhook-reference. It gives you a way to link users directly to your bot with support for passing arbitrary parameters via the link.

So a possible approach would be:

  1. Make sure your bot is subscribed to the messaging_referral event.
  2. Craft your bot's m.me link to include the registration code in the ref param e.g http://m.me/mybot?ref=REGISTRATION_CODE. if you're interested in security you might consider encrypting the code
  3. Send the link(s) to the user. When the user click's the link, they're directed to your bot on messenger and once they initiate a session with your bot, you'll receive a messaging_referral event at your webhook with a payload similar to

{
  "sender":{
    "id":"USER_ID"
  },
  "recipient":{
    "id":"PAGE_ID"
  },
  "timestamp":1458692752478,
  "referral": {
    "ref": "REGISTRATION_CODE",
    "source": "SHORTLINK",
    "type": "OPEN_THREAD",
  }
}
  1. You can then evaluate the ref value and send your desired feedback to the user.
like image 148
Oranagwa Osmond Oscar Avatar answered Nov 27 '22 19:11

Oranagwa Osmond Oscar


Every messenger app use it's own link. For facebook https://m.me/XXXXXXXX where XXXXXXXX - page name.

I always use https://msng.link/fb-messenger.html for generation FB link. Better to remember one website and genereate all messengers what you need.

like image 35
anstak Avatar answered Nov 27 '22 19:11

anstak