# Microsoft Teams Integration Setup Guide

This guide walks you through connecting Lathe Studio to Microsoft Teams for notifications and team collaboration.

---

## Prerequisites

- Microsoft Teams account
- Permission to add connectors/apps to your team
- Project admin access in Lathe Studio

---

## Overview

The Microsoft Teams integration enables:

- **Test Run Notifications**: Get notified when test runs are completed
- **Build Alerts**: Receive alerts when builds are ready for testing
- **Release Updates**: Track release status changes
- **Team Collaboration**: Discuss test results in Teams channels

---

## Connecting Microsoft Teams

### Step 1: Add Incoming Webhook to Teams

1. In Microsoft Teams, go to the channel where you want notifications
2. Click the **...** (more options) next to the channel name
3. Select **Connectors**
4. Search for **Incoming Webhook**
5. Click **Add**
6. Give it a name: "Lathe Studio"
7. Upload the Lathe Studio logo (optional)
8. Click **Create**
9. Copy the webhook URL

### Step 2: Configure in Lathe Studio

1. Go to **Project Settings > Integrations > Microsoft Teams**
2. Paste the webhook URL
3. Click **Save**

### Step 3: Configure Notifications

Select which events trigger Teams notifications:

| Event                    | Description                                       | Default  |
|--------------------------|---------------------------------------------------|----------|
| Test Run Completed       | When a test run is marked complete                | Enabled  |
| Test Run Submitted       | When a tester submits results                      | Enabled  |
| Build Created            | When a new build is available                     | Enabled  |
| Release Released         | When a release is shipped                          | Enabled  |
| Test Case Failed         | When a test fails (immediate)                     | Disabled |
| Daily Summary            | Daily digest of activity                           | Disabled |

### Step 4: Test the Integration

1. Click **Send Test Message** in Lathe Studio
2. Check the Teams channel
3. You should see a test notification

---

## Notification Format

### Test Run Completed

**Card Title**: Test Run Completed

**Body**:

- Test Run: Smoke Tests - Build 245
- Project: E-commerce Platform
- Results: ✅ 42 Passed | ❌ 3 Failed | ⚠️ 1 Blocked
- [View Run] [View Report]

### Build Ready for Testing

**Card Title**: New Build Available

**Body**:

- Build: 246 (v2.4.1)
- Branch: main
- Status: Ready for testing
- [Assign to Release] [View Details]

---

## Channel Configuration

### Project Channels

Configure different Teams channels for different projects:

1. Go to **Project Settings > Integrations > Microsoft Teams**
2. Click **Add Channel**
3. Paste the webhook URL for the channel
4. Choose notification types

### Adaptive Cards

Notifications use Microsoft Adaptive Cards for rich formatting:

- Test result summaries
- Action buttons (View, Assign, Reject)
- Colored status indicators
- Collapsible details

---

## Microsoft Teams App (Coming Soon)

A dedicated Lathe Studio app for Microsoft Teams is in development. Features will include:

- Tab views for test dashboards
- Message extensions for quick test lookups
- Bot commands for status checks
- Meeting integration for test planning

---

## Troubleshooting

### Notifications not appearing

1. Verify the webhook URL is correct
2. Check the connector is active in Teams
3. Ensure notification settings are enabled
4. Try sending a test message

### Webhook URL errors

If you see "Invalid webhook URL":

1. Regenerate the webhook in Teams
2. Update the URL in Lathe Studio
3. Ensure the URL starts with `https://`

### Rate limiting

Microsoft Teams has rate limits for connectors:

- Maximum 30 messages per 60 seconds
- If exceeded, messages may be delayed or dropped

To avoid this:

1. Reduce notification frequency
2. Use daily digests instead of real-time notifications
3. Batch similar notifications

---

## Security

- Webhook URLs are encrypted at rest
- URLs contain unique tokens for authentication
- No Teams credentials are stored
- Users can remove the connector at any time
- Team owners can manage connector permissions

---

## Unlinking Microsoft Teams

To disconnect:

### Method 1: Remove Connector in Teams

1. Go to the channel in Teams
2. Click **...** > **Connectors**
3. Find "Incoming Webhook"
4. Click **Configured**
5. Find the Lathe Studio webhook
6. Click **Remove**

### Method 2: Remove in Lathe Studio

1. Go to **Project Settings > Integrations > Microsoft Teams**
2. Click **Remove Integration**
3. Confirm disconnection

**Note**: Removing the integration stops all notifications. Previously sent messages remain in Teams.

---

## Advanced Configuration

### Power Automate Integration

Use Microsoft Power Automate for advanced workflows:

1. Create a flow triggered by Lathe Studio webhook
2. Add actions like:
   - Send email notifications
   - Create Planner tasks
   - Update SharePoint lists
   - Post to other channels

### Custom Card Formatting

Enterprise customers can customize Adaptive Cards:

1. Go to **Organization Settings > Integrations > Microsoft Teams > Advanced**
2. Edit card templates using Adaptive Card JSON
3. Preview changes before saving

---

_For additional help, contact support._
