Skip to main content

A simple Python package to send messages to Microsoft Teams using webhooks

Project description

Teams Webhook

A simple Python package to send messages to Microsoft Teams using webhooks.

Features

  • Easy-to-use interface for sending Teams messages
  • Support for rich message cards with titles, subtitles, and images
  • Customizable theme colors
  • Error handling and response validation
  • Both class-based and function-based APIs

Installation

pip install teams-webhook

Quick Start

Using the Class

from teams_webhook import TeamsWebhook

# Initialize with your webhook URL
webhook = TeamsWebhook("https://your-company.webhook.office.com/webhookb2/your-webhook-url")

# Send a message
result = webhook.send_message(
    message_title="🚨 Alert",
    activity_title="System Monitor",
    activity_subtitle="Health Check",
    text_message="This is a test message!"
)

print(f"Success: {result['success']}")

Using the Function

from teams_webhook import send_teams_message

# Send a message directly
result = send_teams_message(
    webhook_url="https://your-company.webhook.office.com/webhookb2/your-webhook-url",
    message_title="📊 Status Update",
    activity_title="Automation Bot",
    activity_subtitle="QA Automation",
    text_message="**Status:** All systems operational"
)

Parameters

Required Parameters

  • webhook_url (str): Your Microsoft Teams webhook URL
  • message_title (str): The main title of the message
  • activity_title (str): The activity title in the message card
  • activity_subtitle (str): The activity subtitle in the message card
  • text_message (str): The main text content of the message

Optional Parameters

  • theme_color (str): The theme color of the message card (default: "0076D7" - blue)
  • activity_image (str): URL of the activity image

Examples

Error Alert

from teams_webhook import TeamsWebhook

webhook = TeamsWebhook("your-webhook-url")

result = webhook.send_message(
    message_title="🚨 Critical Error",
    activity_title="Error Monitor",
    activity_subtitle="Service Alert",
    text_message="**Error Level:** CRITICAL<br>**Service:** webapp-service<br>**Error:** Database connection failed",
    theme_color="FF0000",  # Red for error
    activity_image="https://example.com/error-icon.png"
)

Status Update

from teams_webhook import send_teams_message

result = send_teams_message(
    webhook_url="your-webhook-url",
    message_title="📊 Status Update",
    activity_title="System Monitor",
    activity_subtitle="Health Check",
    text_message="**Status:** All systems operational<br>**Uptime:** 99.9%",
    theme_color="00FF00"  # Green for success
)

Response Format

The package returns a dictionary with the following structure:

{
    "success": True,  # Boolean indicating if the request was successful
    "status_code": 200,  # HTTP status code
    "message": "Message sent successfully to Microsoft Teams!",
    "response": "..."  # Raw response from Teams
}

Error Handling

The package handles various error scenarios:

  • Network connectivity issues
  • Invalid webhook URLs
  • Teams service unavailability
  • Malformed message payloads

All errors are caught and returned in the response dictionary with appropriate error messages.

Getting a Teams Webhook URL

  1. Go to your Microsoft Teams channel
  2. Click on the three dots (...) next to the channel name
  3. Select "Connectors"
  4. Find "Incoming Webhook" and click "Configure"
  5. Fill in the details and click "Create"
  6. Copy the webhook URL

Requirements

  • Python 3.7+
  • requests library

License

MIT License

Contributing

Contributions are welcome! Please feel free to submit a Pull Request.

Changelog

1.0.0

  • Initial release
  • Basic webhook functionality
  • Class and function-based APIs
  • Error handling and response validation

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

teams_webhook-1.0.0.tar.gz (8.8 kB view details)

Uploaded Source

Built Distribution

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

teams_webhook-1.0.0-py3-none-any.whl (7.7 kB view details)

Uploaded Python 3

File details

Details for the file teams_webhook-1.0.0.tar.gz.

File metadata

  • Download URL: teams_webhook-1.0.0.tar.gz
  • Upload date:
  • Size: 8.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.13.5

File hashes

Hashes for teams_webhook-1.0.0.tar.gz
Algorithm Hash digest
SHA256 b9bf86cf49677ebc8546bbf8cccd7acf49db5682943de64a8587c2a836cabda4
MD5 91b0aaf88d17822d6dc18368499e2d2c
BLAKE2b-256 bf7b7a55d5250413b42578975d56446b1aeecb58660c15613b798eaf2786bc28

See more details on using hashes here.

File details

Details for the file teams_webhook-1.0.0-py3-none-any.whl.

File metadata

  • Download URL: teams_webhook-1.0.0-py3-none-any.whl
  • Upload date:
  • Size: 7.7 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.13.5

File hashes

Hashes for teams_webhook-1.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 3d7d58566c77b6f3a8684b10d424249e0e5cd3e5749b57c4f859492eb7b5de57
MD5 307d44f77b39a52bb3536126cc333394
BLAKE2b-256 ed8a73a086647cb412ce9b817d5c58b44d46ed556b8631222c233801c6be3dd1

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