Slack with Superface
This demo repository showcases the following integrations with Slack:
Setup
- Run
npm install
- Copy
.env.example
to.env
:cp .env.example .env
- Setup HTTPS on localhost (see below)
- Create a Slack app and set credentials in
.env
file (see below) - Get access token (see below)
Setup HTTPS on localhost
Slack requires all callback URLs to be HTTPS, including to localhost
.
You can use mkcert to generate a self-signed certificate:
mkcert -install
mkcert localhost
This will create localhost.pem
and localhost-key.pem
files in the current directory. Set the path to these files in .env
:
HTTPS_KEY_PATH=localhost-key.pem
HTTPS_CERT_PATH=localhost.pem
Create Slack app
⚠ If possible, use a dedicated testing workspace for experiments.
-
Visit https://api.slack.com/apps and create a new app
-
Select "From an app manifest" and use the following app manifest:
display_information: name: Superface Test App features: bot_user: display_name: Superface Test App always_online: false oauth_config: redirect_urls: - https://localhost:3000/auth/slack/callback scopes: bot: - channels:read - chat:write - chat:write.public settings: org_deploy_enabled: false socket_mode_enabled: false token_rotation_enabled: false
-
From Basic Information page, copy Client ID and Client Secret to
.env
:SLACK_CLIENT_ID=11111111.22222222 SLACK_CLIENT_SECRET=aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
Get access token
- Run
npm start
- Visit
https://localhost:3000
- Authorize the application into your workspace
- The
tokens.json
file should be created
Alternatively run get-tokens.js
script and paste the generated JSON manually.
Run demo scripts
- List public channels in the workspace:
node list-channels.js
- Send a message to a channel:
node send-message.js <channel ID> <message>
, e.g.:node send-message.js C12345678 "Hello world"