Posting a message to an MS Teams channel

This documentation references external sources. Nexthink does not have control over the accuracy of third-party documentation, nor any external updates or changes that might create inconsistencies with the information presented on this page. Please report any errors or inconsistencies to Nexthink Support.

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 when configuring the webhook in Nexthink. 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.

You must decode the URL from the Power Automator before pasting it in the webhook configuration in Nexthink.

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. Split the URL from MS Teams into 2 parts, the root and the resource.

    • Root: https://xxxxx.your-instance.logic.azure.com:443

    • Resource: /workflows/XXXXXXXXXXXXX/triggers/manual/paths/invoke?api-version=2016-06-01&sp=%2Ftriggers%2Fmanual%2Frun&sv=1.0&sig=yhejWbe6e03M9-cvU-hXXXXXXXXXXXXX

  3. Paste the root https://xxxxx.your-instance.logic.azure.com:443 into the URL address field.

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

  5. 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. Split the URL from MS Teams into 2 parts, the root and the resource.

    • Root: https://xxxxx.your-instance.logic.azure.com:443

    • Resource: /workflows/XXXXXXXXXXXXX/triggers/manual/paths/invoke?api-version=2016-06-01&sp=%2Ftriggers%2Fmanual%2Frun&sv=1.0&sig=yhejWbe6e03M9-cvU-hXXXXXXXXXXXXX

  3. Paste the root https://xxxxx.your-instance.logic.azure.com:443 into the URL address field.

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

  5. Enter the Access token URL, Client ID and Client secret using the values from the Entra ID application registration. See image below.

  6. 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 Name and Description.

  2. Fill in the NQL Condition following the Configuring webhook NQL conditions documentation.

  3. Choose the configured connector credential for MS Team (depending on the case, with authentication or without authentication) from the Credentials drop-down.

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

  5. Copy and paste into the Resources field, the URL endpoint from the MS Teams configurationwithout 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.

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

Refer to the Post an actionable message card to an Office 365 documentation from Microsoft for more information about actionable messages via connectors.

{
    "type": "message",
    "attachments": [
        {
            "contentType": "application/vnd.microsoft.card.adaptive",
            "content": {
                "$schema": "http://adaptivecards.io/schemas/adaptive-card.json",
                "type": "AdaptiveCard",
                "version": "1.0",
                "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.monitor.name}} alert {{alert.alert.status}} by Nexthink with the priority {{alert.monitors.priority}} version2",
                    "wrap": true,
                    "color": "Dark",
                    "size": "Medium"
                },
                {
                    "type": "TextBlock",
                    "text": "Application: {{alert.alert.context.application.name}}",
                    "wrap": true,
                    "color": "Dark",
                    "size": "Medium"
                }
            ],
            "style": "emphasis"
        },
                    {
                        "type": "FactSet",
                        "facts": [
                            {
                                "title": "Assigned to",
                                "value": "Infrastructure Team"
                            }, {
                               "title": "Effective Date",
                               "value": "{{alert.alert.trigger_time}}"
                           },  {
                               "title": "Applicaiton Name",
                               "value": "{{alert.alert.context.application.name}}"
                           },{
                               "title": "{{alert.alert.trigger_values[0].alias}}",
                               "value": "{{alert.alert.trigger_values[0].value}}"
                           }, {
                               "title": "{{alert.alert.trigger_values[1].alias}}",
                               "value": "{{alert.alert.trigger_values[1].value}}"
                           },
                       {
                               "title": "Reference Value",
                                "value": "{{alert.alert.trigger_reference_value}}"
                           }
                      ,{
                               "title": "{{alert.monitor.thresholds[0].alias}}",
                                "value": "{{alert.monitor.thresholds[0].value}}"
                           }
                        ]
                    },
        {
            "type": "ActionSet",
            "actions": [
                {
                    "type": "Action.OpenUrl",
                    "title": "CI Manual",
                    "url": "Link to your Nexthink instance"
                }
            ]
        }
                ]
            }
        }
    ]
}
  1. Send Test to make sure the message is pushed into MS Teams.

Last updated