# MS Teams

{% hint style="warning" %}
Webhook Notification Channel is getting an upgrade: meet [Webhook Connected App](https://docs.groundcover.com/integrations/connected-apps/generic-webhook)
{% endhint %}

To integrate groundcover with MS Teams, follow the steps below. Note that you’ll need at least a **Business** subscription of MS Teams to be able to create workflows.

1. **Create a webhook workflow for your dedicated Teams channel**\
   Go to Relevant Team -> Specific Channel -> "Workflows", and create a webhook workflow
2. **The webhook workflow is associated a URL** which is used to trigger the MS Teams integration on groundcover - make sure to copy this URL
3. **Set Up the Webhook in groundcover**
   * Head out to the integrations section: Settings -> Integrations, to create a new [Webhook](https://docs.groundcover.com/integrations/workflow-integrations/webhook-integration)
   * Start by giving your Webhook integration a name. This name will be used below in the provider block sample .
   * Set the `Webhook URL` to the url you copied from field (2)
   * Keep the HTTP method as `POST`
4. **Create a Workflow**\
   Go to `Monitors --> Workflows --> Create Workflow`, and paste the YAML configuration provided below.
5. **Configure the `provider` Blocks (There are two of them)**\
   In the `provider` block, replace `{{ providers.your-teams-integration-name }}` with your actual Webhook integration name (the one you created in step 3)\
   For example, if you named your integration `test-ms-teams`, the config reference would be: `{{ providers.test-ms-teams }}`

{% hint style="info" %}
The following example shows a pre-configured MS Teams workflow template. You can easily modify workflows to support different formats based on the MS Teams workflow schema.
{% endhint %}

**Sample code for your groundcover workflow:**

```yaml
workflow:
  id: ms-teams-alerts-workflow
  description: Sends an API to MS Teams alerts endpoint
  name: ms-teams-alerts-workflow
  triggers:
  - type: alert
    filters:
    - key: annotations.ms-teams-alerts-workflow
      value: enabled
  consts:
    silence_link: 'https://app.groundcover.com/monitors/create-silence?keep.replace(keep.join(keep.dict_pop({{ alert.labels }}, "_gc_monitor_id", "_gc_monitor_name", "_gc_severity", "backend_id", "grafana_folder"), "&", "matcher_"), " ", "+")'
    monitor_link: 'https://app.groundcover.com/monitors?backendId={{ alert.labels.backend_id }}&selectedObjectId={{ alert.labels._gc_monitor_id }}'
    title_link: 'https://app.groundcover.com/monitors/issues?backendId={{ alert.labels.backend_id }}&selectedObjectId={{ alert.fingerprint }}'
    description: keep.dictget( {{ alert.annotations }}, "_gc_description", '')
    redacted_labels: keep.join(keep.dict_pop({{alert.labels}}, "_gc_monitor_id", "_gc_monitor_name", "_gc_severity", "backend_id", "grafana_folder", "_gc_issue_header"), "-\n")
    title: keep.dictget( {{ alert.annotations }}, "_gc_issue_header", "{{ alert.alertname }}")

  actions:
  - if: '{{ alert.status }} == "firing"'
    name: teams-webhook-firing
    provider:
      config: ' {{ providers.your-teams-integration-name }} '
      type: webhook
      with:
        body:
          type: message
          attachments:
          - contentType: application/vnd.microsoft.card.adaptive
            content:
              $schema: http://adaptivecards.io/schemas/adaptive-card.json
              type: AdaptiveCard
              version: "1.2"
              body:
              - type: TextBlock
                text: "\U0001F6A8 Firing: {{ consts.title }}"
                weight: bolder
                size: large
              - type: TextBlock
                text: "[Investigate Issue]({{consts.title_link}})"
                wrap: true
              - type: TextBlock
                text: "{{ consts.description }}"
                wrap: true
              - type: TextBlock
                text: "[Silence]({{consts.silence_link}})"
                wrap: true
              - type: TextBlock
                text: "[See monitor]({{consts.monitor_link}})"
                wrap: true
              - type: TextBlock
                text: "{{ consts.redacted_labels }}"
                wrap: true
  - if: '{{ alert.status }} != "firing"'
    name: teams-webhook-resolved
    provider:
      config: ' {{ providers.your-teams-integration-name }} '
      type: webhook
      with:
        body:
          type: message
          attachments:
          - contentType: application/vnd.microsoft.card.adaptive
            content:
              $schema: http://adaptivecards.io/schemas/adaptive-card.json
              type: AdaptiveCard
              version: "1.2"
              body:
              - type: TextBlock
                text: "\U0001F7E2 Resolved: {{ consts.title }}"
                weight: bolder
                size: large
              - type: TextBlock
                text: "[Investigate Issue]({{consts.title_link}})"
                wrap: true
              - type: TextBlock
                text: "{{ consts.description }}"
                wrap: true
              - type: TextBlock
                text: "[Silence]({{consts.silence_link}})"
                wrap: true
              - type: TextBlock
                text: "[See monitor]({{consts.monitor_link}})"
                wrap: true
              - type: TextBlock
                text: "{{ consts.redacted_labels }}"
                wrap: true
  
```
