Sending Timely Reminders


Use for NLP, Moment.js in Javascript Macros, and Dexter’s Reminder Shortcode to let your users set custom times for reminders.


> object encodeURI javascript
  // Encode request from user
  return encodeURIComponent(args[0]);
< object
> object getTimecode javascript
  // Get JSON from HTTP Post
  var json_obj = this.httpData;
  // Get datetime value from JSON
  var time_string = json_obj.entities.datetime[0].value;
  // Use Moment.js to convert to readable time
  var time_readable = moment(time_string).utcOffset("-05:00").format("dddd, MMMM Do, YYYY, h:mm a");
  // Use Moment.js to convert to unix timecode
  var time_unix = moment(time_string).valueOf();
  // Set variables for use in Dexter
  rs.setUservar(rs.currentUser(), 'time_unix', time_unix);
  rs.setUservar(rs.currentUser(), 'time_readable', time_readable);
  // Continue conversation and set reminder
  return rs.reply(rs.currentUser(), 'reminder');
< object
+ set reminder
- When would you like a reminder?
+ *
$ POST"<call>encodeURI <star></call>" {"headers":{"Authorization":"Bearer <<YOUR_API_KEY>>","Content-Type":"application/json"}}
* ${{entities.datetime.0.confidence}} >= 0.9 => <call>getTimecode</call>
- Hm, that doesn't seem right. You can say “tomorrow at 1” or “next tuesday at 5pm” or “10/10/2019 9am”—try again please. <send> {@ set reminder}
+ reminder
- ^reminder(my_reminder, "Reminder on <get time_readable>!", <get time_unix>) {@ confirm}
+ confirm
- Ok, you'll get a reminder on <get time_readable>. <send> Say cancel at any time to cancel your reminder.
+ cancel
- Okay, your reminder is cancelled. ^reminderCancel(my_reminder)


Although this snippet is copy-and-pasteable, to understand everything that’s going on here, you will need some understanding of Natural Language Processing (NLP) and Javascript.

You’ll need a key to use the API which is an NLP interpreter that can convert text to types of data. Create a new app with a datetime entity. Replace <<YOUR_API_KEY>> with the generated key in your app’s Settings page.

From a high-level, here are the steps we’re taking:

  1. Capture when a user wants a reminder (i.e. tomorrow at 1pm).
  2. Encode the message using a Javascript Macro called encodeURI so we can safely send it to
  3. Make a POST Request to the API.
  4. Check the Confidence of the response to make sure was able to identify at least one proper value for datetime.
  5. If the confidence is high, we use another Javascript Macro getTimecode with Moment.js to convert the timestamp to a readable timestamp, and a Unix timestamp.
  6. We use the Unix timestamp with Dexter’s Reminder Shortcode to create a reminder for the bot user.
  7. We use the readable times to confirm the reminder with the user, and then give the user an opportunity to cancel. It’s best practice to always give users a way out.
  8. We can also call the Cancel Reminder shortcode if a user wants to cancel a reminder that has been previously set.

You can also check out our snippets for Capturing Message Content for creating reminders with custom content.