Skip to content

Instantly share code, notes, and snippets.

@TelegramSam
Created February 2, 2011 23:10
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/808653 to your computer and use it in GitHub Desktop.
Save TelegramSam/808653 to your computer and use it in GitHub Desktop.
including the module
meta {
...
use module a8x114 alias kpublicevents with url =
"http://www.google.com/calendar/feeds/sk8bh034vvqfbgercq68rtspi4@group.calendar.google.com/public/basic"
}
//give the menu
rule menustart {
select when twilio givemenu or explicit givemenu
twilio:gather_start("menuchoice") with numDigits = 1;
fired {
ent:menucount += 1 from 1;
raise explicit event menucontent;
}
}
rule instantofficehours {
select when explicit menucontent
if kpublicevents:onnow("Office Hours") then
twilio:say("Office Hours are currently open. Press 5 to join Office Hours.");
fired {
set ent:officehoursactive;
}
}
rule menumain {
select when explicit menucontent
{
twilio:say("Press 1 to speak to a member of the team.");
twilio:say("Press 2 to join a meeting. ");
}
}
rule menuofficeoption {
select when explicit menucontent
if not ent:officehoursactive then
twilio:say("Press 5 to hear about office hours. ");
}
rule menuend {
select when explicit menucontent
{
twilio:gather_stop();
twilio:redirect("givemenu");
}
}
ruleset a8x114 {
meta {
name "GCal Util Module"
description <<
Utilities for Google Calendar, including onnow and next
>>
author "Sam Curren"
logging off
configure using
url = "http://www.google.com/calendar/feeds/sk8bh034vvqfbgercq68rtspi4@group.calendar.google.com/public/basic"
provides onnow
}
dispatch {}
global {
//used for self reference
thisappid = "a8x114";
//default calendar options.
caloptions = {
"singleevents":"true",
"alt":"jsonc",
"ctz":"America/Denver",
"orderby":"starttime",
"sortorder":"a"
};
//this is needed for testing. 'configure' variables are not available when running as a ruleset
rawurl = url => url | "http://www.google.com/calendar/feeds/sk8bh034vvqfbgercq68rtspi4@group.calendar.google.com/public/basic";
calendarurl = rawurl.replace(re/basic$/i, "full"); //make it a 'full' feed if basic was specified
onnow = function(title){
start = time:now();
end = time:add(start, {"minutes":1});
requestoptions = caloptions.put({"start-min": start,"start-max": end });
onnow = http:get(calendarurl, requestoptions).pick("content").decode();
alltitles = onnow.pick("$..items[*].title", true);
relevanttitles = alltitles.filter(function(t){t==title});
relevanttitles.length() > 0;
};
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment