added example echobot to readme

This commit is contained in:
thekindlyone
2016-08-29 09:39:18 +05:30
parent e44356f265
commit 7ab0d3caf0

View File

@@ -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("<email>", "<password>")
bot.listen()
Authors
=======