# Sending data to a Slack channel

{% hint style="warning" %}
This documentation references external sources.&#x20;

Nexthink does not control the accuracy of third-party documentation or external updates that can result in inconsistencies.

Report any errors or inconsistencies to [Nexthink Support](https://support.nexthink.com/).
{% endhint %}

This document demonstrates how to send data to a Slack channel, using Nexthink webhook capability, to stand out from other messages in the channel.

## In Slack <a href="#sendingdatatoaslackchannel-inslack" id="sendingdatatoaslackchannel-inslack"></a>

1. [Create a new Slack app](https://api.slack.com/apps?new_app=1) in the workspace where you want to post messages.
2. From the **Features** page, toggle **Activate Incoming Webhooks** on.

<figure><img src="https://268444917-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FxJSUDk9NTtCHYPG5EWs3%2Fuploads%2Fgit-blob-b2d3f4b6166dac900e27630cb006451a027bb2f7%2Fnxwh-1642167674.png?alt=media" alt="Activating incoming webhooks in Slack"><figcaption></figcaption></figure>

3. Click **Add New Webhook to Workspace**.

<figure><img src="https://268444917-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FxJSUDk9NTtCHYPG5EWs3%2Fuploads%2Fgit-blob-113f1bcf5098c695190d5f78df0082aed71fa949%2Fnxwh-1642167810.png?alt=media" alt="Adding new webhook to workspace" width="544"><figcaption></figcaption></figure>

4. Pick a channel that the app will post to, then click **Authorize**.

<figure><img src="https://268444917-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FxJSUDk9NTtCHYPG5EWs3%2Fuploads%2Fgit-blob-9758753a88d0c6e7fbfee9f6ecf3292418a5b093%2Fnxwh-1642168136.png?alt=media" alt="Authorization" width="442"><figcaption></figcaption></figure>

5. Copy the generated [Incoming Webhook URL](https://api.slack.com/messaging/webhooks#posting_with_webhooks) for future reference. That is, for the [connector credential](#configuring-a-connector-credential-for-the-servicenow-incident-creation) and [webhook configuration](#configuring-a-webhook-for-servicenow-incident-creation) in the Nexthink web interface.\
   **Webhook URL** example: `https://hooks.slack.com/services/T00000000/BXXXXXXXXXX/PLVXXXXXXXXXXXXXXXXXXXXX`

<figure><img src="https://268444917-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FxJSUDk9NTtCHYPG5EWs3%2Fuploads%2Fgit-blob-e54e53d424b3f0e0843ba2dfd9c3bad18b59817a%2Fnxwh-1642168271.png?alt=media" alt="Webhook URL" width="544"><figcaption></figcaption></figure>

## In Nexthink <a href="#sendingdatatoaslackchannel-innexthink" id="sendingdatatoaslackchannel-innexthink"></a>

From the Nexthink web interface:

* [Configure a connector credential for the webhook](#postingamessageinzoom-configuringaconnectorcredentialforzoomcredentialzoomtrue)
* [Configure and test the webhook to post messages in Slack](#postingamessagetoanmsteamschannel-configuringawebhookformschannel)

### Configuring a connector credential for Slack <a href="#postingamessageinzoom-configuringaconnectorcredentialforzoomcredentialzoomtrue" id="postingamessageinzoom-configuringaconnectorcredentialforzoomcredentialzoomtrue"></a>

From the [connector credential](https://docs.nexthink.com/platform/~/changes/Sh4xqs4GDClkDKT9Hvux/integrations/outbound-connectors/connector-credentials) configuration page, fill out the fields using the information from the connection you created in Slack.

1. Choose the **HTTPS** option from the **Protocol** drop-down.
2. Paste the root `https://hooks.slack.com/`  into the **URL address** field from [Webhook URL](#sendingdatatoaslackchannel-inslack) from Slack configuration.
3. Choose **Basic** option from the **Authorization** drop-down.
4. Type in `Test` in the fields **Username** and **Password**, as these fields are not required when configuring Incoming Webhooks for Slack.
5. **Save** the credential.

### Configuring a webhook for Slack channel <a href="#postingamessagetoanmsteamschannel-configuringawebhookformschannel" id="postingamessagetoanmsteamschannel-configuringawebhookformschannel"></a>

From the [webhook configuration page](https://docs.nexthink.com/platform/~/changes/Sh4xqs4GDClkDKT9Hvux/integrations/outbound-connectors/webhooks/managing-webhooks), fill out the fields using the information from the connection you created in Slack and the connector credential defined in Nexthink:

1. Fill in the **NQL Condition** following the [Configuring webhook NQL conditions](https://docs.nexthink.com/platform/~/changes/Sh4xqs4GDClkDKT9Hvux/integrations/outbound-connectors/webhooks/managing-webhooks/configuring-webhook-nql-conditions) documentation.

   * After filling in the NQL Condition, the system lists the [allowed placeholders](https://docs.nexthink.com/platform/~/changes/Sh4xqs4GDClkDKT9Hvux/integrations/outbound-connectors/managing-webhooks/configuring-webhook-fields_-method-resource-and-payload#configuringwebhookfields-method-resource-andpayload-usingdatamodelvariablesasplaceholdersinthepayloa) for the **Payload**.&#x20;

   ```
   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, device.name
   ```
2. Choose the configured [connector credential](#postingamessageinzoom-configuringaconnectorcredentialforzoomcredentialzoomtrue) for Slack from the **Credentials** drop-down.
3. Select the **POST** from the **Method** drop-down.
4. Paste into the **Resources** field, the URL endpoint from the [Slack configuration](#sendingdatatoaslackchannel-inslack) without the root URL address. For example:  \
   `services/T00000000/BXXXXXXXXXX/PLVXXXXXXXXXXXXXXXXXXXXX`
5. Add the message you want to send in **Payload**. See the example below.\
   alert.alerts

   ```
   {
     "text": "There is an alert {{alert.monitor.name}} that is affecting the digital experience"
   }
   ```
6. **Send Test** to make sure the message is pushed into Slack.

{% hint style="info" %}
Refer to the [Slack API ](https://api.slack.com/reference/surfaces/formatting#rich-layouts)documentation for more information about supported payloads.
{% endhint %}
