diff options
author | Aljoscha Rittner <[email protected]> | 2022-06-24 17:58:13 +0200 |
---|---|---|
committer | Aljoscha Rittner <[email protected]> | 2022-06-24 17:58:13 +0200 |
commit | b225524d7c8f7726a1bb441e6cd605fccb94e912 (patch) | |
tree | 5f7c2a66e063b80e77b7be1fe2c24be986e70e1d | |
parent | af59a460687864341b544159a714e4de3891ff08 (diff) | |
download | mastodon.py-b225524d7c8f7726a1bb441e6cd605fccb94e912.tar.gz |
Documentation for processing unknown events in streaming.
Fixes #234
-rw-r--r-- | docs/index.rst | 14 |
1 files changed, 14 insertions, 0 deletions
diff --git a/docs/index.rst b/docs/index.rst index 473777a..e7b1ed9 100644 --- a/docs/index.rst +++ b/docs/index.rst | |||
@@ -1275,6 +1275,19 @@ The streaming functions take instances of `StreamListener` as the `listener` par | |||
1275 | A `CallbackStreamListener` class that allows you to specify function callbacks | 1275 | A `CallbackStreamListener` class that allows you to specify function callbacks |
1276 | directly is included for convenience. | 1276 | directly is included for convenience. |
1277 | 1277 | ||
1278 | For new well-known events implement the streaming function in `StreamListener` or `CallbackStreamListener`. | ||
1279 | The function name is `on_` + the event name. If the event-name contains dots, use an underscore instead. | ||
1280 | |||
1281 | E.g. for `'status.update'` the listener function should be named as `on_status_update`. | ||
1282 | |||
1283 | It may be that future Mastodon versions will come with completely new (unknown) event names. In this | ||
1284 | case a (deprecated) Mastodon.py would throw an error. If you want to avoid this in general, you can | ||
1285 | override the listener function `on_unknown_event`. This has an additional parameter `name` which informs | ||
1286 | about the name of the event. `unknown_event` contains the content of the event. | ||
1287 | |||
1288 | Alternatively, a callback function can be passed in the `unknown_event_handler` parameter in the | ||
1289 | `CallbackStreamListener` constructor. | ||
1290 | |||
1278 | When in not-async mode or async mode without async_reconnect, the stream functions may raise | 1291 | When in not-async mode or async mode without async_reconnect, the stream functions may raise |
1279 | various exceptions: `MastodonMalformedEventError` if a received event cannot be parsed and | 1292 | various exceptions: `MastodonMalformedEventError` if a received event cannot be parsed and |
1280 | `MastodonNetworkError` if any connection problems occur. | 1293 | `MastodonNetworkError` if any connection problems occur. |
@@ -1294,6 +1307,7 @@ StreamListener | |||
1294 | .. automethod:: StreamListener.on_notification | 1307 | .. automethod:: StreamListener.on_notification |
1295 | .. automethod:: StreamListener.on_delete | 1308 | .. automethod:: StreamListener.on_delete |
1296 | .. automethod:: StreamListener.on_conversation | 1309 | .. automethod:: StreamListener.on_conversation |
1310 | .. automethod:: StreamListener.on_unknown_event | ||
1297 | .. automethod:: StreamListener.on_abort | 1311 | .. automethod:: StreamListener.on_abort |
1298 | .. automethod:: StreamListener.handle_heartbeat | 1312 | .. automethod:: StreamListener.handle_heartbeat |
1299 | 1313 | ||