DEV Community

Cover image for Send messages to Slack from Camunda Cloud
Adam
Adam

Posted on • Edited on • Originally published at urbanisierung.dev

1

Send messages to Slack from Camunda Cloud

This is not a use case that makes sense on its own. But it belongs, in my view, to the portfolio of useful integrations that are quite generic and can be applied in many places. Slack is a widely used collaboration tool that is making email obsolete in many organizations.

Too unspecific? Okay, let me illustrate with an example. You already widely use Slack in your company and want to receive an active notification when a new user has registered to your service. That means you can create a new channel just for that purpose and all Slack users who are interested can join the channel.

If you already have an onboarding process running you can simply add a new service task with the Slack worker and that's it ;)

What is needed?

Since we want to integrate with Slack you need a Slack Workspace. Navigate to your Slack Apps and create a new Slack app or use an existing one.

Alt Text

Enable Incoming Webhooks and add a new webhook to a channel.

Alt Text

Implement Worker

The next step is to have a worker that sends messages to this Slack channel via the webhook that has been set up.

import { IncomingWebhook } from '@slack/webhook'
import { ZeebeController } from '../zeebe.controller'
const SLACK_WEBHOOK_BASE = 'https://hooks.slack.com/services'
export class SlackWorkerController {
private webhook: IncomingWebhook | null = null
constructor(private zeebeController: ZeebeController) {}
public createWorker(taskType: string) {
this.zeebeController.getZeebeClient().createWorker({
taskType,
taskHandler: async (job: any, complete: any, worker: any) => {
const webhookid = job.customHeaders.webhookid
const message = job.customHeaders.message
const webhookurl = `${SLACK_WEBHOOK_BASE}/${webhookid}`
this.webhook = new IncomingWebhook(webhookurl)
try {
await this.send(message)
complete.success()
} catch (error) {
complete.failure('Failed to send slack message')
}
},
})
}
private async send(message: string) {
const slackMessage = {
text: `🚀 ${message} 🚀`,
mrkdwn: true,
attachments: [
{
title: `Greetings from Rest Zeebe!`,
},
],
}
if (this.webhook) {
await this.webhook.send(slackMessage)
} else {
throw new Error(`Failed to initialize Slack Webhook`)
}
}
}
view raw slack.worker.ts hosted with ❤ by GitHub

The worker uses the official Slack Node Client which makes integration a breeze. The parameters set are the webhookId and the message. This allows the worker to be used in different places with different webhooks. The message could alternatively come from the process context, but that depends on how you want to use the service task.

A small process with the Slack Task

Alt Text

The process is pretty unspectacular. It gets exciting when you integrate this service task into a larger context.

Happy Slacking! ;)

I'm quite curious if and how you guys use Slack for active notifications from outside :)

Alt Text


Let me know if the article was helpful! And if you like the content follow me on Twitter, LinkedIn or GitHub :)


Header Photo by Jon Tyson on Unsplash

Last Photo by Joan Gamell on Unsplash

Image of Timescale

🚀 pgai Vectorizer: SQLAlchemy and LiteLLM Make Vector Search Simple

We built pgai Vectorizer to simplify embedding management for AI applications—without needing a separate database or complex infrastructure. Since launch, developers have created over 3,000 vectorizers on Timescale Cloud, with many more self-hosted.

Read more →

Top comments (1)

Collapse
 
jaynebackus profile image
JayneBackus • Edited

How to send messages from Camunda to Slack? Cloud will have no objection to posting too many test messages! Love spell with hair

A Workflow Copilot. Tailored to You.

Pieces.app image

Our desktop app, with its intelligent copilot, streamlines coding by generating snippets, extracting code from screenshots, and accelerating problem-solving.

Read the docs