Realtime Client

class pyryver.ryver_ws.RyverWS(ryver: Ryver)

A live Ryver session using websockets.

You can construct this manually, although it is recommended to use Ryver.get_live_session().

@on_chat(func)

The on chat message coroutine decorator.

This coroutine will be started as a task when a new chat message arrives. It should take a single argument, the chat message data.

@on_chat_deleted(func)

The on chat message deleted coroutine decorator.

This coroutine will be started as a task when a chat message is deleted. It should take a single argument, the chat message data.

@on_chat_updated(func)

The on chat message updated coroutine decorator.

This coroutine will be started as a task when a chat message is updated. It should take a single argument, the chat message data.

@on_connection_loss(func)

The on connection loss coroutine decorator.

This coroutine will be started as a task when the connection is lost.

EVENT_REACTION_ADDED = '/api/reaction/added'
EVENT_REACTION_REMOVED = '/api/reaction/removed'
EVENT_ALL = ''
@on_event(event_type: str)

The on event coroutine decorator for a specific event or all unhandled events.

This coroutine will be started as a task when a new event arrives with the specified type. If the event_type is None or an empty string, it will be called for all events that are unhandled. It should take a single argument, the event data.

Parameters:event_type – The event type to listen to, one of the constants in this class starting with EVENT_ or RyverWS.EVENT_ALL to receieve all otherwise unhandled messages.
MSG_TYPE_ALL = ''
@on_msg_type(msg_type)

The on message type coroutine decorator for a specific message type or all unhandled messages.

This coroutine will be started as a task when a new message arrives with the specified type. If the msg_type is None or an empty string, it will be called for all messages that are unhandled. It should take a single argument, the message data.

Parameters:msg_type – The message type to listen to, one of the constants in this class starting with MSG_TYPE_ or RyverWS.MSG_TYPE_ALL to receieve all otherwise unhandled messages.
await send_chat(to_chat: pyryver.objects.Chat, msg: str)

Send a chat message to a chat.

Parameters:
  • to_chat – The chat to send the message to.
  • msg – The message contents.
async with typing(to_chat: pyryver.objects.Chat) → pyryver.ryver_ws.RyverWSTyping

Get a context manager that keeps sending a typing indicator to a chat.

Useful for wrapping long running operations, like:

async with session.typing(chat):
    print("do something silly")
    await asyncio.sleep(4)
    await session.send_chat(chat, "done") # or do it outside the with, doesn't matter
Parameters:to_chat – Where to send the typing status.
await send_typing(to_chat: pyryver.objects.Chat)

Send a typing indicator to a chat identified by JID.

The typing indicator automatically clears after a few seconds or when a message is sent.

Parameters:to_chat – Where to send the typing status.
PRESENCE_AVAILABLE = 'available'
PRESENCE_AWAY = 'away'
PRESENCE_DO_NOT_DISTURB = 'dnd'
PRESENCE_OFFLINE = 'unavailable'
await send_presence_change(presence: str)

Send a presence change message.

Parameters:presence – The new presence, a constant in this class starting with PRESENCE_

Note

If you use this class as an async with context manager, you don’t need to call these two methods, unless you want to break out of a RyverWS.run_forever().

await start()

Start the session.

await close()

Close the session.

Any future operation after closing will result in a ClosedError being raised.

await run_forever()

Run forever, or until the connection is closed.

class pyryver.ryver_ws.RyverWSTyping(rws: pyryver.ryver_ws.RyverWS, to: pyryver.objects.Chat)

A context manager returned by RyverWS to keep sending a typing indicator.

You should not create this class yourself, rather use RyverWS.start_typing() instead.

start()

Start sending the typing indicator.

await stop()

Stop sending the typing indicator.

Note that the typing indicator doesn’t clear immediately. It will clear by itself after about 3 seconds, or when a message is sent.

class pyryver.ryver_ws.ClosedError

Bases: Exception

An exception raised to indicate that the session has been closed.