This repository has been archived on 2025-07-31. You can view files and clone it, but cannot push or open issues or pull requests.
Files
fbchat/examples/echobot.py
Mads Marquart 942c3e5b70 Merge pull request #499 from carpedm20/session-in-models
Add ThreadABC helper, and move a bunch of methods out of Client
2020-01-09 11:33:45 +01:00

20 lines
568 B
Python

import fbchat
# Subclass fbchat.Client and override required methods
class EchoBot(fbchat.Client):
def on_message(self, author_id, message_object, thread, **kwargs):
self.mark_as_delivered(thread.id, message_object.id)
self.mark_as_read(thread.id)
print("{} from {} in {}".format(message_object, thread))
# If you're not the author, echo
if author_id != self.session.user_id:
thread.send(message_object)
session = fbchat.Session.login("<email>", "<password>")
echo_bot = EchoBot(session)
echo_bot.listen()