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.1.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.1-py3-none-any.whl (5.1 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: mattermost_client_py-0.1.1.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.1.tar.gz
Algorithm Hash digest
SHA256 f34f6ab5958c981b3ff1ca75817dde60c1828c602a86af602e9a09faf36363a4
MD5 6034264f07e98f660730f0a6179d9a59
BLAKE2b-256 48e5517c7705e092db69f775a5b4588d10c1306e3ecbdb42ba1bbe8eecd81c18

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for mattermost_client_py-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 6e253f6e7f662993a4aa299518b5f8d6663a117449d079cd35d2cee022908ff1
MD5 ea215af8409d9599587c19642978e851
BLAKE2b-256 37f3df868cddbddea1d90a0007df07faa6f912ac07ba956d091a14c8de3a9c77

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