10

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.

Adam Itshar
  • 115
  • 1
  • 1
  • 7

2 Answers2

8

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.
  • Thanks! that's exactly what i wanted! – Adam Itshar Mar 20 '17 at 23:14
  • is it possiblel to send a prefilled message? so the user will open a message windows with some text prefilled by us? – Fo Nko Sep 15 '18 at 21:20
  • 1
    @FoNko, I'm not sure I understand what you mean by "prefilled message". If you mean sending a "text" message response to the user, then yes. If it means, say, setting some text in the user's chat input field then no, it's currently not possible. For use cases where you might need to have the user send a specific 'input' to the bot then you could consider using the [quick reply](https://developers.facebook.com/docs/messenger-platform/send-messages/quick-replies/) feature or any of the message templates that support postback. – Oranagwa Osmond Oscar Sep 17 '18 at 00:55
  • yup, i meant setting some text over a variable in my link so the user clicks that button which opens a chat windows with a text and user needs to hit enter so it's sent to us (site admins) – Fo Nko Oct 06 '18 at 19:31
3

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.

anstak
  • 89
  • 3