Skip to Content
Technical Articles
Author's profile photo Dominik Bigl

Push SAP Cloud Platform Workflow Notifications to a Slack Channel

Intro

Let’s send SAP Cloud Platform Workflow (workflow) notifications to a Slack channel. These may be user task notifications or even some state changes of the workflow.

Quick Reference

These main steps are needed to push messages from the workflow to Slack

  1. (Slack) Create a Slack app with incoming-webhook permission
  2. (Slack) Install the app in your workspace and define the target channel
  3. (SCP Cockpit) Create a destination for the Webhook URL
  4. (SCP Workflow) Prepare the message in the context – Script task
  5. (SCP Workflow) Send the message to Slack – Service task

 

Step by Step Guide

Prepare Slack

If you are new to Slack follow this tutorial to create a new Slack Workspace: https://developers.sap.com/uk/tutorials/sapui5-register-app-api.html

In order to send messages from your workflow to a channel, some additional steps are needed.

 

Create a Slack app with incoming-webhook permission

Open the App Builder

Sign in to your workspace and

use Administration->Manage Apps and click on Build and Your Apps

or call https://api.slack.com/apps?new_app=1 in a new tab.

 

Create a new app

Set a useful name and the development Slack workspace and create the app.

 

In the Basic Information click the Permission section.

 

Select incoming-webhook under Scopes and save your changes.

 

Install the app in your workspace and define the target channel

Install your app to your workspace

 

Select the channel you want the messages be posted to and authorize your app.

 

Webhook URL

Go to Incoming Webhooks in the menu

With this Webhook URL you can post messages to the channel defined in the previous step. You can test this with curl, Postman,…

 

Be careful with this URL since it can be used by everyone to send messages to the specified channel! You may also read the Security recommendations.

 

That’s it for the moment! We can now send a message by posting a JSON to the Webhook URL.

Create a destination for the Webhook URL

Now we add a new destination to the Workflow service (you can add the destination also to your subaccount, if prefered).

Go to the Workflow service and click Configure Service and Destinations (default) and create a new destination.

Name <useful name>
Type HTTP
Description <useful description>
URL <Slack App Webhook URL Part 1>*
Proxy Type Internet
Authentication NoAuthentication

*) for security reasons don’t set the full Webhook URL here, e.g. use only the first 2 path words

 

Save your destination.

 

Enhance your workflow

Open your workflow in WebIDE

 

Add an Parallel Gateway to the workflow where you want to push a message to Slack.

Also add an Script Task to prepare the message sent to Slack.

You can do this also in sequence. But with the parallel paths there is a clear separation of the main workflow and the Slack communication.

Prepare the message in the context

Build a new context element with your slack message and useful context information.

For details about message formatting see https://api.slack.com/docs/message-formatting and https://api.slack.com/docs/message-attachments.

$.context.slackmessage = { "attachments": [
							{ "fallback":"An new partner change needs to be checked:",
							  "title":"Partner Change Check:" && $.context.partner.name,
							  "text":"some changes need to be checked ",
							  "fields": [ {	"title": "Partner ID",
											"value": $.context.partner.id,
											"short": true
										  },
										  {	"title": "Name",
											"value": $.context.partner.name,
											"short": true
										  } ]
                            }
                        ] };

 

Send the message to Slack

Add an Service Task to send the message to the Slack channel.

Destination <Slack destination name>
Choose a Service from Others
Path <Slack App Webhook URL Part 2>*
HTTP Method POST
Request Variable $.context.slackmessage

*) for security reasons put only the second part of the Webhook URL here, e.g. last path word

 

Add a  Parallel Gateway to combine the two paths.

 

Save and deploy your workflow.

 

Test your workflow

I’ll trigger a new instance from the Workflow Monitor. The initial context depends on your workflow definition.

 

The user task is in my Inbox

 

And I also received a Slack message

We’re done!

 

Conclusion

It’s quite simple to add Slack to your workflow.

But I have some security concerns about the Webhook URL, although you can whitelist IP ranges.

Also, if there are any error in the Slack workflow path, the whole workflow is broken!

 

So there should be:

  • an “End Path Event” for the SCP Workflow to end a parallel path. Or even an embedded workflow based on intermediate messages!
  • a possibility to add header fields to HTTP destinations so one can set the Authorization header or a token.

 

Have fun,

Domi

Assigned Tags

      Be the first to leave a comment
      You must be Logged on to comment or reply to a post.