This application demopnstrates the implementation of Slack app to play Janken game (paper-scissors-rock).
- Runtime: Node.js
- Framework: Bolt - Slack's official chat app framework
- Database: Firestore
- Infrastructure: Google App Engine
- CI/CD: GitHub Actions
- Slack app is created
- GCP project is created
OAuth & Permissions > Scopes > Bot Token Scopes
Add the following scopes.
chat:write
chat:write.public
commands
$ cp .env.sample .env
$ vi .env
Set the following variables.
Key | Value |
---|---|
SLACK_SIGNING_SECRET | Slack app web console > Basic Information > App Credentials > Signing Secret |
SLACK_BOT_TOKEN | Slack app web console > OAuth & Permissions > Bot User OAuth Access Token |
Obtain a service account key from the GCP console.
IAM & Admin > Service Accounts > Select project > Service account of
firebase-adminsdk
> Actions > Create key
Rename the file to firestore_service_account_key.json
and place it in the credentials
directory.
$ npm install
$ npm run dev
You ngrok URL will be output.
Slash Commands > Create New Command
- Command:
/janken_dev
- Request URL: (Your ngrok URL)/slack/events
- Escape channels, users, and links sent to your app: On
Interactivity & Shortcuts > Interactivity > Request URL
- URL: (Your ngrok URL)/slack/events
If you use the OAuth flow to install your app, the following setup is needed in addition to above.
Add the following variables to .env file.
Key | Value |
---|---|
SLACK_OAUTH_ENABLED | 1 |
SLACK_CLIENT_ID | Slack app web console > Basic Information > App Credentials > Client ID |
SLACK_CLIENT_SECRET | Slack app web console > Basic Information > App Credentials > Client Secret |
SLACK_STATE_SECRET | This can be a random string. This is used in the OAuth flow. |
ENCRYPTION_KEY | This can be a random string of 32 Bytes. This is used in encrypt/decrypt tokens. |
BUFFER_KEY | This can be a random string of 16 Bytes. This is used in encrypt/decrypt tokens. |
OAuth & Permissions > Redirect URLs > Add New Redirect URL
URL: (Your ngrok URL)/slack/oauth_redirect