teams-webhook 1.0.0
A simple Python package to send messages to Microsoft Teams using webhooks
Requires Python: >=3.7
Keywords: microsoft, teams, webhook, notification, messaging

# 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

```bash
pip install teams-webhook
```

## Quick Start

### Using the Class

```python
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

```python
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

```python
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

```python
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:

```python
{
    "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