Integrating Community with Slack

Difficulty Trivial
Skill level required Novice
Tools Preferences editor, workflows
Estimated time to complete 1 hour

Introduction

You can integrate Yomly with external messaging applications, such as Slack, Microsoft Teams, and Google Hangouts. This can, for example, enable you to send a notification through the messaging app when an article is added to Community.

Integrations such as these are trivial, which means there are no coding requirements. The platform provides all of the tools required to accomplish the integration (and much more complex integrations, such as Microsoft Dynamics 365).

Objective

In this tutorial, you will learn how to modify the platform to enable Community to publish notifications to your chosen Slack channel when an article is added or modified.

Procedure

To achieve the objective, you must do the following:

  1. Create and define the preference in the Preferences editor.
  2. Configure the webhook.
  3. Modify the workflows associated with Community feeds.
  4. Test the integration.

Step 1: Create and define the preference in the Preferences editor

For any feature with the ability to change platform behaviour, you need a mechanism to set up, enable, or disable the service. Your first step is to generate the preference definition.

You can do this in the Preferences editor. Create a preference with the following settings:

Setting Description
enabled A Boolean field that determines whether or not the integration is enabled
communityWebHook The URL of the Slack webhook
comments A field that provides you with the ability to document the changes you make to a preference setting.

To set up this preference, you can use the following schema:

{

  "$schema": "http://json-schema.org/draft-07/schema#",

  "$id": "http://example.com/product.schema.json",

  "title": "ESlack Integration",

  "description": "Preference for the Slack Integration",

  "type": "object",

  "properties": {

    "enabled": {

     "description": "true if the feature is enabled, false or null if not",

      "type": "boolean"

    },

        "communityWebHook": {

      "description": "The webhook for the communitychannel",

      "type": "string",

      "widget": "url"

    },

        "comments": {

      "description": "The webhook for the communitychannel",

      "type": "string"

    }

  }

}

The following image illustrates the complete definition of the preference, including the documentation:

mceclip0.png

Step 2: Configure the webhook

  1. In your Slack workspace, search for incoming webhooks. 

  2. Enter the required details in the dialogue and point the webhook to the required Slack channel.

  3. Copy the webhook URL.

  4. In Yomly, paste the webhook URL in the communityWebHook field in the preference you created in Step 1.

mceclip1.png

Step 3: Modify the workflows associated with Community feeds

There are two workflows associated with Community feeds; one for creating and the other for updating an article. You must modify both workflows. Do the following:

    1. Check if the integration is enabled.

      To do this, simply use a get_preference, followed by a gateway.

      If the preference is disabled or not present, you can simply continue to the next step of the workflow, which guarantees backwards compatibility.

    2. Format the body of the request you are sending Slack.

      Use the moustache language with the script worker to return the formatted body.

      You can use the following payload, including the required moustache markup:

      {

          "text": "{{articleTitle}}",

          "blocks": [

            {

              "type": "header",

              "text": {

                "type": "plain_text",

                "text": "{{articleTitle }}"

              }

            },

            {

              "type": "image",

              "title": {

                "type": "plain_text",

                "text": "{{ articleSubtitle}}"

              },

              "block_id": "image4",

              "image_url": "{{fileDef}}",

              "alt_text": "{{articleTitle}}"

            },

            {

              "type": "section",

              "text": {

                "type": "mrkdwn",

                "text": "{{articleExcerpt}}"

              }

            }

          ]

        }
    3. Call the webhook by passing the data body that you created in the previous step.

The following image illustrates the modified workflow:

mceclip2.png

Step 4: Test the integration

You can test the whole setup by updating an article. After saving your changes to the article, if the integration is successful, you will see a notification (such as the following one) in the selected Slack channel:

 

mceclip3.png

Additional steps

The data provided to the webhook has multiple options that you can play with. You can add icons, change colours, set reminders, and more.

With a correct combination of properties in your preferences and by changing the template inside your workflow, you can achieve multiple effects.

Was this article helpful?
0 out of 0 found this helpful

Comments

0 comments

Please sign in to leave a comment.