Birthday slackbot implementation...
This slackbot is written in python, using AWS Chalice to configure AWS Lambda and API Gateway automatically. Project uses Upstash Redis for database.
-
Commands:
- set:
/event set birthday <YYYY-MM-DD> <user>:- Sets the birthday of the user.
/event set anniversary <YYYY-MM-DD> <user>:- Sets the anniversary for the user, when they started working there.
/event set custom <YYYY-MM-DD> <user> <any kind of message with whitespaces>:- Sets a custom reminder using the message provided.
- get-all:
/event get-all birthday:- Shows all birthdays that are set.
/event get-all anniversary:- Shows all anniversaries that are set.
/event get-all custom:- Shows all custom events that are set.
- get:
/event get birthday <user>:- Shows the birthday details of the user.
/event get anniversary <user>:- Shows the anniversary details for the user, when they started working there.
/event get custom <event_name>(can be found with get-all):- Shows the custom event details using the message provided.
- remove:
/event remove birthday <user>:- Removes the birthday of the user.
/event remove anniversary <user>:- Removes the anniversary for the user, when they started working there.
/event remove custom <event_name>(can be found with get-all):- Removes the custom event using the message provided.
- set:
-
If a single user is mentioned while setting the event:
- When the actual event date comes, mentions them in the general channel with a celebratory message.
- Sends a private message to everyone except the mentioned user before the actual date comes.
-
Go to the Upstash Console and create a new database
Find the variables in the database details page in Upstash Console:
UPSTASH_REDIS_REST_URLandUPSTASH_REDIS_REST_TOKEN(These will be the env variables for chalice deployment)
May need to revise permissions and what not
- Go to Slack API Apps Page:
- Create new App
- From Scratch
- Name your app & pick a workspace
- Go to Oauth & Permissions
- Add the following scopes
- channels:read
- chat:write
- chat:write.public
- commands
- groups:read
- users:read
- Install App to workspace
- Basic Information --> Install Your App --> Install To Workspace
- Add the following scopes
- Create new App
- Note the variables (These will be the env variables for vercel deployment) :
SLACK_SIGNING_SECRET:- Go to Basic Information
- App Credentials --> Signing Secret
- Go to Basic Information
SLACK_BOT_TOKEN:- Go to OAuth & Permissions
- Bot User OAuth Token
- Go to OAuth & Permissions
(Taken from Official Chalice Repo. You can refer for more info there.)
$ mkdir ~/.aws
$ cat >> ~/.aws/config
[default]
aws_access_key_id=YOUR_ACCESS_KEY_HERE
aws_secret_access_key=YOUR_SECRET_ACCESS_KEY
region=YOUR_REGION (such as us-west-2, us-west-1, etc)
-
Install
chaliceif not installed:pip install chalice -
Configure
config.jsonfile inside the.chalicedirectory by adding:"environment_variables": { "UPSTASH_REST_URL": <UPSTASH_REDIS_REST_URL>, "UPSTASH_TOKEN": <UPSTASH_REDIS_REST_TOKEN>, "SLACK_BOT_TOKEN": <SLACK_BOT_TOKEN>, "SLACK_SIGNING_SECRET": <SLACK_SIGNING_SECRET>, "NOTIFY_TIME_LIMIT": "<amount of days before getting notifications for events>" }To run locally:
chalice localUsing services such as ngrok, tunnel the relevant port, then use the public domain for Slack.
chalice deployUse the
REST API URLfor Slack.
- After deployment, you can use the provided
REST API URL.
- Go to Slack API Apps Page and choose relevant app:
- Go to Slash Commands:
- Create New Command:
- Command :
event - Request URL :
<REST_API_URL> - Configure the rest however you like.
- Command :
- Create New Command:
- Go to Slash Commands:
After these changes, Slack may require reinstalling of the app.