Skip to main content

A Python client for Mattermost incoming webhooks.

Project description

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())

Contributing

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

License

This project is licensed under the MIT License.

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

mattermost_client_py-0.1.2.tar.gz (5.0 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

mattermost_client_py-0.1.2-py3-none-any.whl (5.1 kB view details)

Uploaded Python 3

File details

Details for the file mattermost_client_py-0.1.2.tar.gz.

File metadata

  • Download URL: mattermost_client_py-0.1.2.tar.gz
  • Upload date:
  • Size: 5.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.3

File hashes

Hashes for mattermost_client_py-0.1.2.tar.gz
Algorithm Hash digest
SHA256 b214163733336d8f5c509d259dc92503d0ed4bc7da43e3671992d57b36433711
MD5 2dfd07f24a55182e2716e763a1277e00
BLAKE2b-256 a0e186a1cffeb23e9b1c535b7de1902a8c40b614c7460e32cdf6546d0098d298

See more details on using hashes here.

File details

Details for the file mattermost_client_py-0.1.2-py3-none-any.whl.

File metadata

File hashes

Hashes for mattermost_client_py-0.1.2-py3-none-any.whl
Algorithm Hash digest
SHA256 ddfbcdf2019d5c6bc374a9594e49e74cfa9f2b18a6c67fa7874e2f13c60a68b4
MD5 79955480e200d9234a36579dc3f6520b
BLAKE2b-256 a3bfaa1e3f60e7e7d2d582e22643a5bbfdab77b8699f3654cbb9adccc267f087

See more details on using hashes here.

Supported by

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