Customer matching


Closed Beta
Access to the Customer Matching is currently available in limited release for select businesses.

Facebook allows you to connect your existing customers to your bot using their phone number.
Using this feature you can send a messenger request to the customers using their phone number which is mapped to their Facebook account. Once the customer accepts the messenger request your bot receives an event using which you can trigger the user onboarding messages.

FBM
- image courtesy Facebook documentation

This feature requires you to pay a $99 USD fee to the Facebook and also apply for pages_messaging_phone_number permission when submitting your bot for approval. For more details on getting access to this feature please go through this documentation from Facebook.

Sending the Messenger request to the customer


While using the Gupshup platform you can utilise this feature by using the API “api/bot/{botname}/msg” and sending a specific context to it. We also allow you to send an introductory message along with the messenger request. To access this API go to API tab –>Exapand “IP Messaging” then find the API.

Here is the curl to use this API -

curl -X POST --header 'Content-Type: application/x-www-form-urlencoded' --header 'Accept: application/json' --header 'apikey: <your API key>' -d 'context=%7B%22botname%22%3A+%22%3Cyour_bot_name%3E%22%2C%22channeltype%22%3A+%22fb%22%2C%22contextid%22%3A+%22%3Cphone_number_with_country_code%3E%22%2C%22contexttype%22%3A+%22phone%22%7D&message=<Into message>' 'https://api.gupshup.io/sm/api/bot/{Your bot name}/msg'

There are two parameters in this curl:

  1. context: which takes this specific JSON for the feature

    {"botname": "<your_bot_name>","channeltype": "fb","contextid": "<phone_number_with_country_code>","contexttype": "phone"}
    
  2. message: In this you can send the introductory message.

Once you send the message using this API, Facebook will attempt to match the phone number to a user and based on the success and failure you will recieve the response codes back form this API.
 

Expected response codes from this API:

  1. 200 : this means a valid number is sent and matched.
  2. 400: Check the message in the response
    1. The response body will have a “code” field with value “10” and message as `Requires phone matching access fee to be paid by this page unless the recipient user is an admin, developer, or tester of the app.`
    2. The response body will have a “code” field with value “100” and message as `No matching user found`.

NOTE: This will only work for the bots published on FB channel. If the bot is not yet FB approved then this feature will only work for admins/developers/testers of the Facebook app.

Handling the user acceptance


Once the user taps on “Accept”, It triggers the optin event. You will receive a botoptinevent in the EventHandler of the IDE Bot Builder code.
You can then choose to start the main flow of the bot.

Sample code:

function EventHandler(context, event) {
    if(event.messageobj.text == 'botoptinevent'){ 
        context.sendResponse("Welcome to my store. How can I help?"); 
        }
}