← BackSend messages to Slack from Camunda Cloudu11g.com
2/13/2021

Send messages to Slack from Camunda Cloud

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 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 :) 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.

Home
Projects
Newsletter
Blog
Me
Philosophy
Gen Art
Work
Setup
CV
Machine
Dynamic Pong: Territory Conquest Meets Classic Physics
Introducing Camunda Directory
Getting Started with AIME Directory Collections in 5 Minutes
How to use a proxy in a nodejs environment
Introducing weeklyfoo
Create your own epaper calendar with Canvas
Codespaces can become a game changer
Cloudflare pages direct upload with stable preview urls
Building your own Twitter Thread Generator
300 APIs integrated in minutes, not days
Be an orchestration hero
Cut a few braids - new NPM package
ETHme - your chic web3 identity
Automatically update data and commit
Aren't the standard actions going too far for you? Write your own one!
Screenshots - a perfect task to automate!
Send messages to Slack from Camunda Cloud
5 Steps how to track your Team's Mood
Automate your manual tasks with Camunda and Trello!
Go beyond the basics
Is there an alternative to spaghetti?
Play with node-canvas and build something useful
How do I implement a command line tool?
Aime Directory
Boring Dev Tools
Camunda Directory
Data Democracy
Dev Pulse
Dynamic Pong
Lifosy
Art u11g
dapphuntr
DiyPunks
flethy
Maker Oracles
SwagTime
EthME
fcheat
Find the next victim
Generative Arts
MakerDAO Delegates
SkunkWorks NFT
Trees of Life NFT
zukuNFT
RestZeebe
Websiteshot
Zeebetron: How to Manage Multiple Zeebe Profiles with Electron
dot calendar
Sharu
Switch Interface (theme)
LINKEDIN
X
GITHUB