How to create and deploy a Slackbot on Google Cloud Platform in less than 5 minutes

19 Mar, 2023
Xebia Background Header Wave

In this blog I will show you how to create and deploy a Slackbot on Google Cloud Platform in less than 5 minutes using copier template. To write a bot for Slack is not too difficult. With a few lines of code, you can create a program which will respond to slack commands and mentions. But that is the easy part: you also need to configure the application in Slack, deploy it so that is available 7×24, write unit tests and create CI/CD deployment pipelines and more. This copier template has it all!

  • it creates the source code for your slackbot.
  • it provides the Terraform templates for the infrastructure, the application and the CI/CD pipeline.
  • it provides a CI/CD pipeline using Google CloudBuild to build and deploy the application and infrastructure changes.

This means you can start interacting with your slackbot and iteratively improve the implementation until you have the perfect bot.

deploy a slackbot to Google Cloud Platform

To create and deploy your slackbot, you need to:

  1. generate the source directory
  2. create the application in Slack
  3. install the application in the workspace
  4. obtain the application token
  5. obtain the signing secret
  6. obtain the bot user OAuth token
  7. deploy the slackbot
  8. deploy the tokens and secrets
  9. run the CI/CD pipeline

The following sections provide a detailed explanation of each step.

generate the source directory

Let’s say you want to create a slackbot which generates images using Dall-e. To generate the source directory, type:

$ pip install copier
$ copier /tmp/dali
> the human readable name of your slackbot
   Salvador Dali
> a short description of the Slackbot
   generates images on request
> the name of the package
> the slackbot command prefix
> Your full name?
   Mark van Holsteijn
> Your email address?
> the google project to deploy to
> primary region to deploy the slackbot to
> the replica region for slackbot artifacts
> the artifact repository location to deploy the image to
> name of the terraform state bucket

Now the source code is ready in /tmp/dali. The contents of that directory looks like this:

├── src                                     # bootstrap implementation
│   └── salvador_dali_slackbot
│       ├──
│       ├──
│       ├──
│       ├──
│       └── manifest.yaml
├── tests                                   # skaffold tests for bot functions
│   ├──
│   └──
├── terraform                               # deployment definitions
│   ├──
│   ├──
│   ├── user-data.yaml
│   ├──
│   └──
│   ├──
├── cloudbuild                              # CI/CD pipeline definitions
│   ├── build.yaml
│   └── deploy.yaml
├── secrets 
├── Dockerfile
├── Makefile
├── Pipfile
├── pyproject.toml
├── setup.cfg
├── tox.ini

As you can see everything you need to build, maintain and deploy a slackbot is there! Next, you need to create the application in Slack.

Create the application in Slack

To create the slackbot in Slack, you can use the application manifest manifest.yaml found in the generated source directory. Copy the contents and goto and click on "create app from manifest". slack create new app from manifest

your next step is to install the application in the slack workspace.

Install the application in the workspace

After you created the application, you can install it in your workspace. It is easy: just click the button and follow the flow.

slack install application

Once the application is installed, you need to obtain the application token, signing secret and bot token.

Obtain the application token

After you install the application, scroll down the screen and generate an application token with the scope connections:write. slack generate app-token Copy the generated app token into the file secrets/app-token. app token generated This token will put into a Google secret manager secret later. First you need to get the signing secret and bot token.

Obtain the application signing secret

To obtain the application signing secret, Navigate to Application Basic information, and copy the signing secret into the file secrets/signing-secret. signing secret This secret will put into a Google secret manager secret later. The bot token is the last secret we need to get, before we can deploy the bot.

Obtain the bot user OAuth token

To obtain the bot user OAuth token, navigate to OAuth and permissions and copy the token into the file secrets/bot-token.signing secret

Now everything is done to deploy the Slackbot using Terraform

deploy the slackbot

Before we can deploy the slackbot to Google Cloud Platform, you need to enable the used services and create the Terraform storage bucket. Type:

$ make enable-services 
$ make state-bucket

Now you are ready to let Terraform do it’s magic. Type:

$ cd terraform
$ terraform init
$ terraform apply

This creates everything you need, but the bot will not yet run. The tokens and secrets needs to be made available as Google secrets.

deploy the tokens and secrets

To deploy the tokens and secrets of the slackbot into the respective Google secrets, type:

$ make configure-secrets

run the CI/CD pipeline

Now deploy your changes to the git repository. This will trigger a build of the container image and a deployment of the newly created image using Google CloudBuild.

$ git push

Check the Google CloudBuild logs Once the build and deploy complete your bot is ready to run! You can now chat with your bot and start developing the functionality.


This copier template provides everything you need to quickly build, deploy and maintain a Slackbot on Google Cloud Platform. If you have any questions, problems or feedback feel free to contact me. You can also directly add issues on Github

Photo by Stephen Phillips – on Unsplash

Mark van Holsteijn
Mark van Holsteijn is a senior software systems architect at Xebia Cloud-native solutions. He is passionate about removing waste in the software delivery process and keeping things clear and simple.

Get in touch with us to learn more about the subject and related solutions

Explore related posts