Skip to content

Instantly share code, notes, and snippets.

@TelegramSam
Created February 3, 2011 03:59
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save TelegramSam/809029 to your computer and use it in GitHub Desktop.
Save TelegramSam/809029 to your computer and use it in GitHub Desktop.
features that show what is up next
provides onnow, next
rule joinofficehours {
select when twilio menuchoice Digits "5"
if ent:officehoursactive then {
twilio:say("Joining Office Hours. Press star to exit.");
twilio:dial_conference("officehours") with hangupOnStar = "true";
}
fired {
raise explicit event EnsureRep;
}
}
rule nextofficehours {
select when twilio menuchoice Digits "5"
pre {
nextevent = kpublicevents:next("Office Hours");
eventtitle = nextevent => verbaldate(nextevent.pick("$.when[0].start")) | "No Event Scheduled";
}
if nextevent then {
twilio:say("Our next office hours session is #{eventtitle} Mountain Time.");
twilio:redirect("givemenu");
}
notfired {
raise explicit event "NotScheduled";
}
}
rule notscheduled {
select when explicit NotScheduled
{
twilio:say("There are no office hours currently scheduled. Please check our website for more details.");
twilio:redirect("givemenu");
}
}
//returns either the next event with a matching title, or a 'falsy' value
next = function(title){
start = time:now();
end = time:add(start, {"days":30});
requestoptions = caloptions.put({
"start-min": time:atom(start),
"start-max": time:atom(end)
});
onnow = http:get(calendarurl, requestoptions).pick("content").decode();
allevents = onnow.pick("$..items[*]", true);
relevantevents = allevents.filter(function(e){e.pick("$.title") eq title});
nextevent = relevantevents.head();//first event is next, because of sort order
nextevent;
};
verbaldate = function(d){
datestringA = time:strftime(d, "%A, %d of %B at %I, %M %p");
datestringB = datestringA.replace(re/ 0/g, " ").replace(re/ 0/g, " ");
datestringB;
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment