🤖Standup Shuffle Bot for Slack

Standup Shuffle is a custom Slack bot designed to add a fun twist to the traditional standup routine by randomizing the order in which team members share their updates.

Say goodbye to the predictable routine of standup meetings, where team members often follow the same sequence when providing updates. Standup Shuffle ensures that each day brings a fresh and unpredictable order, promoting a collaborative environment where everyone's contributions take center stage.

How to create your own Standup Shuffle Bot yourself using Slack and Bitbucket Pipeline Forms? Let's find out!

Creating the Slack app and obtaining the webhook URL

Create a Slack app on https://api.slack.com/apps, fill in name and choose your workplace of choice. Optionally, provide images, colors, etc. for a better appearance.

On the left sidebar, choose Incoming Webhooks. Create a new webhook, chose the target channel, and save the webhook url with the token in a note.

Creating the shell script

In your repository, where the extension is installed and accessible, create a shell script called standupbot.sh:

#!/bin/bash

# Get the names from the environment variable
names_string=$NAMES

# Split the environment variable string into an array
IFS=',' read -ra names <<< "$names_string"

# Function to shuffle the array randomly
shuffle_names() {
    local i
    for ((i=${#names[@]}-1; i>0; i--)); do
        local j=$((RANDOM % (i+1)))
        local temp=${names[i]}
        names[i]=${names[j]}
        names[j]=$temp
    done
}

# Invoke function to shuffle names
shuffle_names

# Get the message prefix from the environment variable or set a default
message=${MESSAGE_PREFIX:-"Sziasztok! A mai Sync sorrend: "}
# Concatenate the shuffled names
for ((i=0; i<${#names[@]}; i++)); do
    message+=" ${names[i]},"
done

# Remove the trailing comma
message=${message%,}

# Set the webhook URL from the environment variable
webhook_url=$SLACK_WEBHOOK_URL

# Get the joke URL from the environment variable or set it to an empty string if not provided
joke_url=${JOKE_URL:-""}

# Fetch the joke from the URL using curl
joke=$(curl -s "$joke_url")

# Add the joke to the message
message+=". Hoztam egy viccet is: $joke"

escaped_message=$(echo -n $message | jq -Rs .)

echo $escaped_message

# Send the message to Slack
curl -X POST -H 'Content-type: application/json' --data-raw "{\"text\":$escaped_message}" $webhook_url

Adding the script runner to the pipeline config

Create or edit your bitbucket-pipelines.yml file where your script is located:

image: node:18
pipelines:
  custom:
    # ...
    daily-standup:
      - step:
          name: Run Bash Script
          script:
           - apt-get update 
           - apt-get -y install jq
           - bash ./standupbot.sh # Or the name you provided
    # ...

Creating the pipeline-forms.yml

Bitbucket Pipeline Forms uses a file, called pipeline-forms.yml which is the main configuration and template description for your forms. Create the file in your repository root, and paste the following:

fields:
  - &daily-standup-names
    label: Names for Daily Standup
    type: text
    name: NAMES
    mandatory: true
  - &daily-standup-url
    label: Slack Webhook URL
    type: text
    name: SLACK_WEBHOOK_URL
    mandatory: true
  - &daily-standup-message-prefix
    label: Message Prefix
    type: text
    name: MESSAGE_PREFIX
    mandatory: false
forms:
  - name: Daily Standup Shuffle
    fields:
      - *daily-standup-names
      - *daily-standup-url
      - *daily-standup-message-prefix
    pipelines:
      - daily-standup

This config means the following:

  • There is a mandatory text field for the environment variable NAME

  • There is a mandatory text field for the environment variable SLACK_WEBHOOK_URL

  • There is an optional text field for the environment variable MESSAGE_PREFIX

  • There is a form called "Daily Standup Shuffle", which is available for the daily-standup pipeline (which we just defined in the bitbucket-pipelines.yml), using the fields we defined recently (keep an eye on the & and * characters, which are used for YAML anchors).

The names of the fields are used as the environment variable names. Take a look back at the shell script we defined earlier: there are three environment variables used in the script, one of which is "optional" (and has a default value). Those variable names should match the name of the fields you define in the pipeline forms config. You can use the label property to display the purpose of the fields more clearly.

Don't forget to save (commit) the file!

Triggering the pipeline manually

In the repository, click the Pipeline Forms menu item on the left sidebar: this will open the application.

Select the master branch, the latest commit (the first option, it will show the LATEST badge when selected), the daily-standup pipeline and the Daily Standup Order form. If there are more options in one of the checkboxes than it is displayed, you can use the built-in search in the combo boxes.

The form will load, you are free to fill in the values. Once done, try running the pipeline with the environment values you just provided, by clicking the blue Run Pipeline button at the bottom.

The status of the trigger (not the pipeline run itself) will be displayed on the bottom. Green means the pipeline has started successfully.

To verify the result, click the Pipelines menu item in the left sidebar, then click the top item and check the variables, run result, etc.

You should receive a Slack notification if you are following this demo.

To try with different values, just repeat the steps in this section! There is no need to configure anything again!

Triggering the pipeline by a schedule

Scheduling a trigger does not differ significantly from the steps taken previously, you just need to press the Schedule button instead of Run Pipeline.

This will open a dialog for you, in which you can set up your schedule.

Type in a name, and check whether you would like to run this schedule on the latest commit available on the selected branch.

Select the occurrence of the trigger. For our standup shuffle bot, we will use the weekly occurrence. We will select the hour range and weekdays on which the trigger will occur. Select from Monday to Friday!

This means that on every workday between XX:00 and XX:59 at some point, the trigger will occur.

Your selected hour range and weekdays together are converted to a UTC timestamp, which you can preview at the end of the form when everything is filled in.

Click schedule! The result will appear on the right side in the Schedule List menu. Click on it, and verify if everything has been set up correctly. Note that secret variables will be hidden.

Updating a schedule

Mistakes are made, changes happen, colleagues come and go: how can we update the variables or the schedule?

Click the pencil icon in the Actions column. In the dialog, update the fields as you wish!

During an update, field values are updated as raw key-value pairs, meaning that the format will not be verified based on the form - you are able to enter anything you like.

Keep in mind that when editing secret variables, the current value will not be displayed. If you do not wish to update a secret variable, just leave it blank.

After you complete the changes, save the schedule by clicking the Update button. The next scheduled trigger will use the updated values.

If you want to update fundamental settings, such as the branch, commit, pipeline or the form behind the schedule, we recommend that you delete and recreate the whole schedule.

Deactivating or deleting schedules

If you want to temporarily activate or deactivate you scheduled daily standup bot, just use the switch in the Active column (it saves automatically).

If you no longer wish to use your standup bot, click the trash icon and confirm the delete operation.

Last updated