KynTwilGooCal - Tell Me When
In my last post, I described how to modify IVR menu item ordering based on Google Calendar events. In this post, I'll show you how we build option 5, including joining an active conference or finding out when the next one will happen.
First, we need some new functions. My module was so useful last time that I think I'll extend it to help me some more. First, a function. This is similar to onnow() from the last post, but looks for the next scheduled item with a matching title in the next 30 days. If no matching event is found, a falsy value will be returned. This method was added to the global block of the module I created last time.
In order to make that function available to rulesets that use this module, I need to add it's name to the list of functions provided in the meta block. The updated line looks like this:
Now for the rules. There are two possible behaviors for option 5, depending on if Office Hours are active. Recall that we set the ent:officehoursactive entity variable if our onnow() call returned true. We use that variable as a condition to join the caller to the office hours conference.
If Office Hours are not active, we need to tell the user when the next scheduled session is. Our second rule uses our new next() function, then formats the date for speaking and constructs a message. We've placed the formatting into a function for reuse and to clean up the flow of our code.
Our third rule catches the case that no future events were found, just in case something bad happened.
Our formatting function isn't fancy, but does the job. I plan to improve it in the future, so calling a function allows me to update this in one place, but have the improvements everywhere. Ahh, code reuse.
The clever reader will have noticed that I raise an event called EnsureRep when I join the caller to the office hours conference. I'd tell you about it, but I don't want to spoil the surprise! Soon, young KRL ninja.
A quick side note about modules: I added the next() method to my previous module. Anyone who has already started using this module can instantly use that method to spruce up their app! Modules are good for this sort of thing, so consider them when you want to reuse some code or share with others.