Last Updated: September 29, 2021
·
2.306K
· drrobotnik

Create team reminders with Hubot

Hubot-scripts comes with a reminders script. It is great, but (purposely?) missing the ability to add reminders for your team. Here's how I added team notifications.

In this bit, we add an extra regex match to capture who. Everything else is identical to the original script.

robot.respond /(remind )(.*) in ((?:(?:\d+) (?:weeks?|days?|hours?|hrs?|minutes?|mins?|seconds?|secs?)[ ,]*(?:and)? +)+)to (.*)/i, (msg) ->
  who = msg.match[2]
  time = msg.match[3]
  action = msg.match[4]

Hubot comes with an incredibly useful fuzzyname search. So go ahead and shorthand your teammates name, just be sure to be specific enough so there aren't multiple results.

users = robot.brain.usersForFuzzyName(who)
if users.length is 1
  user = users[0]

This is the key change. Most default hubot scripts respond to the person who wrote the request, here we need to set the user within msg.envelope.user to the one we captured above.

msg.envelope.user = user

And finally, create the reminder.

reminder = new Reminder msg.envelope, time, action
reminders.add reminder

If you find this useful, you can add this code to the end of the remind.coffee script found in hubot-scripts and move it where ever you're loading your scripts.