🎉🎈🎂🍾🎊🍻💃
Daily, automated problem of the day slack notifications.
Simple serverless script that will post a practice problem to a prespecified slack channel daily. The daily portion is achieved with a configured CRON job on Webtask. This job will invoke a function that POSTs to a Slack Incoming Webhook. Problems are managed via Airtable which provides a robust API for reading data to be pushed through the pipes to the slack channel.
- Support multiple users (for managing practice problems) via Airtable.
- Configurable CRON support for daily, bi-weekly, weekly, etc post frequency.
- Easily deployable to Webtask itself.
- Fire and forget, easy to resuse.
- Once the script is up and running, actual content can be managed by one or many non-technical personnel.
- Aims to be highly configurable...(not really sure if this has been achieved yet!)
This is a readonly base that demonstrates how the data should be organized. It is strongly recommended that you copy the base as a starting point to ensure data-types are presevered.
Using only bases and the CRON schedule, it is possible to apply this project towards pushing automated messages to a channel via date only. Find below some other template bases that can be leveraged for common class tasks.
- Lecture Base. Used to push common lecture info every Tues/Thursday before class begins.
Self explanatory, chatroom tool in use like...a lot. They've great API support! Super developer friendly! Great vehicle for practice content delivery.
Javascript focused serverless tool, very easy to configure and deploy. However, it is not meant to be used for more involved applications. Future iterations of this bot may have to migrate over to AWS Lambda for this reason.
There's a few steps required to deploy this script. Ideally, these steps could be made simpler - please submit PRs and ideas/issues around this!
$ <git clone repo, cd into it>
$ cd app/
$ npm install
Everything is installed locally, so you will have to use ./node_modules/.bin/<script>
to run scripts. Yes, this is annoying. Yes, it is worth the pain.
If you don't have webtask CLI already set up, please do so now. Setting up Webtask CLI.
In order to properly use this script, you will have to supply some scripts. In the app/
directory you will see a .secrets.txt.sample
.
First, let's copy it.
$ cd app/
$ cp .secrets.txt.sample .secrets.txt
Below, please find an explanation of what each key does. NOTE: Not all are "secrets" per-se but for now easier to keep all in one place.
TABLENAME=Problems
INDEXCOL=Date
DATACOL=Problem
BASEKEY=XXXXXXXXXXX
VIEW=Grid view
MAXRECORDS=100
AIRTABLE_API_KEY=XXXXXXXXXXX
FMT=YYYY-MM-DD
SECRET NAME | SECRET VALUE |
---|---|
TABLENAME |
the name of your table in a new airtable base. Essentially, a "base" is equivalent to a google spreadsheet. Each "table" is an individual view of that spreadsheet. You are free to name your table anything you want - just point to the correct label here. |
INDEXCOL |
refers to the column that stores the dates for the problem of the day. |
DATACOL |
is the column that will store all the data to be pushed through to slack. |
BASEKEY |
refers to a key assigned by Airtable to the base. Pls refer to the figures below to track down your base key. |
AIRTABLE_API_KEY |
super important, required to connect ot Airtable. Pls refer to the figure below to track down api key. |
VIEW |
is a value that the airtable API requires, Keeping it around in case we wanted to change ever. |
FMT |
airtable has a date picker column that seems to default to YYYY-MM-DD . |
MAXRECORDS |
will select only that many records in query. Not sure what the max queryable number is so we defaulted to 100, which seemed reasonable. |
STEP 1: Find the '?' icon on the top right corner of the base view.
STEP 2: Click on the icon and then select the API DOCUMENTATION selection
STEP 3: On the top right of the page that opens, select the show API Key option
STEP 4: Scroll down to the AUTHORIZATION section to grab the pertinent info In this case, BASEKEY is appy3yLRvrVArKmhJ and AIRTABLE_API_KEY is YOUR_API_KEY.
USERS=U85KT784S,U85N9D3V2
MENSTIONSEP= or
TEMPLATE=<!channel>: here is the *problem of the day* for today:\n\`\`\`\n$DATA\n\`\`\`\nRemember to hit up $MENTIONS (...or your classmates) to discuss! Goodluck!`,
SLACK_WEBHOOK=https://hooks.slack.com/services/XXXXXXXXXXX/XXXXXXXXXXX/XXXXXXXXXXX
SECRET NAME | SECRET VALUE |
---|---|
USERS |
refers to actual users that can be @-mentioned when problem of the day is pushed through. Ideally these users should be TAs or student reps (this is useful to tell students how to submit solutions to the problems of the day) |
MENTIONSSEP |
refers to how the @-mentioned users are seperated, just formatting stuff mainly |
TEMPLATE |
allows for editing how the problem of the day text is formatted. $DATA is the content read from Airtable's DATACOL column. $MENTIONS is an assembled list of USERS who will be @-mentioned. The <!channel> will call out to the entire channel. (Look at the Variables section here) |
SLACK_WEBHOOK |
refers to slack incoming webhooks. Set that up here |
$ cd app/
$ npm run deploy -- -t sample-task -c "50 20 * * *"
Where -c
is defined CRON frequency, -t
is the name of your task.
Donezo!
- Better test coverage
- More meaningful tests
- Convert more of the javascript codebase to use webpack generated 'bundle.js'
- Dedicated AWS Lambda / DynamoDB store (ie: migrate off of MyJSON API)
PRs welcome! Please follow guidelines here.
This project is a remotecontrol service.