Send the GitHub trending of your favorite languages into your Slack channel!
SLACK_HOOK_URL="https://hooks.slack.com/services/T00000000/B00000000/XXXXXXXXXXXXXXXXXXXXXXXX" npx ts-node src/report.ts javascript today
You should install Incoming Webhooks first to get a slack hook url.
If you can use envrc
, please check an example file: .envrc.example
.
Add a new schedule.json
file copied from schedule.example.json
file to set that to SCHEDULE
environment variable.
{
"dayOfWeek": {
"trendings": [{ "language": "language", "period": "period" }],
"owners": ["owner-name"]
}
}
dayOfWeek
is a string and it is one of mon
, tue
, wed
, thu
, fri
, sat
and sun
. For example, you can set like this if you want to receive the c++ weekly
trend and Microsoft
's repositories that have changed over the past day in every Monday.
{
"mon": {
"trendings": [{ "language": "c++", "period": "weekly" }],
"owners": ["microsoft"]
}
}
Of course, you can use all
of dayOfWeek
to schedule something for all days.
{
"all": {
"trendings": [{ "language": "golang", "period": "weekly" }],
"owners": ["google"]
}
}
And then run a scheduler.js
script with SLACK_HOOK_URL
.
SLACK_HOOK_URL="https://hooks.slack.com/services/T00000000/B00000000/XXXXXXXXXXXXXXXXXXXXXXXX" node scheduler.js
If you don't think about a machine to run this script as a cron job, you can choose the AWS Lambda. It can run a lambda function periodically with CloudWatch's scheduler tick. I set to launch this function at every 10AM (KST) into functions.reportToday.events.schedule
at serverless.yml
.
You can deploy this into your lambda with your AWS_PROFILE
environment variable by serverless
.
- Check your AWS credentials, for example,
AWS_PROFILE
env. - Install
serverless
withnpm
command. - Check your
SLACK_HOOK_URL
,SLACK_TRENDING_CHANNEL
,SLACK_OWNER_CHANNEL
andSCHEDULE
environment variables with referencing.envrc.example
file andschedule.example.json
file. - Check the cron expression in
serverless.yml
file. npm run deploy
to deploy.
It contains an API Gateway endpoint to call it manually, so you use curl
to test it.
curl -XPOST "https://YOUR-APIID.execute-api.AWS-REGION.amazonaws.com/production/trending/LANGUAGE/PERIOD"
curl -XPOST "https://YOUR-APIID.execute-api.AWS-REGION.amazonaws.com/production/owner/LANGUAGE/PERIOD"
Or, you can call all things in the schedule using this endpoint.
curl -XPOST "https://YOUR-APIID.execute-api.AWS-REGION.amazonaws.com/production/"