This article was originally published on bmf-tech.com.
Overview
Implement a Slash Command for a Slack App using Cloud Functions.
Here is the boilerplate I created this time.
go-slack-app-on-cloud-functions-boilerplate
There are various ways to create a Slack App with Slash Commands, but I tried using CloudFront Functions because it is cheap, easy, and serverless.
Prerequisites
- Google Cloud Platform is available
- The gcloud command is set up
- The gcloud command must be available to deploy the application
- Cloud Build API is enabled
- It is necessary to build the function to deploy functions to Cloud Functions.
Create a Function with Cloud Functions
Create a function in the Cloud Functions console.
Select HTTP as the trigger type, allow unauthenticated invocation, and check HTTPS required.
After deploying the function, note the trigger URL listed under the function details > Trigger in Cloud Functions, as it will be used later.
Prepare the Slack App
Create a Slack App
At Create an app, click From scratch.
Enter the App Name.
Select a workspace under Pick a workspace to develop your app in: and click Create App.
Configure Slash Command
In the settings screen (e.g., https://api.slack.com/app/****), select Slash Commands.
Click Create New Command and enter Command, Short Description, Usage Hint, and Escape channels, users, and links sent to your app as desired.
Enter the trigger URL noted earlier as the Request URL.
The trigger URL is in the format https://REGION-NAME-PROJECT-ID.cloudfunctions.net/FUNCTION_NAME.
Once entered, click Save.
Install the Slack App
In the settings screen (e.g., https://api.slack.com/apps/****), click Install App.
Click Install to workspace to install the app in any workspace.
Obtain Signing Secret
In the settings screen (e.g., https://api.slack.com/apps/****), click Basic Information.
Under App Credentials, there is a Signing Secret, so note the value.
Implement the Function
Implement the function to be deployed to Cloud Functions.
There are some tricky parts (like doing go mod vendor), but the implementation details are omitted.
Refer to the source code below.
go-slack-app-on-cloud-functions-boilerplate
Deploy the Function
Follow the README of go-slack-app-on-cloud-functions-boilerplate to prepare environment variables and deploy.
Verify Operation
Try using the created Slash Command in Slack.
ex.
/hello Bob
Thoughts
It would be nice to be able to code the part of creating a Slack App.
Additional Notes
I wanted to create a Slack Command for attendance management at work, so I created akashi-slack-slash-command based on go-slack-app-on-cloud-functions-boilerplate.
In this implementation, storage is set to Spreadsheet, but when using Google Workspace, there is a management issue where the sharing settings of the Spreadsheet cannot be flexibly adjusted due to permissions, so at work, we replaced the storage from Spreadsheet to Cloud Storage and adjusted the implementation.
If an organization uses Akashi for attendance management and Slack as a chat tool, it should be a Slack Command that can be easily used.
The operational cost is not significant, but scalability might be a bit questionable.
It should probably work fine unless the organization exceeds several thousand people. Probably.






Top comments (0)