Prerequisites
Before deploying the Teams bot, ensure you have:- Rust 1.75+ installed via rustup
- Claude CLI configured (required for both Tier 1 and Tier 2 LLM operations)
- GitHub CLI (
gh) authenticated for creating PRs - Azure account for Bot Framework registration
- Git for cloning repositories
- Public endpoint for webhook (or ngrok for local testing)
Registering a Bot Framework Application
Create Azure Bot Registration
- Log in to the Azure Portal
- Search for Azure Bot and create a new resource
- Choose Bot Channels Registration (or Multi-tenant bot)
- Fill in:
- Bot handle: unique name (e.g.,
magpie-bot) - Subscription: your Azure subscription
- Resource group: create or select existing
- Pricing tier: F0 (free) for testing
- Bot handle: unique name (e.g.,
Get App Credentials
After creation:
- Navigate to Configuration in your bot resource
- Copy the Microsoft App ID (this is
TEAMS_APP_ID) - Click Manage next to the App ID to go to App Registrations
- In Certificates & secrets, create a New client secret
- Copy the secret Value immediately (this is
TEAMS_APP_SECRET)
Configure Messaging Endpoint
In the Azure Bot Configuration page:
- Set Messaging endpoint to your public webhook URL:
- For local testing with ngrok:
- Save the configuration
Add Microsoft Teams Channel
- In your Azure Bot, go to Channels
- Click on the Microsoft Teams icon
- Accept the terms and click Save
- The Teams channel is now enabled
Environment Configuration
The Teams bot requires several environment variables. Create a.env file or set them in your deployment environment:
Required Variables
Optional: HMAC Validation
HMAC validation is optional but recommended for production. If set, incoming webhooks must include a valid
Authorization: HMAC <signature> header.Pipeline Configuration
Optional: Plane Issue Tracking
Optional: Daytona Sandbox
Building and Running
Build the Teams Bot
Build the The compiled binary will be at
magpie-teams binary from the workspace root:target/release/magpie-teams.First build takes 4-5 minutes due to transitive dependencies (Goose, candle, tree-sitter, etc.).
Run the Webhook Server Locally
Set your environment variables and run:Or run the compiled binary directly:You should see:
Expose Local Server (for testing)
If testing locally, use ngrok to expose your webhook:Update your Azure Bot’s messaging endpoint to the ngrok HTTPS URL:
Test the Bot in Teams
In Microsoft Teams:
- Open a chat with your bot or mention it in a channel
- Send a message:
@Magpie add a health check endpoint - The bot will reply with “Working on it…”
- After the pipeline completes, you’ll receive a status message with:
- Pipeline status (Success/PartialSuccess/Failed)
- PR URL (if created)
- Plane issue ID (if configured)
- CI status
Production Deployment
Azure App Service
Deploy the Teams bot to Azure App Service for production:Running as a Systemd Service
For VM-based deployments, create a systemd service file at/etc/systemd/system/magpie-teams.service:
Docker Deployment
See the Docker Setup Guide for containerized deployment options.Reverse Proxy with NGINX
For production, place NGINX in front of the webhook server:Architecture
The Teams bot implements theChatPlatform trait from magpie-core:
- Webhook Server: Axum HTTP server listening on port 3978 (Bot Framework standard)
- HMAC Validation: Optional signature verification using
TEAMS_HMAC_SECRET - OAuth2 Authentication: Token caching with 5-minute expiry buffer
- Async Pipeline: Spawns pipeline in background, sends immediate acknowledgment
- Mention Stripping: Removes
<at>...</at>tags from Teams messages
Key Files
| File | Purpose |
|---|---|
crates/magpie-teams/src/main.rs:32 | Reads credentials and starts Axum server |
crates/magpie-teams/src/webhook.rs:75 | Webhook handler with HMAC validation |
crates/magpie-teams/src/auth.rs:50 | OAuth2 token manager with caching |
crates/magpie-teams/src/adapter.rs | ChatPlatform implementation for Teams |
crates/magpie-teams/src/reply.rs | Formats pipeline results for Teams |
Endpoints
| Endpoint | Method | Purpose |
|---|---|---|
/api/messages | POST | Bot Framework webhook (main entry point) |
/health | GET | Health check endpoint (returns “ok”) |
OAuth2 Flow
The bot uses client credentials OAuth2 flow:- On first message, requests token from
login.microsoftonline.com/botframework.com/oauth2/v2.0/token - Caches token with expiry (default: 3600s minus 300s buffer)
- Reuses cached token for subsequent API calls
- Automatically refreshes when expired
HMAC Signature Validation
WhenTEAMS_HMAC_SECRET is configured:
webhook.rs:46 before processing.
Troubleshooting
Bot doesn’t respond to messages
Check messaging endpoint
Check messaging endpoint
Verify your Azure Bot’s messaging endpoint is correct and publicly accessible:
Verify App credentials
Verify App credentials
Test OAuth2 token acquisition:
Check server logs
Check server logs
Run with verbose logging:
HMAC validation fails
Verify secret matches
Verify secret matches
Ensure
TEAMS_HMAC_SECRET matches the secret used to sign requests.Check signature format
Check signature format
Bot Framework sends:
Authorization: HMAC <base64_signature>The webhook strips the “HMAC ” prefix before validation.Disable HMAC for testing
Disable HMAC for testing
Remove
TEAMS_HMAC_SECRET from environment to skip validation during debugging.OAuth2 token errors
401 Unauthorized
401 Unauthorized
Token expired
Token expired
The auth manager automatically refreshes tokens. If you see this repeatedly, check system clock sync.
Pipeline fails immediately
Verify Claude CLI is configured
Verify Claude CLI is configured
Test the Claude CLI:
Check GitHub CLI authentication
Check GitHub CLI authentication
Verify repository access
Verify repository access
Ensure
MAGPIE_REPO_DIR points to a valid git repository with remote configured.Next Steps
Docker Setup
Containerize the Teams bot for easier deployment
Pipeline Configuration
Learn about all available pipeline settings
Blueprint Engine
Understand how Magpie orchestrates agent tasks
Azure Deployment
Deploy to Azure App Service or Container Instances