Automating Slack Greetings to Community with Orkes Conductor
Tags: microservices, orchestration, automation, workflow
Published: 2024-04-17 07:36:56

Imagine a situation where you joined a community channel and felt lonely, not knowing where to start—has it ever happened to you? 

What if your community members, too, feel the same about joining your community platforms? It’s a make-or-break moment when it comes to community engagement.

In this blog, we’ll explore how Orkes Conductor, the leading workflow orchestration platform built on the popular open-source Conductor, can help you automate the process of welcoming new community members to your dedicated Slack channel. 

## Creating a Community Welcome Bot

Before beginning with the bot creation process, you need to ensure that:

- You have a Slack workspace.
- You have signed up for [Orkes Playground](https://play.orkes.io/), a free developer sandbox from Orkes, to test Conductor in real-time. We’ll be using Playground to test the welcome bot in this blog. 

So, here’s a quick overview of how our Conductor community welcome bot will work:

1. A webhook event is sent to Orkes Conductor whenever a new member joins the community. 
2. On receiving the event, the application flow begins, and the new member gets a message from the designated person (for example, the Head Of Community) welcoming them to the community with relevant greetings.
3. The workflow waits a few minutes, and a message is sent to help them get started.

And Boom! You’ve automated the welcome greetings to all the newly joining community members. Sounds simple, doesn't it?    

As a result, when your community keeps growing, you don’t have to worry about sending personalized messages to every new member. 

All you need to do is create an application flow in Orkes Conductor, and Conductor automates this process.

## Creating Workflows

Let’s look at the application flow {workflow} now:

![Community welcome workflow in Orkes Conductor](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/3p1xnz4780y4reaqsmzw.png)

[View in Playground](https://play.orkes.io/workflowDef/community-welcome-workflow)

You can get the [JSON file](https://github.com/conductor-sdk/conductor-examples/blob/main/community-welcome-workflow/community-welcome-workflow.json) for the workflow in our GitHub repository.

- The workflow begins with a [switch task](https://orkes.io/content/reference-docs/operators/switch), an operator in Orkes Conductor. In Orkes Conductor, operators are tasks equivalent to common programming language constructs.
- In our example, we have added two switch cases evaluating an input parameter named _switchCaseValue_; one gets executed whenever a new community member joins (the value equals _team_join_). For all other cases, the default case will be executed. This is a good example of how to validate elementary input data from the workflow executor and logically branch to an error management flow.
- The workflow then moves to an [HTTP task](https://orkes.io/content/reference-docs/system-tasks/http-poll), yet another operator in Orkes Conductor. It sends a POST request to the Slack Webhook with the user information. Through this task, a message would be posted to the required channel on new members joining.

```
           "name": "http_task_1",
           "taskReferenceName": "http_task_ref_1",
           "inputParameters": {
             "uri": "https://hooks.slack.com/services/XXXXXX",
             "method": "POST",
             "connectionTimeOut": 3000,
             "readTimeOut": "3000",
             "accept": "application/json",
             "contentType": "application/json",
             "body": {
               "text": "A new user has joined our community slack - ${workflow.input.event.user.profile.display_name}."
             }
           },
           "type": "HTTP",
```

- It is followed by another HTTP task, which is used to welcome the new user to the community.

```
     "name": "http_task_2",
           "taskReferenceName": "http_task_ref_2",
           "inputParameters": {
             "http_request": {
               "uri": "https://slack.com/api/chat.postMessage",
               "method": "POST",
               "connectionTimeOut": 3000,
               "readTimeOut": "3000",
               "accept": "application/json",
               "contentType": "application/json",
               "headers": {
                 "Authorization": "Bearer ${workflow.secrets.slack_welcome_token}"
               },
               "body": {
                 "channel": "${workflow.input.event.user.id}",
                 "text": ":wave: Hi there!  I would like to welcome you to our DevRel community on Slack.  We're thrilled to have you join our vibrant community! :blush: Whether you're here to collaborate, share knowledge, or simply connect with like-minded individuals, you're in the right place. Take a moment to introduce yourself in the #introduce-yourself channel. Share your interests, what brought you here, or anything else you'd like the community to know! ",
                 "as_user": true
               }
             }
           },
           "type": "HTTP",
```

- Then, the workflow pauses for a specific period and sends another message with tips to get started. The wait period can be configured using a [Wait task](https://orkes.io/content/reference-docs/operators/wait). Adding a Wait task can be useful to make the flow less “robotic” and give users a natural perception of things happening behind the scenes.

```
          "name": "wait_for_sometime",
           "taskReferenceName": "wait_for_sometime",
           "inputParameters": {
             "duration": "2 minutes"
           },
           "type": "WAIT",
```

- The final task in the workflow is an HTTP task that sends messages to the user with utility links to help them get started.

## Creating Webhook

New user sign-up information is received as an event within Orkes Conductor through Webhooks. Webhooks are used to trigger workflows.

Therefore, create a Webhook by navigating to **Definitions > Webhook** from the left menu on your Conductor cluster, and set the webhook parameters as shown below:

![Webhook for receiving events](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/3guxqwwcsanu34j65jnz.png)

1. Provide a **_Webhook name_** and choose the **_Source platform_** as Slack. 
2. Under the field “Start workflow when webhook event comes”, choose the workflow we’ve created in the previous step. 
3. When saving the webhook, an unverified URL will be generated. It gets verified when this URL is copied to your Slack app.

You might wonder why we did not add the workflow under the field “Workflow to receive webhook event”. In this case, the workflow must be started only after the webhook event is received, i.e., whenever a new community member joins.

## Creating Slack App

The next step is to create a Slack app.

1.  Navigate to [Slack Apps API](https://api.slack.com/apps) and click **Create an App**.  

![Creating Slack Bot](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/5wbo7gf8xh6ycw0mlf8s.png)

2. Choose the option **From scratch** and provide an app name and the Slack workspace to which the application will be integrated. Click **Create App**.

![Creating Slack Bot - Name & workspace creation](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/xjoqsfzi7n5zz79ts74k.png)

3. Next, activate the incoming webhooks by navigating to **Features > Incoming Webhooks**. Turn on the option **Activate Incoming Webhooks**.

![Activate Incoming Webhooks](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/if1iksa1t3iixtalrllg.png)

4. Then, from **Features > Event Subscriptions**, turn on **Enable Events**.

![Enable Events](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/t9x0fas2dwqlne5tgjou.png)

- Under the field **Request URL**, provide the webhook URL created previously. At this step, the URL becomes verified in your Conductor cluster.
- Under _**Subscribe to bot events**_, click **_Add Bot User Event_** & add _**team_join**_ (remember, this is the value evaluated by our switch in our workflow).
- Save the changes.

5. Navigate to **Features > App Home**, and under the Messages tab, enable the option _Allow users to send slash commands and messages from the messages tab_.

![messages-tab-community.png](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/79c7gn2sjpwdwljv8rd9.png)

6. Then, you need to enable permissions for your Slack app by navigating to **Features > OAuth & Permissions**.

- Under **Scopes > Bot Token Scopes**, add the following permissions to those added by default.
- channels:read
- chat:write
- chat:write.public
- groups:history
- groups:read
- im:history
- mpim:history
- mpim:read

- Under **Scopes > User Token Scopes**, add the following permissions.
- channels:history
- channels:read
- chat:write
- groups:history
- groups:read
- im:history
- mpim:read
- users:read

### Install App to Slack Workspace

Now that you have created your Slack app let’s install the app:

For this:

1. Navigate to **Settings > Install App**, and click **Install to Workspace**.
2. Under “_Community Welcome App for Slack requires a channel to post to as an app_”, choose the channel you want to notify when a member joins the workspace.

![Installing Slack App to Workspace](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/hle6edvmn2cc9a4wyaq0.png)

Once the app is installed, OAuth tokens will be generated. 

![OAuth tokens & webhook URL](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/xfhcuvnr45jh1mxqor5l.png)

To try this workflow in your Slack workspace, you need to make some changes to the following configurations in the sample workflow.

1. [Create a secret in Orkes Conductor](https://orkes.io/content/developer-guides/secrets-in-conductor) from the left menu. 
- Provide a name for your secret and save the **User OAuth token** generated (see above image) when the app was installed in your workspace. In this example, we have saved the secret as **slack_welcome_token** and used it in the workflow definition, as shown below:

```
"headers": {
                 "Authorization": "Bearer ${workflow.secrets.slack_welcome_token}"
               },
```

Note: Ensure you replace the **slack_welcome_token** in your workflow definition with the secret name you created. 

2. From your Slack APIs, copy the Webhook URL (refer to the above image) and replace the POST URL in the first HTTP task as shown below:

![Updating Slack URL in HTTP post request](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/uocvmqmdb02oxfs3v9ef.png)

3. Now save the workflow definition.

## Executing Community Bot App

Whenever a person joins your Slack community, the webhook event will be received, and the workflow will be triggered. 

![Welcome workflow triggered when a user joined](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/f9uvp1xvu8pbaq3lx9fq.png)

### From the newly-joined Community User perspective: 

The user will receive a welcome message from the Workspace admin (the one who created the Slack app). 

You can customize the message according to your needs. These messages are sent using the HTTP task. 

Here’s the welcome message received by the user. 

![Initial welcome message received by the community user](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/ds1epcaobx0b9r8wjfko.png)

And it can be changed as needed by updating the “text”  in **http_task_2**.

```
               "body": {
                 "channel": "${workflow.input.event.user.id}",
                 "text": ":wave: Hi there!  I would like to welcome you to our DevRel community on Slack.  We're thrilled to have you join our vibrant community! :blush: Whether you're here to collaborate, share knowledge, or simply connect with like-minded individuals, you're in the right place. Take a moment to introduce yourself in the #introduce-yourself channel. Share your interests, what brought you here, or anything else you'd like the community to know! ",
                 "as_user": true
               }
```

After this, we have added a wait period of 2 minutes using the wait task. So, the user will receive the second message after the wait period like this:

![Second welcome message received by the user to get started](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/rp6qmfxsm37pyewvnpdr.png)

It can be updated as needed by changing the “text” in **http_task_3**.

```
"body": {
                 "channel": "${workflow.input.event.user.id}",
                 "text": "Welcome aboard! Here's a link to get started: [https://orkes.io/content/getting-started/first-workflow-application]. These will help you get the most out of your experience here. Feel free to ping us for any help. ",
                 "as_user": true
               }
```

### From the Slack Admin perspective: 

Once a new community user has joined, a message will be posted on the **_slack-community-join-updates_** channel (which is the channel we chose to install the application on). 

![Slack channel where user joining updates are posted by the Bot](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/huqfz9lc3aid6pzxbala.png)

The message can be configured via the **http_task_1,** where you can update the “text” like this:

```
"body": {
               "text": "A new user has joined our community slack - ${workflow.input.event.user.profile.display_name}."
             }
```

This ensures that the admins are notified when someone joins. 

Tip: Consider posting these updates in a private channel, as they contain details other community members may not need to know.

Now, you can check on Orkes Conductor to see that the workflow has been completed successfully.

![Completed workflow](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/inxzqm1bytuyariu7ydd.png)

**_“That’s how we welcome new members to our community Slack channel at Orkes. [Join and witness the magic for yourself now.](https://join.slack.com/t/orkes-conductor/shared_invite/zt-xyxqyseb-YZ3hwwAgHJH97bsrYRnSZg)”_**

This is a simple example with just a few tasks. Of course, you can customize this app to fit your needs, adding additional tasks and changing the flow as per your requirements. 

Here’s a video guide summarizing the example we’ve discussed:

{% embed https://youtu.be/OpTFPeeCjGA?si=PEGE8Un3OaQY6nw4 %}

## Summing Up

We have used our own platform for welcoming our community members & many other use cases like:

- [Running our daily engineering standup](https://orkes.io/blog/create-standup-bot-using-conductor-slack-integration/)
- [Orchestrating infrastructure updates](https://orkes.io/blog/orchestrating-infrastructure-upgrades-with-conductor/)
- [Automating Wildcard Certificate Management Across Multiple Kubernetes Clusters  ](https://orkes.io/blog/wildcard-certificate-management-across-multiple-kubernetes-clusters-with-orkes-conductor/)

If you have similar use cases that need to be automated within your organizations, request a free trial with [Orkes Cloud](https://orkes.io/orkes-cloud-free-trial?utm_campaign=community-welcome-blog&utm_source=devto-blog&utm_medium=web).

Meanwhile, don’t forget to give us a 🌟on our [Conductor OSS repo](https://github.com/conductor-oss/conductor)!