简体   繁体   English

Facebook聊天机器人和身份验证

[英]Facebook chatbot and authentication

I have an application where users can login using Facebook. 我有一个用户可以使用Facebook登录的应用程序。 I have the user's auth token which is valid for 30 days. 我拥有有效期30天的用户身份验证令牌。 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? 如果不可能,是否可以“链接”但通过比较他们的Facebook用户ID与其中一个登录用户发起与我的机器人的聊天? (I am afraid not, since the Facebook user ID seems to be scoped to the app!) (恐怕不会,因为Facebook用户ID似乎仅限于该应用!)

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. 1)为了可靠地向用户发送消息(不受用户交互提示),您将需要FB的“订阅消息传递”权限,该功能目前处于限制性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. 如果不是这样,您仍然可以向用户发送通知,但是每次需要获得他们的响应(按钮按下,文本响应),以获取超出标准消息传递24小时限制的另一条消息。 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. 2)当您拥有另一个应用程序或页面的用户ID时,要获取用户的页面范围ID,请使用ID匹配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 . 您必须创建一个FB Business帐户(如果您还没有帐户),并将您的应用程序和页面与该业务相关联,请按照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: 要获取您的企业帐户拥有的页面的所有页面范围的ID,当您拥有用户的应用ID(例如,通过FB登录)时,您将向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: 您将收到一个类似于以下内容的响应,其中包含您的企业帐户拥有的每个页面的指定用户的页面范围ID:

"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"
        }
      }
    ]

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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