Skip to main content

Example

What you'll build​

Build a WSO2 Integrator automation that posts a message to a Slack channel using the Slack connector. The integration connects to your Slack workspace using an OAuth token and sends a text message to a specified channel.

Operations used:

  • post : Sends a message to a Slack channel with a specified payload.

Architecture​

Prerequisites​

  • A Slack OAuth token (see the Setup Guide)
  • A Slack workspace with a channel to post messages to

Setting up the Slack integration​

New to WSO2 Integrator? Follow the Create a New Integration guide to set up your integration first, then return here to add the connector.

Adding the Slack connector​

Step 1: Open the connector palette​

In the WSO2 Integrator sidebar, hover over Connections to reveal the Add Connection button. Select it to open the connector palette.

Slack connector palette open with search field before any selectionSlack connector palette open with search field before any selection

In the search box, enter slack to filter connectors, then select ballerinax/slack from the results to open the Add Connection form.

Configuring the Slack connection​

Step 2: Fill in the connection parameters​

In the connection configuration form, bind each field to a configurable variable:

  • connectionName : Enter slackClient as the connection name
  • Config : Switch to Expression mode and enter { auth: { token: slackAuthToken } }, where slackAuthToken is a configurable variable of type string
Slack connection form fully filled with all parameters before savingSlack connection form fully filled with all parameters before saving

Step 3: Save the connection​

Select Save to create the connection. The slackClient connection node appears on the canvas and under Connections in the sidebar.

Slack Connections panel showing slackClient entry after savingSlack Connections panel showing slackClient entry after saving

Step 4: Set actual values for your configurables​

In the left panel, select Configurations. Set a value for each configurable listed below:

  • slackAuthToken (string) : Your Slack OAuth token from the Setup Guide

Configuring the Slack post operation​

Step 5: Add an automation entry point​

In the WSO2 Integrator sidebar, hover over Entry Points to reveal the Add Entry Point button. Select it to open the artifact type selector, then select Automation. Accept the default settings and select Create.

The automation flow opens in the canvas, showing Start, a placeholder node, and Error Handler.

Step 6: Select and configure the post operation​

Select the + button between the Start and Error Handler nodes to open the node selection panel. Under Connections, select slackClient to expand its available operations.

Slack connection node expanded showing all available operations before selectionSlack connection node expanded showing all available operations before selection

Select post from the list to open the operation configuration form, then fill in the fields:

  • Payload : A record with the channel to post to and the message text, for example {channel: "general", text: "Hello from WSO2 Integrator!"}
  • result : The variable name to store the response (default slackChatpostmessageresponse)
Slack post operation configuration filled with all valuesSlack post operation configuration filled with all values

Select Save to add the step to the flow.

Completed Slack automation flowCompleted Slack automation flow

Try it yourself​

Try this sample in WSO2 Integration Platform.

Deploy to Devant

View source on GitHub

More code examples​

The Slack connector provides practical examples illustrating usage in various scenarios. Explore these examples, covering the following use cases:

  1. Automated Summary Report - This use case demonstrates how the Slack API can be utilized to generate a summarized report of daily stand-up chats in the general channel.

  2. Survey Feedback Analysis - This use case demonstrates how the Slack API can be utilized to perform a company-wide survey by creating a dedicated channel to receive and track feedback replies.