Messenger Codes

Messenger Codes can be scanned to instantly link the user to your bot, no typing needed. They're great for sticking on fliers, ads, or anywhere in the real world where you want people to try your bot.

You can get a Messenger Code for your Page using the page admin tool, in the Pages Manager app, and using the Messenger Code API.

Contents

Generating a static code

Getting the static Messenger Code is useful if you're running a tool that manages messaging on behalf of many different pages. In such a situation, you might want to request a code on behalf of your client and display it in a prominent place in the UI your customers see.

For a complete list of request properties, see the Messenger Code API reference.

curl -X POST -H "Content-Type: application/json" -d '{
  "type": "standard",
  "image_size": 1000
}' "https://graph.facebook.com/v2.6/me/messenger_codes?access_token=<ACCESS_TOKEN>" 

Generating a parametric code

Developers can also arbitrarily generate codes to pass different ref parameters to the same bot. You might use this to track which codes are getting scanned the most. A bot could even activate different functionality based on which code was scanned. For instance, a restaurant could put a different code on a each table to pass along to the bot where food should be delivered.

You can watch for users scanning parametric codes in the postback and referral webhook events.

For a complete list of request properties, see the Messenger Code API reference.

curl -X POST -H "Content-Type: application/json" -d '{
  "type": "standard",
  "data": {
    "ref":"billboard-ad"
  },
  "image_size": 1000
}' "https://graph.facebook.com/v2.6/me/messenger_codes?access_token=<ACCESS_TOKEN>"

API Response

The Messenger Code API will respond with a URI you can download your Messenger Code at.

This is not a permanent URI; you should download and cache the image as soon as possible.

{ 
  "uri": "<YOUR_CODE_URL_HERE>"
}

Scanning Messenger Codes

To scan a Messenger Code, do the following:

  1. Activate the Messenger camera.
  2. Press and hold in the viewfinder. A circle will appear.
  3. Center the Messenger Code in the circle. Messenger will automatically scan the code.

Responding to Scans

After generating a parametric code, you should watch for the ref parameter in two places:

  • If the user is entering the bot for the first time, the postback webhook will be called.

  • If the user is re-entering the bot by scanning the code, the referral webhook will be called.