Skip to main content

asyncio-based Python wrapper for the Rocket.Chat Realtime API.

Project description

rocketchat-async

asyncio-based Python wrapper for the Rocket.Chat Realtime API.

When should you use this library?

Use this library if you:

  • want to integrate with Rocket.Chat from Python
  • are using asyncio to drive your code
  • want to use Rocket.Chat's efficient websockets-based Realtime API

Installation

pip install rocketchat-async

Example usage

import asyncio
from rocketchat_async import RocketChat


def handle_message(channel_id, sender_id, msg_id, thread_id, msg, qualifier):
    """Simply print the message that arrived."""
    print(msg)


async def main(address, username, password):
    rc = RocketChat()
    await rc.start(address, username, password)
    # A possible workflow consists of two steps:
    #
    # 1. Set up the desired callbacks...
    for channel_id, channel_type in await rc.get_channels():
        await rc.subscribe_to_channel_messages(channel_id, handle_message)
    # 2. ...and then simply wait for the registered events.
    await rc.run_forever()


# Side note: Don't forget to use the wss:// scheme when TLS is used.
asyncio.run(main('ws://localhost:3000/websocket', 'username', 'password'))

API Overview

Brief overview of the currently implemented methods.

As of now, Rocket.Chat's API is only covered partially (based on my original needs). I am open to both feature requests as well as pull requests.

Methods

RocketChat.get_channels()

Get a list of channels the logged-in user is currently member of.

RocketChat.send_message(text, channel_id, thread_id=None)

Send a text message to a channel.

RocketChat.send_reaction(orig_msg_id, emoji)

Send a reaction to a specific message.

RocketChat.send_typing_event(channel_id, is_typing)

Send the "typing" event to a channel.

RocketChat.subscribe_to_channel_messages(channel_id, callback)

Subscribe to all messages in the given channel. Returns the subscription ID.

The provided callback should accept six arguments: channel_id, sender_id, msg_id, thread_id, msg_text and msg_qualifier. The qualifier can help to determine if e.g. the message is a system message about the user being removed from the channel.

RocketChat.subscribe_to_channel_changes(callback)

Subscribe to all changes in channels. Returns the subscription ID.

The provided callback should accept two arguments: channel_id and channel_qualifier. The qualifier helps to determine e.g. if it's a direct message or a normal room.

RocketChat.unsubscribe(subscription_id)

Cancel a subscription.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

rocketchat_async-1.0.1.tar.gz (6.9 kB view details)

Uploaded Source

Built Distribution

rocketchat_async-1.0.1-py3-none-any.whl (7.9 kB view details)

Uploaded Python 3

File details

Details for the file rocketchat_async-1.0.1.tar.gz.

File metadata

  • Download URL: rocketchat_async-1.0.1.tar.gz
  • Upload date:
  • Size: 6.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.3.1 CPython/3.9.2 Linux/5.10.0-20-amd64

File hashes

Hashes for rocketchat_async-1.0.1.tar.gz
Algorithm Hash digest
SHA256 538cf7cd13e505015f248c49f5b2e0222ea57801720e4cb32c4670af7cf9176e
MD5 e1a1384236cf31dedc6389f0f6f9d97f
BLAKE2b-256 d51132a5197c2a9f7afd6ca03ce7ac879e8bbf657afb9fb01874f8a5fcf8b23e

See more details on using hashes here.

File details

Details for the file rocketchat_async-1.0.1-py3-none-any.whl.

File metadata

  • Download URL: rocketchat_async-1.0.1-py3-none-any.whl
  • Upload date:
  • Size: 7.9 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.3.1 CPython/3.9.2 Linux/5.10.0-20-amd64

File hashes

Hashes for rocketchat_async-1.0.1-py3-none-any.whl
Algorithm Hash digest
SHA256 45e17c291a66b5097949f56d1952ff8c1904a6909a39c063837d4bfb781d321d
MD5 ac8565497928a51fb1b0e240076b7d45
BLAKE2b-256 daf17e6bf902dc32ffeeefb29fa9a85a3de4326d2af907c826f50d72bf480c1c

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page