【问题标题】:Can't respond to messages in message request in fbchat无法在 fbchat 中回复消息请求中的消息
【发布时间】:2020-09-26 10:38:28
【问题描述】:

我正在尝试制作一个机器人,以便当有人向它发送消息时,机器人会发回一个笑话,但我注意到这仅适用于我的朋友列表中的人,但如果随机人发送给机器人,那么他们的消息卡在 messenger 上的消息请求中,甚至 fbchat 库都识别到了这一点,并在控制台中告诉我有一条新的待处理消息,那么有没有办法回应这些消息?

这是我的代码:

from fbchat import Client,ThreadLocation

class JokesBot(Client):
    def onMessage(self, author_id, message_object, thread_id, thread_type, **kwargs):
        self.moveThread(ThreadLocation.PENDING,thread_id,thread_type)
        self.markAsDelivered(thread_id, message_object.uid)
        self.markAsRead(thread_id)

        # If you're not the author, echo
        if author_id != self.uid:
            self.send(Message(text='wiso tefl hehe'), thread_id=thread_id, thread_type=thread_type)



client = JokesBot('email', 'password')

client.listen()

请记住,我仍然没有实现这些笑话,所以代码中缺少它

提前致谢

【问题讨论】:

    标签: python python-3.x bots facebook-messenger facebook-messenger-bot


    【解决方案1】:

    onMessage 事件仅在已连接的 Facebook 好友向您发送消息时调用。

    对于未连接的 facebook 用户(不是朋友),您应该使用另一个事件 onPendingMessage 但与待处理消息中的 onMessage' 不同,事情变得越来越复杂: 看看fbchatdocumentation

    在事件调用之后,你应该调用方法:“fetchThreadList”,以便查看传入的消息

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2020-09-17
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-06-20
      • 1970-01-01
      • 1970-01-01
      • 2020-10-11
      相关资源
      最近更新 更多