Node app to listen to slack channel for requests for accounts on demo.dev.medcimobile.org:
- Person submits form on contact page requesting a demo account
- A Slack message is sent in #cht-demo-setup Slack channel from Squarespace through Zapier
- This repository's bot runs on an EC2 instance (Medic's Watchdog server, a good place to run Docker stuffs), that listens to specific Slack messages or slash commands and creates a demo account in demo-cht.dev.medicmobile.org.
- This same bot sends an email to the person who submitted the form with their credentials for their demo account using an SMTP provider
This is needed for both prod and dev. Consider setting up two Slack apps so you can easily test dev by switching out SLACK_SIGNING_SECRET, SLACK_APP_TOKEN and SLACK_BOT_TOKEN and having each app point to a different channel in slack.
Follow the Slack Bolt docs for creating an app. After you create the app, add it your channel by going to the app and clicking "Add BOT-NAME-HERE to a channel". I could not get it to work by going to the channel and adding the app 🤷
Be sure it has the following perms:
- chat:write
- channels:history
- groups:history
- users:read
As well, be sure to enable socket for the app:
- go to the Slack API Page
- click on your app
- go to "Socket Mode"
- make sure "Enable Socket Mode" is enabled
- clone this repo:
git clone https://github.com/medic/demo-account-slack-bot.git - ensure you have node 22
- cd into the repo
- copy
env.exampleto.envand populate secrets - using demo secrets from 1pass - install dependencies
npm ci - run it
npm run start
Make sure .env file has correct values and run test script. For example to email [email protected] (but use your email!):
node --env-file=.env smtp-test.js [email protected]You should get back:
Message sent: <[email protected]>And an email should be sent with the subject showing which email provider was used:
SUBJECT: SMTP Demo Test Email (email-smtp.eu-west-2.amazonaws.com)
FROM: The Community Healthtoolkit
DATE: 12:11 PM (4 minutes ago)
BODY:
Test email
Good jobTo ensure the docker image gets rebuilt when new code is released, be sure to update the image value in the compose.yaml file. So if you were on version 1.0 and released a new version, you would change the line to be 1.1 like so:
image: medic-demo-account-slack-bot:1.1- clone the repo:
git clone https://github.com/medic/demo-account-slack-bot.git - copy
env.exampleto.envand populate produciton secrets from 1pass - run
docker compose up -d
To update the service when there's code changes, first commit them to this repo. Then SSH to where docker is running and run:
docker compose down -v # stops service and deletes any ephemeral datagit pull origin main # pulls in latest code from githubdocker pull node:22-alpine # updates node imagedocker compose up -d # starts service in the background, optionally rebuilding the local cached image if need bedocker logs -f demo-account-slack-bot-node-1 # optional call to check logs - ctrl + c to exit when done
All configuration is stored in the .env file. If you need to make configuration changes, edit the .env file. Then run docker compose restart to make the changes take effect.
This may be helpful in trying to bootstrap the app in a more modern environment like docker or EKS:
No Node version was specified; we are using default version 10. You can change this in package.json: https://help.glitch.com/hc/en-us/articles/16287495688845-Can-I-change-the-version-of-node-js-my-project-uses-
node v10.24.1, npm 6.14.12
Installing...
audited 102 packages in 4.079s
1 package is looking for funding
run `npm fund` for details
found 35 vulnerabilities (6 low, 14 moderate, 15 high)
run `npm audit fix` to fix them, or `npm audit` for details
Total install time: 11672ms
🔼💮 ⚡️ Bolt app is running!
No Node version was specified; we are using default version 10. You can change this in package.json: https://help.glitch.com/hc/en-us/articles/16287495688845-Can-I-change-the-version-of-node-js-my-project-uses-
node v10.24.1, npm 6.14.12
Installing...
audited 102 packages in 3.383s
1 package is looking for funding
run `npm fund` for details
found 35 vulnerabilities (6 low, 14 moderate, 15 high)
run `npm audit fix` to fix them, or `npm audit` for details
Total install time: 10879ms
🎧🖤 ⚡️ Bolt app is running!
No Node version was specified; we are using default version 10. You can change this in package.json: https://help.glitch.com/hc/en-us/articles/16287495688845-Can-I-change-the-version-of-node-js-my-project-uses-
node v10.24.1, npm 6.14.12
Installing...
audited 102 packages in 3.383s
1 package is looking for funding
run `npm fund` for details
found 35 vulnerabilities (6 low, 14 moderate, 15 high)
run `npm audit fix` to fix them, or `npm audit` for details
Total install time: 10879ms
🥄🪝 ⚡️ Bolt app is running!