This article is the fourth in a series exploring fun, straightforward ways you can control workflows using Camunda Cloud — have a read of the others for some background if you’d like to see Camunda Cloud in action with Restzeebe, without a line of code:


Do you use Slack? How about adding a level of automation to this widely used collaboration tool, that is making email obsolete in many organizations?

Let’s say you already widely use Slack in your company and want to receive an active notification when a new user has registered to your service? 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 😉

This use case sits within a wider portfolio of useful integrations that can be applied in many places, and it’s a really useful one to have in your toolkit.

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.

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

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`)
    }
  }
}

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

The process gets more and more exciting when you integrate this service task into a larger context.

Happy Slacking! 😉


This blog was originally published on dev.to. If you like this great tutorial, follow Adam on TwitterLinkedIn or GitHub 

< Back
  • Countdown to the Camunda Community Summit

    Introducing our speaker line-up and the Camunda Community Awards  Camunda has always been focused on creating an excellent experience for developers everywhere who are trying to automate processes. From our days as a small process automation consulting firm to the powerful products used by hundreds around the globe, our engineering mindset and commitment to our community has always been at the heart of what we do. Which is why we’re excited to share the final speaker line-up for our first ever Camunda Community Summit, taking place April 27-28, 2021.  Highlights will include presentations from: Adrianna Tan, San Francisco Digital Services, will explore Automation in Local Government Digital Services in a Post-Pandemic World.  Markus Stahl, Deutsche Post Adress GmbH presenting: Open...

    Read more
  • Six Tips for building a global Meetup...

    Building and nurturing a community of users is vital to any tech organization’s success. If you want to get the word out about your product and build meaningful relationships with your user community, you’ll want to empower your community contributors to lead successful meetup groups. In this blog post, I’ll share some of the learnings from building up a support program for our global Camunda meetup organizers over the past three years.  I’m the Community Manager at Camunda and a people connector at heart. One of my greatest passions is building meaningful relationships that serve global communities and empower individuals. I strongly believe that exchanging ideas and learning about the experiences of others can be a great source of knowledge...

    Read more
  • Contributing to the Camunda Modeler and getting...

    A report from a true fan. Watching sports is a little like using Open Source Software. I know that is a bit of a  stretch, but if you keep reading you will see that both need contribution from “hobby leagues”. By watching your favorite sports team you (maybe unintentionally) tell sports clubs and TV stations that you are interested in their offerings. Maybe at one point you decide to play the sport yourself. By starting to play, you begin contributing to that community. You may not ever be a professional athlete, but overall you start to influence the sport you’re participating in at a small level.  I am a big user of bpmn.io. I guess if you work at Camunda...

    Read more