From 7ab0d3caf0de319b73648025c553eb62b7dfd672 Mon Sep 17 00:00:00 2001 From: thekindlyone Date: Mon, 29 Aug 2016 09:39:18 +0530 Subject: [PATCH] added example echobot to readme --- README.rst | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/README.rst b/README.rst index 0fd10fc..f2d9e13 100644 --- a/README.rst +++ b/README.rst @@ -52,6 +52,33 @@ Getting last messages sent print(message.body) +Example Echobot +=============== + +.. code-block:: python + + import fbchat + #subclass fbchat.Client and override required methods + class EchoBot(fbchat.Client): + + def __init__(self,email, password, debug=True, user_agent=None): + fbchat.Client.__init__(self,email, password, debug, user_agent) + + def on_message(self, mid, author_id, author_name, message, metadata): + self.markAsDelivered(author_id, mid) #mark delivered + self.markAsRead(author_id) #mark read + + print("%s said: %s"%(author_id, message)) + + #if you are not the author, echo + if str(author_id) != str(self.uid): + self.send(author_id,message) + + bot=EchoBot("", "") + bot.listen() + + + Authors =======