Skip to main content

Mattermost Client for Incoming Webhooks

A simple Python client for sending messages to Mattermost using incoming webhooks.

Installation

pip install mattermost-client-py

Usage

First, you need to create an incoming webhook in your Mattermost instance. You can find instructions on how to do that here.

Synchronous Client

The synchronous client is useful for simple applications that don't require asynchronous operations.

from mattermost_client import SyncMattermostClient

# Initialize the client with your Mattermost webhook URL
client = SyncMattermostClient("https://your-mattermost-instance.com/hooks/your_webhook_token")

# Send a simple message
response = client.send_message(text='Hello, Mattermost!')
print(response)

# Send a more complex message with attachments
attachments = [
    {
        "fallback": "Upgrade your client to see this attachment.",
        "color": "#FF8000",
        "pretext": "This is optional pretext that shows above the attachment.",
        "author_name": "Mattermost",
        "author_link": "https://mattermost.com/",
        "author_icon": "http://www.mattermost.org/wp-content/uploads/2016/04/icon.png",
        "title": "Example Attachment",
        "title_link": "https://docs.mattermost.com/developer/message-attachments.html",
        "text": "This is the text of the attachment. It can be formatted with Markdown.",
        "fields": [
            {
                "short": False,
                "title": "Long Field",
                "value": "This is a long field, so it is not short."
            },
            {
                "short": True,
                "title": "Short Field",
                "value": "This is a short field."
            }
        ],
        "image_url": "http://www.mattermost.org/wp-content/uploads/2016/04/icon.png"
    }
]


response = client.send_message(
    text='A message with an attachment.',
    attachments=attachments,
    channel='town-square',
    username='My Bot',
    icon_url='https://www.mattermost.org/wp-content/uploads/2016/04/icon.png'
)
print(response)

Asynchronous Usage (with aiohttp)

The asynchronous client is ideal for applications using asyncio.

import asyncio
from mattermost_client import AsyncMattermostClient

async def main():
    # Initialize the client with your Mattermost webhook URL
    mm = AsyncMattermostClient("https://your-mattermost-instance.com/hooks/your_webhook_token")

    # Send a message asynchronously
    response = await mm.send_message("Hello, Mattermost! (async)")
    print(response)

if __name__ == "__main__":
    asyncio.run(main())

Bot Token & Direct Messaging (Personal Messages)

You can also send personal direct messages to individual users using a bot account token.

Synchronous Client

from mattermost_client import SyncMattermostClient

# Initialize with the Mattermost server base URL and your Bot personal access token
client = SyncMattermostClient(
    server_url="https://your-mattermost-instance.com",
    bot_token="your_bot_account_token"
)

# Send a personal message to a user by their username (with or without '@') or user ID
response = client.send_direct_message(recipient="john.doe", text="Hello from bot!")
print(response)

Asynchronous Client

import asyncio
from mattermost_client import AsyncMattermostClient

async def main():
    # Initialize with the Mattermost server base URL and your Bot personal access token
    client = AsyncMattermostClient(
        server_url="https://your-mattermost-instance.com",
        bot_token="your_bot_account_token"
    )

    # Send a personal message asynchronously
    response = await client.send_direct_message(recipient="john.doe", text="Hello from bot! (async)")
    print(response)

if __name__ == "__main__":
    asyncio.run(main())

Contributing

Contributions are welcome! Please open an issue or submit a pull request on GitHub.

License

This project is licensed under the MIT License.

Metadata

Release files for mattermost-client-py 0.1.3

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for mattermost-client-py 0.1.3
File Size Uploaded
mattermost_client_py-0.1.3.tar.gz 7.6 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for mattermost-client-py 0.1.3
File Interpreter ABI Platform
mattermost_client_py-0.1.3-py3-none-any.whl Python 3 none any Details

Total release size: 14.8 kB

Release files / mattermost_client_py-0.1.3.tar.gz

Download URL mattermost_client_py-0.1.3.tar.gz
Size 7.6 kB
Tags Source
SHA-256 checksum
How to use checksums
ba19504c6701d9ce48be57e0a0441db45d0694af281950a40caf9a36d73a2342
BLAKE2b-256 checksum
How to use checksums
af1fe828ef2bcc95a516bdb20e0eae0ed2800799214daa7bccc5218510d364d1
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.12.3

Release files / mattermost_client_py-0.1.3-py3-none-any.whl

Download URL mattermost_client_py-0.1.3-py3-none-any.whl
Size 7.1 kB
Tags Python 3
SHA-256 checksum
How to use checksums
64a235a7c8f3a6868bebdb2ac745e0cb993e59a1b255e595fe9e562858d8a03d
BLAKE2b-256 checksum
How to use checksums
21e29b4f0a16f913aba641a75e007aac4a3e7778c99485124c7fe595ba8cbe10
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.12.3

Release history Release notifications | RSS feed

This release

0.1.3 This release

2 release files

0.1.2

2 release files

0.1.1

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page