Events¶
-
class
fbchat.Listener(*, session, chat_on, foreground, mqtt=NOTHING, sync_token=None, sequence_id=None, tmp_events=NOTHING)[source]¶ Listen to incoming Facebook events.
Initialize a connection to the Facebook MQTT service.
- Parameters
Example
>>> listener = fbchat.Listener(session, chat_on=True, foreground=True)
-
listen()[source]¶ Run the listening loop continually.
This is a blocking call, that will yield events as they arrive.
This will automatically reconnect on errors, except if the errors are one of
PleaseRefreshorNotLoggedIn.Example
Print events continually.
>>> for event in listener.listen(): ... print(event)
- Return type
Iterable[Event]
-
disconnect()[source]¶ Disconnect the MQTT listener.
Can be called while listening, which will stop the listening loop.
The
Listenerobject should not be used after this is called!Example
Stop the listener when receiving a message with the text “/stop”
>>> for event in listener.listen(): ... if isinstance(event, fbchat.MessageEvent): ... if event.message.text == "/stop": ... listener.disconnect() # Almost the same "break"
- Return type
None