简体   繁体   中英

Facebook chatbot and authentication

I have an application where users can login using Facebook. I have the user's auth token which is valid for 30 days. I am using Passport. At the moment, I am requiring the absolute minimum amount of permissions (email-only) so that my auth app doesn't need to get verified.

Now... I need to write a chatbot that will occasionally write to users who are authenticated. So, the bot needs to initiate the conversation. It's actually notifications that the users are actively interested in.

Given that I know how to write the chatbot itself, I was wondering... is doing so even possible?

If it's NOT possible, is it possible to "link" however initiates a chat with my bot with one of the logged in users by comparing their Facebook user ID? (I am afraid not, since the Facebook user ID seems to be scoped to the app!)

1) In order to reliably send messages to the user, unprompted by user interaction, you will need Subscription Messaging permissions from FB, which is currently in a restrictive beta.

Subscription Messaging is limited to non-advertisment messages from apps in News, Personal Tracker, and Productivity categories. If your bot fits into one of these categories, you can potentially get the permissions to do what you want.

If it does not, you can still send notifications to users, but will need to elicit their response (button press, text response) each time to earn another message outside of the 24hr limit imposed on Standard Messaging. These messages can be promotional.

2) To get the page scoped id of a user when you have their user id for another app or page use the ID Matching API.

You must create a FB Business account (if you do not already have one) and associate your apps and pages with the business, follow the guide in the ID Matching API Docs .

To get all page scoped id's for pages owned by your Business account, when you have a user's app id (from FB login, as an example) you will make the following request to the Graph API:

GET /{user-id}/ids_for_pages
    ?access_token=[app_access_token]
    &appsecret_proof=[appsecret_proof]

You will receive a response that looks something like this, containing the page scoped id of the specified user for each page your business account owns:

"data": [
      {
        "id": "12345123", // The psid for the user for that page
        "page": {
          "category": "Musician",
          "link": "https://www.facebook.com/Johns-Next-Great-Thing-380374449010653/",
          "name": "John's Next Great Thing",
          "id": "380374449010653"
        }
      }
    ]

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM