Duty Bot Updater is an interactive Slack component that lets any Slack user update the schedule posted by Duty Bot.
- User clicks "More actions" for a message
- User clicks "Update Duty Member"
- User selects another Slack user
- Orginal message is updated
sequenceDiagram
actor U as User
participant S as Slack
participant A as App
U ->> S: User clicks "Update Duty Member"
S ->> A: Slack requests the payload view
A ->> S: App calls views.open with the modal instructions
S ->> U: Slack displays modal to user
U ->> S: User submits modal with the selected RA
S ->>+ A: Slack sends modal submission payload
A -->> S: App calls chat.update to update the message
A -->> S: App calls chat.postMessage to log the change
A ->>- S: App returns 200 ok
S ->> U: Slack closes the modal
- Create an app at https://api.slack.com/apps
- Navigate to the OAuth & Permissions page and add the following bot token scopes:
commands
(required for Actions)chat:write
(required to send messages as a bot user)im:write
(required to open a DM channel between your bot and a user)
- Click 'Save Changes' and install the app
-
Get the code
git clone git@github.com:ChaseC99/duty-bot-updater.git
npm install
-
Set the following environment variables to
.env
with your API credentials (see.env.sample
):SLACK_ACCESS_TOKEN
: Your app's bot token,xoxb-
token (available on the Install App page, after you install the app to a workspace once.)SLACK_SIGNING_SECRET
: Your app's Signing Secret (available on the Basic Information page)to a workspace)LOG_CHANNEL
: The channel id for where your log messages will go.
-
If you're running the app locally:
- Start the app (
npm start
) - In another window, start ngrok on the same port as your webserver (
ngrok http 3000
)
- Start the app (
- Go back to the app settings and click on Interactive Components.
- Click "Enable Interactive Components" button:
- Request URL: Your ngrok URL +
/updateDutyMessage
in the end (e.g.https://example.ngrok.io/updateDutyMessage
) - Under Actions, click "Create New Action" button
- Action Name:
Update Duty Member
- Description:
Updates the message to display the correct Duty Member
- Callback ID:
update_duty_member
- Action Name:
- Request URL: Your ngrok URL +
- Click Save
I could have just used serverless
to create these resources and deploy but I wanted to get the experience of setting up and deploying my code manually.
- Create a new Lambda function with a Node runtime environment
- You may need to extend the timeout to 15 seconds
- Add an API Gateway trigger to the lambda function
- Update your Slack app's interactive component request url to be the url from the API Gateway.
- Run
source build_deployment.sh
- Upload the new
deployment-package.zip
file to the Lambda function