> ## Documentation Index
> Fetch the complete documentation index at: https://docs.dodopayments.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Microsoft Teams

> 将 Dodo Payments 通知发送到 Microsoft Teams 渠道，使用丰富的自适应卡片。

## 介绍

通过 Microsoft Teams 中的实时支付通知，让您的业务团队保持信息同步。此集成将支付事件作为丰富的自适应卡片传递——非常适合 Teams 作为主要协作工具的企业环境。

<Info>
  本指南假设您在 Microsoft Teams 工作区拥有创建 Webhook 的管理员权限。
</Info>

## 开始使用

<Steps>
  <Step title="Open the Webhook Section">
    在您的 Dodo Payments 仪表板中，导航至 <b>Webhooks → + 添加终端</b> 并展开集成下拉菜单。

    <Frame>
      <img src="https://mintcdn.com/dodopayments/slbAEdrLLwKHfaRf/images/integrations/teams.png?fit=max&auto=format&n=slbAEdrLLwKHfaRf&q=85&s=240820e1a3d3162b2faee6fa052535c6" alt="Add Endpoint and integrations dropdown" style={{ maxHeight: '500px', width: 'auto' }} width="1694" height="936" data-path="images/integrations/teams.png" />
    </Frame>
  </Step>

  <Step title="Select Microsoft Teams">
    选择 <b>Microsoft Teams</b> 集成卡。
  </Step>

  <Step title="Create Teams Webhook">
    在 Teams 中，前往您的频道 → ⋯ → 连接器 → 传入 Webhook → 配置。复制该 Webhook URL。
  </Step>

  <Step title="Paste Webhook URL">
    将 Teams Webhook URL 粘贴到端点配置中。
  </Step>

  <Step title="Customize Transformation">
    编辑转换代码，使消息格式为 Teams 的自适应卡片。
  </Step>

  <Step title="Test & Create">
    使用示例有效负载进行测试，然后点击 <b>创建</b> 以激活。
  </Step>

  <Step title="Done!">
    🎉 现在，您的 Teams 频道将以自适应卡片形式接收 Dodo Payments 更新。
  </Step>
</Steps>

## 转换代码示例

### 基本支付卡

```javascript payment_card.js icon="js" expandable theme={null}
function handler(webhook) {
  if (webhook.eventType === "payment.succeeded") {
    const p = webhook.payload.data;
    webhook.payload = {
      type: "message",
      attachments: [{
        contentType: "application/vnd.microsoft.card.adaptive",
        content: {
          type: "AdaptiveCard",
          body: [
            {
              type: "TextBlock",
              text: "✅ Payment Successful",
              weight: "Bolder",
              size: "Medium"
            },
            {
              type: "FactSet",
              facts: [
                { title: "Amount", value: `$${(p.total_amount / 100).toFixed(2)}` },
                { title: "Customer", value: p.customer.email },
                { title: "Payment ID", value: p.payment_id }
              ]
            }
          ]
        }
      }]
    };
  }
  return webhook;
}
```

### 订阅管理

```javascript subscription_card.js icon="js" expandable theme={null}
function handler(webhook) {
  const s = webhook.payload.data;
  switch (webhook.eventType) {
    case "subscription.active":
      webhook.payload = {
        type: "message",
        attachments: [{
          contentType: "application/vnd.microsoft.card.adaptive",
          content: {
            type: "AdaptiveCard",
            body: [
              {
                type: "TextBlock",
                text: "📄 Subscription Activated",
                weight: "Bolder",
                color: "Good"
              },
              {
                type: "FactSet",
                facts: [
                  { title: "Customer", value: s.customer.email },
                  { title: "Product", value: s.product_id },
                  { title: "Amount", value: `$${(s.recurring_pre_tax_amount / 100).toFixed(2)}/${s.payment_frequency_interval}` },
                  { title: "Next Billing", value: new Date(s.next_billing_date).toLocaleDateString() }
                ]
              }
            ]
          }
        }]
      };
      break;
    case "subscription.cancelled":
      webhook.payload = {
        type: "message",
        attachments: [{
          contentType: "application/vnd.microsoft.card.adaptive",
          content: {
            type: "AdaptiveCard",
            body: [
              {
                type: "TextBlock",
                text: "⚠️ Subscription Cancelled",
                weight: "Bolder",
                color: "Warning"
              },
              {
                type: "FactSet",
                facts: [
                  { title: "Customer", value: s.customer.email },
                  { title: "Product", value: s.product_id },
                  { title: "Cancelled At", value: new Date(s.cancelled_at).toLocaleDateString() }
                ]
              }
            ]
          }
        }]
      };
      break;
  }
  return webhook;
}
```

### 争议警报

```javascript dispute_card.js icon="js" expandable theme={null}
function handler(webhook) {
  if (webhook.eventType.startsWith("dispute.")) {
    const d = webhook.payload.data;
    const color = d.dispute_status === "won" ? "Good" : d.dispute_status === "lost" ? "Attention" : "Warning";
    const title = d.dispute_status === "won" ? "🏆 Dispute Won" : d.dispute_status === "lost" ? "❌ Dispute Lost" : "🚨 Dispute Update";
    
    webhook.payload = {
      type: "message",
      attachments: [{
        contentType: "application/vnd.microsoft.card.adaptive",
        content: {
          type: "AdaptiveCard",
          body: [
            {
              type: "TextBlock",
              text: title,
              weight: "Bolder",
              color: color
            },
            {
              type: "FactSet",
              facts: [
                { title: "Payment ID", value: d.payment_id },
                { title: "Amount", value: `$${(d.amount / 100).toFixed(2)}` },
                { title: "Status", value: d.dispute_status },
                { title: "Stage", value: d.dispute_stage }
              ]
            }
          ]
        }
      }]
    };
  }
  return webhook;
}
```

## 提示

* 使用自适应卡片进行丰富的交互式格式化
* 选择适当的颜色：良好（绿色）、警告（黄色）、注意（红色）
* 保持事实集简洁易读
* 在部署之前使用 Teams Webhook 测试工具进行测试

## 故障排除

<AccordionGroup>
  <Accordion title="No messages in Teams">
    * 验证 Webhook URL 是否正确且处于活动状态
    * 检查转换是否返回有效的自适应卡片 JSON
    * 确保该 Webhook 拥有在频道发布的权限
  </Accordion>

  <Accordion title="Card formatting issues">
    * 在 Teams Webhook 测试器中验证自适应卡片架构
    * 检查所有必需字段是否存在
    * 确保颜色值有效（Good、Warning、Attention、Default）
  </Accordion>
</AccordionGroup>
