Slack application to manage reminders with commands.
The goal is build a simple mechanism that keeps reminders using Slack service to notify when they happen in our devices like PC or mobile phone.
-
I decided to save the state of the reminders into a NoSQL database because it's good for resume after shutdown or energy fault.
-
We have some level of abstraction in the database interface.
ReminderDB |
---|
BasicDB |
MongoDB |
- Code modularity was keep in mind to give an easy way to add new commands and operations.
Starting with the types defined in NotyTypes.hs
- NotyReq: Represent requests by the user.
- NotyResp: Represent reply for an user request.
The same for the parsing module (Parsing.lhs) and communication settings for Slack (SlackConfig.hs) behind Linklater library.
Reminder API | |||
---|---|---|---|
DailyReminder | EventualReminder | ||
ReminderTypes | NotyTypes | SlackConfig | Parsing |
We have a listener thread running in port 3000 that uses Reminder Manager's interface. After a command is received, processing functions will be executed, so can be happen the next:
- Generate a direct reply.
- Change the state of the reminders.
- Launch a thread for new reminder.
When the waiting time of a reminder is reached, the system wakes up its thread that will send a message to the Slack channel and then check for a new iteration.
Inside scripts, you will find:
deps.sh
to install needed dependencies.config.sh
to configure the project with stack and download needed libs.build.sh
to build NotyBot application.run.sh
to run NotyBot application in a shell.launch.sh
to run NotyBot application with screen and record log file.
We need to do some steps more to use NotyBot app in Slack:
- Create an account and workspace in Slack
- Create a channel where user NotyBot app
- Crear una app en Slack API
- Add features and functionalities:
- Incoming webhooks: Habilitarlo y crear un webhook en el canal donde se va a utilizar la app. Guardar la URL en un archivo llamado "hook" en el directorio raíz de este repo.
- Slash commands: Agregar dos comandos "eventual" y "daily", completar el campo "Request URL" con http://TU_IP_PUBLICA:3000 NOTA: Si no tienes IP pública puedes usar algún servicio como ngrok y asignar esa.
- Permissions: Entiendo que los que vienen por defecto alcanza, se podría agregar alguno si hiciera falta.
- Instalar la app en el workspace
Una vez que se haya instalado la aplicación en un canal de Slack y se encuentre en ejecución el servidor. Es posible utilizar los comandos para empezar a usarla:
daily
: To manage recurring reminders. Ex: Run in the park, water the plants, change toothbrush, etceventual
To manage reminders about defined datetimes. Ex: A meeting, anniversary, etc.
We defined 3 operations for each command.
add
Add new reminder.del
Delete reminder.list
List all reminders.
The next command creates a reminders with id "iD_rec" that will notify you at 7:30 pm during 8 days.
/daily add iD_rec at 19:30 repeat 7
The next command creates a reminders with id "clase2" that will notify you every 22 minutes once time.
/daily add clase2 every 22 minutes
he next command creates a reminders with id "cumple_juan" that will notify you at 20 of December of 2019 at 7:30 pm.
/eventual add cumple_juan on 2019-12-20 at 19:30
NOTE: The identifiers must be start with lowercase letter follow by any combination of alphanumeric chars, middle hyphen or underscore.
/eventual list
/daily list
Get a list with all pending reminders with some information associated.
/eventual del cumple_juan
/daily del iD_rec
- Distribute NotyBot into Slack App Directory:
- Configure SSL certificate to use HTTPS.
- Enable OAuth 2 y URL redirection.