Started: Aug 2020
Ended:
Single repository for tester apps to breakdown Slack API features
- To have a way to quickly and easily test each of Slack's API features independently.
- Clone repository and run
npm install
- Create a Slack app see here for each specific feature configuration
npm run [/feature]
(each feature corrosponds to a folder name)
- Node
- NPM
- Nodemon (automatically restarts the node application when a file changes. keep in mind to do a full restart when changing enviornment variables! etc)
- NGROK (creates a public URL and tunnels it to your local host see resources
Follow the appropriate configuration guide for the feature you want to test. A Slack app can be created from here: https://api.slack.com/apps?new_app=1
Note: creating a Slack app for each feature makes it easier to debug independently.
- On your Slack App configuration page, head to the Interactivity & Shortcuts tab and toggle Interactivity. Add the public request URL of your server with an
/slack/events
end point:yourserver/slack/events
- Underneath click Create New Shortcut choosing Global > Next > Fill out the details (the name and description will appear in Slack and the Callback ID isn't used within this app but is mandatory).
- Head to the Install App tab and install the app.
- In the project folder create a
.env
file within the/modals
directory. Add aBOT_TOKEN
variable and set it to the Bot User OAuth Acccess Token from the "Install App" tab.
- In Slack head to any channel and click the lightning bolt next to the input
- Search for the name (added step2 in the Configuration steps above) and trigger the modal view to open (which is found here
/modals/modal_views/view1.json
)
- Start the app by running
npm run events
- On your Slack App configuration page, head to the Event Subscriptions and toggle Enable Events. Add the public request URL of your server with an
/slack/events
end point:yourserver/slack/events
(this will only verify if the app is running correctly) - Underneath click Subscribe to bot events and click Add Bot User Event choosing the
app_mention
andapp_home_opened
events - Head to the Install App tab and install the app.
- In the project create a
.env
file within the/events
directory and add aBOT_TOKEN
variable setting it to the Bot User OAuth Acccess Token from the Install App tab in step4 above. - To add enviornment variables, the app needs to be restarted:
⌃c
(control c), thennpm run events
- In Slack invite the bot to a channel(enter
/invite @[your-appname]
) - Mention the bot
@[your-appname]
- you should see the event hit your end point - Head to the bot direct message and go to the Home tab, you should see the view in:
/events/views/home.json
)
Hosted here: https://glitch.com/edit/#!/false-peridot-band
- On your Slack App configuration page, head to the Socket Mode tab and toggle Enable Socket Mode
- Give the app-level token a name of SOCKET_MODE (or anything you like) and click Generate
- Note the token that is generated (you can find this later under the Basic Information tab > App-Level Tokens)
- Click on the Event Subscriptions tab and toggle Enable Events, click Save Changes (down the bottom right)
- Underneath click Subscribe to bot events and click Add Bot User Event choosing the
app_mention
event - Click on the Install App tab and click through the Install to Workspace options
- In the project code, create a
.env
file and add theSOCKET_MODE
variable:SOCKET_MODE=xapp-...
from step 3.
- https://api.slack.com/scopes/connections:write (automatically added when setting up Socket Mode)
- https://api.slack.com/scopes/app_mentions:read
- Start the app by running
npm run socketmode
- In Slack invite the bot to a channel(enter
/invite @[your-appname]
) - Mention the bot
@[your-appname]
- you should see the event come through on the socket displayed in your terminal.
This tester app uploads a file and then unfurls it when someone enters the corrosponding unfurl URL (https://YOURUNFURLDOMAIN.com/image123
)
- Head to
unfurling/manifest.json
- Change
features.unfurl_domains
to your domain that your app will unfurl for - Change
settings.event_subscriptions.request_url
to the public server URL hosting your app - Head to https://api.slack.com/apps/new and create an app entering the JSON from
unfurling/manifest.json
. - Install the app by clicking on the Install App tab on the left.
- Back in the project code, create a
.env
file and add aBOT_TOKEN
variable for the token from step 5. - Add
UNFURL_DOMAIN
variable for your domain name
The .env
file should look like this with appropriate replacements:
#.env
BOT_TOKEN=xoxb-...
UNFURL_DOMAIN=https://YOURUNFURLDOMAIN.com
- https://api.slack.com/scopes/links:read
- https://api.slack.com/scopes/links:write
- https://api.slack.com/scopes/remote_files:write
- Run
npm run unfurling
- In Slack invite the bot to a channel(enter
/invite @breakdown-unfurling
) - Enter
https://YOURUNFURLDOMAIN.com/image123
Note: image123
is hardcoded in unfurling/controllers/unfurling-controller.js
)