FB Messenger Bot 🤖 — How to Identify a User via Page- & App-Scoped User-ID’s

Update 2017–04–17: Facebook finally has an API for that 🎉
https://developers.facebook.com/docs/messenger-platform/connecting-accounts

In my last blog post I wrote about our first chatbot and the challenge to identify users.

We get a page-scoped user-id from Messenger, so we can’t match existing users with their app-scoped user-id, even though we are using the same FB App for Facebook Login and Messenger Bot Integration.

(..) Ids are page-scoped. These ids differ from those returned from Facebook Login apps which are app-scoped. You must use ids retrieved from a Messenger integration for this page in order to function properly. — Source: Facebook Docs

In my test I had the following user-ids:
page-scoped user-id: 1026377564065xxx (through Messenger Bot)
app-scoped user-id: 10205652825102xxx (through FB App, Facebook Login)
These user-ids are totally different — so we can’t check if the user already exists in our database. We need a user identification to save all votes and swells. At least one unique identifier.

There is a little trick to match the page-/app-scoped user-id based on the profile picture url. Let me explain it in a few steps:

Facebook offers an API to get the userprofile with the Messenger user-id (page-scoped) and the page access-token:

Let’s check the Graph API Explorer to get the userprofile with the app access-token from the user.

As you can see, the filename of the profile picture is identical: 13177091_10209330090191529_6260308789231765xx_n

Now we can match the Messenger user with the existing user (who signed up with facebook) in our database. If we dont find a matching user, we create a temporary user with the Messenger user-id and the profile picture filename. If this user signs up with Facebook, we can match the new user with the temporary user.

Attention: If a user changes his profile picture, the url will change too. So it’s impossible to match an old temporary user. 🙀

Hopefully Facebook will add a “matching api” for this case.

#swell yeah

Your’s Phil

👏👏Clap below to recommend this article to others👏👏

Chatbots Magazine

Chatbots, AI, NLP, Facebook Messenger, Slack, Telegram, and…

Medium is an open platform where 170 million readers come to find insightful and dynamic thinking. Here, expert and undiscovered voices alike dive into the heart of any topic and bring new ideas to the surface. Learn more

Follow the writers, publications, and topics that matter to you, and you’ll see them on your homepage and in your inbox. Explore

If you have a story to tell, knowledge to share, or a perspective to offer — welcome home. It’s easy and free to post your thinking on any topic. Write on Medium

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store