fbchat: onMessage stopped working.

Description of the problem

I have created a messenger chatbot, and suddenly all of it’s functions stopped working today since they are based on the ‘onMessage’ function.

Even the most basic setup containing “onMessage” doesn’t work:

Code to reproduce

from fbchat import Client
from fbchat.models import *
import pickle
import time

import logging
logging.basicConfig(level=logging.DEBUG)

with open('/home/pi/Documents/FBBotV4/data/pass.txt', 'rt') as pass_txt:
    passwd = pass_txt

class Client(Client):
    def onMessage(self, message_object, **kwargs):
        print(message_object)

client = Client('[...]', passwd)
client.listen()

However, this works and sends messages normally:

Working Code

from fbchat import Client
from fbchat.models import *
import pickle
import time

import logging
logging.basicConfig(level=logging.DEBUG)

with open('/home/pi/Documents/FBBotV4/data/pass.txt', 'rt') as pass_txt:
    passwd = pass_txt

client = Client('[...]', passwd)

client.send(Message(text='$> test'), thread_id='[...]', thread_type=ThreadType.GROUP)

Environment information

  • Python version: Python 3.7.3
  • fbchat version: 1.8.3

About this issue

  • Original URL
  • State: closed
  • Created 5 years ago
  • Reactions: 7
  • Comments: 25 (8 by maintainers)

Most upvoted comments

Somehow the program only stuck on the client.listen(); my girlfriend was so angry because i didn reply her for 10min! because my chatbot stopped working!

Don’t close the issue, because it’s still a problem in the fbchat origin.

The new protocol is MQTT 3.1.0 over websockets. I have a basic implementation for receiving events that way in my asyncio fork of fbchat: https://github.com/tulir/fbchat-asyncio/blob/master/fbchat/_client.py#L2748-L2895

Any updates on the issue?

I have quickly checked and I can confirm, all my bots stopped reacting too. I’ll try to take a closer look when I’m home, but I suspect some breaking change within FB (again)

I’ve released v1.9.0, which fixes this! 🎉🚀

You can install this using pip install -U fbchat.

It should be fairly stable, but I’ll need your help testing the last few odd corners, so feel absolutely free to open an issue if you find anything!

Thanks for your patience, and for taking the time to submit the issue! 🙏👍

Also, I’m new to this. I’ve made a very simple thing in the past, but how can I go about using the forked version? I see that i have to install it, but will that interfere with my fbchat install?

@syspic I had to uninstall fbchat and install fbchat-asyncio using

git clone https://github.com/tulir/fbchat-asyncio.git
cd fbchat-asyncio
pip install .

Try checking out the examples over at https://github.com/tulir/fbchat-asyncio/tree/master/examples

The three main differences you should worry about are:

  • The starting / log-in function
  • async def [...]s and awaits before function and class definitions and calls
  • snake_case instead of camelCase

Sorry if I didn’t explain it well, I’m new to this as well 😕

How difficult would it be to port the changes from fbchat-asyncio back to this implementation?

Sorry about the delay. As @tulir said, the protocol is MQTT 3.1.0 over websockets, and that means we’ll have to make some (possibly major?) modifications to our current setup.

This’ll take me time to fix, and my exams are coming up, so I won’t have that time the next few weeks. If anyone is keep on fixing this, please do, but otherwise, for now, the solution I’d recommend is using @tulir’s fork.

I’ve worked on this over the holidays, and my work is finally near finished, sorry for the long delay.

In a few days, I’ll release a new version!

this is already solve using this fork https://github.com/tulir/fbchat-asyncio by @tulir