Because I can't remember it is whose turn to clean toilet and house this week

Telegram Roster Bot (Bot Programming)

Apr 22

Background

This short blog talks about how I created a telegram bot and used Github Action to remind me and my new housemates whose turn is to wash toilets and clean the house (because I can't remember whose turn is it).

Tools and Methods

  • Github Action
  • JavaScript

Read time

  • 3 mins

Weekly Roster

Since my housemates and I have already agreed that we will split the houseworks into two, and each housework would be taken up by a group of two taking turns repeatedly, so we have the following arrangement, every week:

  • - Clean toilet: Me, Housemate-A
  • - Clean house floor: Housemate-B, Housemate-C

So the logic is simple, one of the weeks I and Housemate-B will form a pair to clean the toilet and house respectively, and the following week will be Housemate-A and Housemate-C's turns. This pattern will repeat indefinitely until we have a new arrangement.

With the routine out of the way, now I just have to build it out. I first created a telegram bot through @BotFather , a helper bot created by the telegram team to help developers create their own bot. Then I added the bot to my house's group chat. The role of the bot is to simply ping our group with that week's roster.

Placeholder

Implementation

As for the roster generation, I simple forked out a project by richierich25 on Github where his project was to send the weather information every 15 minutes. I modify the code to fit my own use case. Basically, I have a nodejs main function which will get invoked whenever the file index.js gets executed. Inside the main function, is another function call to get the cleaner telegram username (hardcoded in an array) for the toilet and house floor. With the username returned, I simply generate a message from the template and fire the telegram's API call to send a message to our group through the bot.

As this app is not running 24/7, we cannot save the state in this script. To easily solve that, I simply write the next person to a file (toilet.txt, house.txt) and retrieve it the next week the same script gets executed and updates the file with the next person.

Lastly, to automatically trigger the script at the same time every week, I used Github Action to do the job. One caveat I noticed was that the time I received the message from the bot is not the time configured on Github Action. After a quick search online, it was probably due to a large number of jobs from other developers, causing the jobs to be processed later than it was supposed to be. Hence, use it with care if you need to run time-sensitive jobs with it.

Placeholder

And that's basically it! A simple over-the-weekend project that solves my own need. Hope you enjoy reading this piece, thank you richierich25 for the original project, Github for the free services and my lovely housemates for keeping our house clean!

Placeholder
© 2020-2024 Tan Shin Jie. Site built with ❤️ by yours truly.