Skip to main content

Slack integration: assignee change

In Part 1 of this example we showed how to set up a webhook to post a message in a Slack channel when a content item was created or updated.

In this example we show you how to post a personalized message to Slack when a content item is assigned to one or more users.

If you've already got a webhook set up following the steps in Part 1, then you go straight to Step 2 of this example.

Pre-requisites
Link copied!

  • A Slack account
  • A Dynamic Content account with the developer role assigned for the hub in which you want to create webhooks

This example is designed to work with the payloads generated from the "content item - assignee changed" webhook event. For this webhook event, the webhook payload will contain the content item to which more on or more users was assigned.

Before you begin: configure a Slack app
Link copied!

In Slack create an app if you don't already have one set up. This app must be configured to accept incoming webhooks (1 in the image below).

When the app is added to your chosen Slack workspace and configured for Webhooks, a Webhook URL will be generated (2). This is the URL you'll specify when creating a Webhook in Dynamic Content.

Copy the URL to the clipboard.

Set up an app in Slack to accept incoming webhooks

Step 1: Create a webhook
Link copied!

Choose "Webhooks" from the Development menu and click the "Add webhook" button. Give the webhook a label and paste the webhook URL generated by Slack into the URL field.

Set "Content item- assignee change" as the webhook trigger as highlighted in the image below.

Create a webhook in Dynamic Content with the Slack app webhook URL

Step 2 Find the URL to open content items in the Content Library
Link copied!

As part of the Slack message, you can include a link to the content item in Dynamic Content. The structure of the URL is as shown in the example below.

You can include this URL, together with the templated value for the content item id, in your custom payload.

https://content.amplience.net/#!/<hubname>/authoring/content-item/edit/<content item id>

To find your hub name, open a content item from the Content Library and look at the item's URL at the top of the window. In the example below, the hub name (1) is ampproduct-doc.

Find the structure of the URL for items on your hub

Step 3: Configure the custom payload
Link copied!

In the payload section choose the "Custom" radio button and add the following handlebars in the custom payload box. This handlebars is used to generate the custom payload included in the body of the webhook request. For now the Slack message will just state that the assignee for a content item has changed and include the URL to open the item in Dynamic Content. You'll personalize the message for each assignee in a later step.

An example custom payload, including the content item URL, is shown below. Change ampproduct-doc to the hubname you found in Step 2.

{
"blocks": [
{
"type": "section",
"text": {
"type": "mrkdwn",
"text": "Content item assigned: <https://content.amplience.net/#!/ampproduct-doc/authoring/content-item/edit/{{payload.id}}|{{payload.label}}>"
}
}
]
}

When payload has been added, click the "Save" button at the top of the window to create the webhook.

Add the handlebars to generate the custom payload for the Slack message

Step 4: Trigger your webhook and view the result in Slack
Link copied!

To test out what you've added to your webhook configuration so far, go to the Content Library and assign a content item to one or more users.

To test out your webhook congiguration, assign a content item to one or more users

A message will be shown in the Slack channel you chose to send messages to and will include the item's name and a link that will open the item in Dynamic Content.

A message is displayed in your Slack channel, including the URL of the content item for which the assignees have changed

Step 5: Find your user ids
Link copied!

The payload sent when the "content item- assignee change" webhook event is triggered includes the id of each of the users to which the content item is assigned. You need to make a note of the ids of each of the users that you want to include in your assignee workflow so you can match them with their Slack names. Our webhook testing features makes this easy.

Go into the production view, find any content item that has no assignees and assign it to a user, making a note of that user's name. This will trigger your webhook and send a payload containing the id of the user that the content item has been assigned to.

Assign a content item to a use

Then unassign the content item from the previous user and assign it to a new user, again making a note of their name and the order in which you assigned the content. The webhook will be triggered again with a payload containing the id of this user.

Assign the content item to another user

When you have assigned the item to each of your users in turn, open your webhook.

  • Scroll down to the payload section and click the "Standard" button (1 in the image below). Don't save the webhook, you will close the window without saving when you've finished.

  • Click the icon (2) to open the test pane.

  • Choose a recent delivery from the list (3). The most recent invocation of the webhook is shown first. So if you assigned content to two users one at a time, to find the first user that you assigned a content item to, you'd choose the second entry in the list.

  • Click the test button (4) to trigger the webhook in test mode.

Choose the webhook delivery for the first user you assigned the content item to

Take a look at the webhook payload and find the assignees list. If you followed the steps to assign the item to one user at a time, the list will contain just one user id (1 in the image below).

Test using this webhook delivery to find the user id for the assignee

Repeat the process for each of your users and match the user ids to their names.

Step 6: Update the custom payload to include Slack user ids
Link copied!

In the custom payload, use the handlebars contains helper to customize the message displayed for a user when content is assigned to them.

To include a mention for a user, and generate a notification in Slack, you need to know their Slack user id. You can find out how to get this ID in the Slack documentation.

To mention a user with the Slack user id of UTPGW47M3, include the following in the custom payload:

<@UTPGW47M3>

An example of the updated handlebars that checks for two users is shown below. In the custom payload each of the assignees is mentioned using their Slack user id. A user that is mentioned in the message will receive a notification (if they have notifications turned on).

 "text": "<https://content.amplience.net/#!/ampproduct-doc/authoring/content-item/edit/{{payload.id}}|{{payload.label}}> assigned to:
{{#contains payload.assignees "200827cd-f51c-4d3e-bb50-87623d1c5768"}}<@UTPGW47M3> {{/contains}}
{{#contains payload.assignees "1c9409a4-2f19-4f3a-932a-01af19fa112b"}}<@UV0CNPV4J> {{/contains}}"

Your custom payload should now look something like that shown below. You will need to include the Dynamic Content user ids and Slack user ids of your own users.

Here's an example of the custom payload including Slack user ids.

{
"blocks": [
{
"type": "section",
"text": {
"type": "mrkdwn",
"text": "<https://content.amplience.net/#!/ampproduct-doc/authoring/content-item/edit/{{payload.id}}|{{payload.label}}> assigned to: {{#contains payload.assignees "200827cd-f51c-4d3e-bb50-87623d1c5768"}}<@UTPGW47M3> {{/contains}}{{#contains payload.assignees "1c9409a4-2f19-4f3a-932a-01af19fa112b"}}<@UV0CNPV4J> {{/contains}}"
}
}
]
}

Use the test feature to check the custom payload that is generated for each of your recent deliveries.

Use the webhook test feature to check the custom payload

Step 7: View the result in Slack
Link copied!

Now when you assign a content item in the Production view, a message will be posted to your Slack channel. If you've added the Dynamic Content and Slack user ids for the users to which the content item is assigned, the assignees will be mentioned in the message.

A message is posted in your Slack channel, notifying each assignee by their Slack name

Webhooks overview

Customizable webhooks

Webhook payloads

Assigning content