Posting a message to an MS Teams channel

This document demonstrates how to post a message to an MS Teams channel using a webhook.

In MS Teams

After creating a new MS Teams channel, configure a new workflow using Microsoft Power Automate.

  1. Click three dots on the created channel and select Workflows.

  2. From the pop-up, search for and choose Post to a channel when a webhook request is received option. See the image below.

  1. Name the workflow and define the workflow connection.

    • Define the Team channel (from MS Teams) to notify using the Nexthink webhook.

  2. Select the Add Workflow button to create the new workflow.

  3. Copy the URL for future reference for future reference. That is, for the connector credential and webhook configuration in the Nexthink web interface. See the image below.

    • URL example: https://xxxxx.your-instance.logic.azure.com:443/workflows/XXXXXXXXXXXXX/triggers/manual/paths/invoke?api-version=2016-06-01&sp=%2Ftriggers%2Fmanual%2Frun&sv=1.0&sig=yhejWbe6e03M9-cvU-hXXXXXXXXXXXXX

  4. Select Manage your Workflow:

    • Ensure the output format is set to attachments

    • Ensure the Adaptive card is defined as content.

    • For private Team channels, use the dropdowns to set Post as: User. Otherwise, you can select Fow Bot.

In Entra ID

Jump to the In Nexthink section if you do not require authentication OAuth 2.0 for the connector credentials.

Follow the steps below in Microsoft Entra ID:

  1. Go to your Entra ID instance and register a new Application.

    • Manage > App registrations > New registration

  2. Name the application and define the supported account type.

  3. Register the application and copy the application ID for future reference when configuring the connector credentials with authetication in Nexthink.

  4. Click on the new Client secret and define the experience date.

  5. Copy the secret value (not the ID) for future reference when configuring the connector credentials with authetication in Nexthink.

    • You can only copy the secret value after created.

  6. Navigate to the API permission tab and add the Access Microsoft Flow as signed in user permission.

  7. Navigate back to overview of the just registered app and navigate to the to Endpoints tab.

  8. Save the OAuth 2.0 token endpoint (v2) for future reference when configuring the webhook in Nexthink.

In Nexthink

From the Nexthink web interface:

Configuring a connector credential for MS Team without authentication

From the connector credential configuration page, fill out the fields using the information from the configured incoming webhook in MS Teams:

  1. Choose the HTTPS option from the Protocol drop-down.

  2. Paste the root https://xxxxx.your-instance.logic.azure.com:443 into the URL address field from URL from MS Teams.

  3. Choose No Auth (None) option from the Authorization drop-down.

  4. Save the credential.

Configuring a connector credential for MS Team with authentication

From the connector credential configuration page, fill out the fields using the information from the configured incoming webhook in MS Teams:

  1. Choose the HTTPS option from the Protocol drop-down.

  2. Paste the root https://xxxxx.your-instance.logic.azure.com:443 into the URL address field from URL from MS Teams.

  3. Choose OAuth 2.0 - Client Credentials option from the Authorization drop-down.

  4. Enter the Access token URL, Client ID and Client secret using the values from the Entra ID application registration.

  5. Save the credential.

Configuring a webhook for MS channel

From the webhook configuration page, fill out the fields using the information from the connection you created in MS Teams and the connector credential defined in Nexthink:

  1. Fill in the NQL Condition following the Configuring webhook NQL conditions documentation. See query below.

alert.alerts
| where monitor.tags contains "web-applications"
| where alert.context contains "*Salesforce*" or alert.context contains "*Microsoft*"
| list alert.monitor.name, alert.status, monitor.tags, alert.context, trigger_time, recovery_time, alert.monitor.thresholds, monitor.priority, alert.trigger_values, alert.trigger_reference_value, alert.recovery_values, alert.context, device_view_link , issue_view_link
  1. Choose the configured connector credential for MS Team (depending on the case, with authentication or without authentication) from the Credentials drop-down.

  2. Select the POST from the Method drop-down.

  3. Paste into the Resources field, the URL endpoint from the MS Teams configuration without the root URL address. For example: /workflows/XXXXXXXXXXXXXXXXXXX/triggers/manual/paths/invoke?api-version=?????&sp=/triggers/manual/run&sv=1.0&sig=XXXXXXXXXXXXXXX

    • Make sure the URL is not encoded.

  4. Add the message you want to send in Payload. See the example below.

{
  "type": "message",
  "attachments": [{
      "contentType": "application/vnd.microsoft.card.adaptive",
      "content": {
        "$schema": "http://adaptivecards.io/schemas/adaptive-card.json",
        "type": "AdaptiveCard",
        "version": "1.0",
        "msteams": {
          "width": "Full"
        },
        "body": [{
            "type": "TextBlock",
            "text": "Nexthink Alert",
            "id": "Title",
            "spacing": "Medium",
            "horizontalAlignment": "Center",
            "size": "ExtraLarge",
            "weight": "Bolder",
            "color": "Accent"
          }, {
            "type": "Container",
            "items": [{
                "type": "TextBlock",
                "text": "{{alert.alert.context.application.name}},{{alert.monitor.name}}",
                "wrap": true,
                "color": "Default",
                "size": "Medium"
              }
            ],
            "style": "emphasis"
          }, {
            "type": "FactSet",
            "facts": [{
                "title": "Assigned to",
                "value": "Infrastructure Team"
              }, {
                "title": "Triggered on: ",
                "value": "{{alert.alert.trigger_time}}"
              }, {
                "title": "Application Name",
                "value": "{{alert.alert.context.application.name}}"
              },
            ]
          }, {
            "type": "TextBlock",
            "text": "Condition breached:",
            "wrap": true
          }, {
            "type": "Table",
            "columns": [{
                "width": 1
              }, {
                "width": 1
              }, {
                "width": 1
              }, {
                "width": 1
              }
            ],
            "rows": [{
                "type": "TableRow",
                "cells": [{
                    "type": "TableCell",
                    "items": [{
                        "type": "TextBlock",
                        "text": "Metric name",
                        "wrap": true
                      }
                    ]
                  }, {
                    "type": "TableCell",
                    "items": [{
                        "type": "TextBlock",
                        "text": "Threshold",
                        "wrap": true
                      }
                    ]
                  }, {
                    "type": "TableCell",
                    "items": [{
                        "type": "TextBlock",
                        "text": "Metric value",
                        "wrap": true
                      }
                    ]
                  }, {
                    "type": "TableCell",
                    "items": [{
                        "type": "TextBlock",
                        "text": "Baseline Value",
                        "wrap": true
                      }
                    ]
                  }
                ]
              }, {
                "type": "TableRow",
                "cells": [{
                    "type": "TableCell",
                    "items": [{
                        "type": "TextBlock",
                        "text": "{{alert.alert.trigger_values[0].alias}}",
                        "wrap": true
                      }
                    ]
                  }, {
                    "type": "TableCell",
                    "items": [{
                        "type": "TextBlock",
                        "text": "{{alert.monitor.thresholds[0].value}}",
                        "wrap": true
                      }
                    ]
                  }, {
                    "type": "TableCell",
                    "items": [{
                        "type": "TextBlock",
                        "text": "{{alert.alert.trigger_values[0].value}}",
                        "wrap": true
                      }
                    ]
                  }, {
                    "type": "TableCell",
                    "items": [{
                        "type": "TextBlock",
                        "text": "{{alert.alert.trigger_reference_value}}",
                        "wrap": true
                      }
                    ]
                  }
                ]
              }, {
                "type": "TableRow",
                "cells": [{
                    "type": "TableCell",
                    "items": [{
                        "type": "TextBlock",
                        "text": "{{alert.alert.trigger_values[1].alias}}",
                        "wrap": true
                      }
                    ]
                  }, {
                    "type": "TableCell",
                    "items": [{
                        "type": "TextBlock",
                        "text": "{{alert.monitor.thresholds[1].value}}",
                        "wrap": true
                      }
                    ]
                  }, {
                    "type": "TableCell",
                    "items": [{
                        "type": "TextBlock",
                        "text": "{{alert.alert.trigger_values[1].value}}",
                        "wrap": true
                      }
                    ]
                  }, {
                    "type": "TableCell",
                    "items": [{
                        "type": "TextBlock",
                        "text": "",
                        "wrap": true
                      }
                    ]
                  }
                ]
              }
            ],
            "showGridLines": false
          }, {
            "type": "ActionSet",
            "actions": [{
                "type": "Action.OpenUrl",
                "title": "View in Nexthink",
                "URL": "{{alert.alert.issue_view_link}}"
              }
            ]
          }
        ]
      }
    }
  ]
}
  1. Send Test to make sure the message is pushed into MS Teams.

Last updated

Was this helpful?