Add a slack notification using a trigger

Notifications to a Slack channel are currently a Dark Feature that can be enabled in Comala Document Management 6.11.3. 

Overview

A custom notification can be created and posted to a channel in a Slack workspace using a workflow {trigger} and the {slack-channel-message} macro.

The {slack-channel-message} macro works similarly to the {set-message} macro in a trigger. The message instead of being added to a page is posted to a Slack channel identified by a webhook URL.

The content of the macro body is posted as the message content

  • the macro body content format is plain text
  • the values for any value references in the body will be rendered in the message e.g.@author@ will display the username of the page author
  • the poster is the name of the Slack app created

Link a channel in a Slack workspace for notifications

For the trigger to work, a Slack app needs to be created in the Slack workspace and a webhook feature added to post to a specific Slack channel.

The URL from the webhook in the Slack app is added to the {slack-channel-message} macro.

{slack-channel-message:webhook=https://hooks.slack.com/services/<webhook_ID>}


When added as part of a trigger macro the message will be posted to the Slack channel denoted by the webhook URL.

See: Set up a Slack channel for notifications

Add a slack notification trigger

Once the Slack has been created and the webhook added a notification cab be posted to the Slack channel by adding a trigger to your workflow.

You will need to add the {slack-channel-message} macro to the body of the trigger. This will act as the action macro for the trigger.

{slack-channel-message:webhook=<webhookurl>}


You will need to Copy and paste the <webhookurl> from the Slack app into the macro.


The webhook URL will be in the format  https://hooks.slack.com/services/<webhook_ID>.

  • the <webhook_ID> element will be unique to the Slack channel in the Slack workspace.


Adding the following trigger markup will post a notification when the workflow transitions to the Approved state.

{trigger:statechanged|state=Approved}
	{slack-channel-message:webhook=https://hooks.slack.com/services/<webhook_ID>}
    This is my first Slack notification.
	It was sent from the @pagetite@ page
    when the content was transitioned to the Approved state.
    Thanks @user@
    {slack-channel-message}
{trigger}


A typical  <webhook_ID> will look similar to "T016LT7RLQH/B016G1FCTMJ/SPIM4rxIZR4Uc5eZX5FmrWmZ". A webhook ID is unique to a Slack app, the specific channel, the specific Slack workspace. 

How this works

  • the trigger macro listens for the state changed event to the Approved state

  • the slack-channel-message macro posts the notification message to the Slack workspace app and channel identified by the webhook URL

  • the message consists of the body content of the slack-channel-message macro


  • the name of the message poster in Slack is the Slack app
  • value reference values are rendered in the notification e.g @user@ is the user admin; @pagetitle@ is Project Team Meeting Jun 30 2020.


Slack notification triggers can be configured for most workflow events. The same webhook URL can be used for triggers listening to different workflow events to post to the Slack channel in the workspace.

If required

  • you can add the app to other Slack workspace channels adding a different webhook to allow you to post into different channels
  • different Slack apps can be created for different notification requirements choosing the Slack app name to reflect the notifications e.g. approvals; rejections

See https://api.slack.com/messaging/webhooks

See Also

Content Integrations

Unable to render {children}. Page not found: Slack notifications.

Workflow Authoring Guide