Skip to main content

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

Metadata

Release files for teams-webhook 1.0.0

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

Source distribution (sdist)

Source distribution for teams-webhook 1.0.0
File Size Uploaded Provenance
teams_webhook-1.0.0.tar.gz 8.8 kB Without provenance Details

Built distribution (wheel)

Table of built distributions (wheels) for teams-webhook 1.0.0
File Interpreter ABI Platform
teams_webhook-1.0.0-py3-none-any.whl Python 3 none any Details

Total release size: 16.5 kB

Release files / teams_webhook-1.0.0.tar.gz

Download URL teams_webhook-1.0.0.tar.gz
Size 8.8 kB
Tags Source
SHA-256 checksum
How to use checksums
b9bf86cf49677ebc8546bbf8cccd7acf49db5682943de64a8587c2a836cabda4
BLAKE2b-256 checksum
How to use checksums
bf7b7a55d5250413b42578975d56446b1aeecb58660c15613b798eaf2786bc28
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.13.5

Release files / teams_webhook-1.0.0-py3-none-any.whl

Download URL teams_webhook-1.0.0-py3-none-any.whl
Size 7.7 kB
Tags Python 3
SHA-256 checksum
How to use checksums
3d7d58566c77b6f3a8684b10d424249e0e5cd3e5749b57c4f859492eb7b5de57
BLAKE2b-256 checksum
How to use checksums
ed8a73a086647cb412ce9b817d5c58b44d46ed556b8631222c233801c6be3dd1
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.13.5

Security for teams-webhook 1.0.0

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Release history Release notifications | RSS feed

This release

1.0.0 This release

2 release files No provenance

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