Skip to main content

Mattermost async bot

Project description

Aiomatter Bot

Aiomatter is a Python library for creating a bot that interacts with Mattermost via its API and WebSocket. This README provides instructions on setting up the bot and an example of a greeting plugin.

Table of Contents

Installation

To install Aiomatter, use pip:

pip install aiomatter

Configuration

To configure the bot, you need to create a settings object with the following parameters:

  • bot_token: Your Mattermost bot token.
  • base_url: The base URL of your Mattermost server.
  • api_path: The API path (default is /api/v4).

Example:

from aiomatter.settings import Settings

settings = Settings(
    bot_token='your_bot_token',
    base_url='https://chat.yourserver.com',
    api_path='/api/v4'
)

Running the Bot

To run the bot, create an instance of the Bot class and call the run method:

from aiomatter.bot import Bot
from aiomatter.settings import Settings
from plugins import MyPlugin  # Your plugin

def get_bot() -> Bot:
    settings = Settings(
        bot_token='your_bot_token',
        base_url='https://chat.yourserver.com',
        api_path='/api/v4'
    )
    
    plugins = [MyPlugin()]

    return Bot(settings=settings, plugins=plugins)

if __name__ == '__main__':
    bot = get_bot()
    bot.run()

Example Greeting Plugin

The following example demonstrates a simple greeting plugin that responds to the POSTED event.

from aiomatter.plugin import Plugin
from aiomatter.wrappers import listen
from aiomatter.events import EventType
from aiomatter.schemas.events import PostEvent

class MyPlugin(Plugin):

    @listen(EventType.POSTED)
    async def hello(self, event: PostEvent):
        channel_id = event.data.post.channel_id  # Access channel_id from the typed event
        if channel_id:
            await self.driver.send_message(
                channel_id=channel_id,
                message='Hello!'
            )
            self.logger.info(f"Message sent to channel {channel_id}.")

Note on Typing

In the plugin methods, the decorator processes the event and returns a typed event instead of a generic event. This enhances type safety and improves code readability.

License

This project is licensed under the MIT License.

Author

Vladimir Savelev - GitHub Profile Polina Grunina - GitHub Profile

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

aiomatter-0.1.7.tar.gz (9.8 kB view details)

Uploaded Source

Built Distribution

aiomatter-0.1.7-py3-none-any.whl (11.1 kB view details)

Uploaded Python 3

File details

Details for the file aiomatter-0.1.7.tar.gz.

File metadata

  • Download URL: aiomatter-0.1.7.tar.gz
  • Upload date:
  • Size: 9.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.1 CPython/3.9.16

File hashes

Hashes for aiomatter-0.1.7.tar.gz
Algorithm Hash digest
SHA256 275f8e249d0bf17602f8d176fd520bbb9e82326ac62a46aaf8b53b7a4561e0ed
MD5 b866c507ec862b0f1bc297f3cc9ddc43
BLAKE2b-256 4b6696d26b3d09b7d69c95e89562c31cd41ff2a4c5d40d65f638648c29c13d67

See more details on using hashes here.

File details

Details for the file aiomatter-0.1.7-py3-none-any.whl.

File metadata

  • Download URL: aiomatter-0.1.7-py3-none-any.whl
  • Upload date:
  • Size: 11.1 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.1 CPython/3.9.16

File hashes

Hashes for aiomatter-0.1.7-py3-none-any.whl
Algorithm Hash digest
SHA256 26a9fa300292f51afbf820bcd689364df91e2ec44478424429b85aca590a582a
MD5 929a461f48b3c0f0c71f5529304988e1
BLAKE2b-256 1a4aaece99d0d05e6c4dc0493200481b08d8869c1fcc52a9906b2ec53ecc59e8

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