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:
- Create and define the preference in the Preferences editor.
- Configure the webhook.
- Modify the workflows associated with Community feeds.
- 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:
Step 2: Configure the webhook
-
In your Slack workspace, search for incoming webhooks.
-
Enter the required details in the dialogue and point the webhook to the required Slack channel.
-
Copy the webhook URL.
-
In Yomly, paste the webhook URL in the communityWebHook field in the preference you created in Step 1.
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:
-
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.
-
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}}"
}
}
]
} -
Call the webhook by passing the data body that you created in the previous step.
The following image illustrates the modified workflow:
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:
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.
Comments
Please sign in to leave a comment.