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
In the #demo-account-testing channel , you can paste the following code to trigger the bot. This is the slowest, noisiest way to test, but is a full e2e test. Replace test values with your own:
Hello - please create a CHT demo account for the below:
Name: test-ignore test-ignore2222
Email: testing@example.org
Demo sign up: YesYou should get back something like:
CHT demo account created! Username: ttest641 Password: Pass1235
CHT demo account Email sent to testore@medic.org!To avoid the round trip via Slack, you can test locally by calling the /cht-user-create-test endpoint. Each time the server starts it will generate a new, secret URL to use based on a UUID. For example:
[INFO] bolt-app ⚡️ Bolt app is running!
[INFO] bolt-app Secret test URL - this changes every start:
curl -X POST http://localhost:4000/cht-user-create-test/a16676a8-c135-4d73-aa9a-d00cce931343And then the test curl call looks like:
curl -X POST http://localhost:4000/cht-user-create-test/a16676a8-c135-4d73-aa9a-d00cce931343
Test user request sentThis will use the TEST_NAME and TEST_EMAIL from your .env file.
Make sure .env file has correct values and run test script. For example to email mrjones@medic.org (but use your email!):
node --env-file=.env smtp-test.js mrjones@medic.orgYou should get back:
Message sent: <22adffea-4fb3-c192-1ec7-6c75d0fe5518@communityhealthtoolkit.org>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 production 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.