Skip to content

Instantly share code, notes, and snippets.

@edorcutt
Created November 8, 2010 16:34
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 edorcutt/667893 to your computer and use it in GitHub Desktop.
Save edorcutt/667893 to your computer and use it in GitHub Desktop.
CloudStatus provides both voice and sms status of 26 public APIs
ruleset a169x159 {
meta {
name "CloudStatus"
description <<
CloudStatus provides both voice and sms status of 26 public APIs
>>
author "Ed Orcutt"
logging on
}
dispatch { }
global {
dataset cloud_jsonp:HTML <- "http://s3.watchmouse.com/psp/overview_data/6404" cachable for 5 minutes;
// Hack! to remove the P part of JSONP :)
cloud_temp = cloud_jsonp.replace(re/render_overview\(/, "");
cloud_jstr = cloud_temp.replace(re/\);/, "");
cloud_status = cloud_jstr.as("json");
// Pick out services with warnings (performance issues) for the current_status
serviceWarnAry = cloud_status.pick("$..services[?(@.current_status eq 'warn')].name");
serviceWarnStr = serviceWarnAry.join(" and ");
serviceWarn = serviceWarnStr.replace(re/ API/g, "");
smsWarnStr = serviceWarnAry.join(", ");
smsWarn = smsWarnStr.replace(re/ API/g, "");
// Pick out services with errors (service disruption) for the current_status
serviceErrorAry = cloud_status.pick("$..services[?(@.current_status eq 'err')].name");
serviceErrorStr = serviceErrorAry.join(" and ");
serviceError = serviceErrorStr.replace(re/ API/g, "");
smsErrorStr = serviceErrorAry.join(", ");
smsError = smsErrorStr.replace(re/ API/g, "");
// Build the Voice Service Status Message
serviceMsgError = (serviceErrorAry.length()) => "service disruptions with " + serviceError + ". " | "";
serviceMsgWarn = (serviceWarnAry.length()) => "performance issues with " + serviceWarn + ". " | "";
serviceMsgBad = (serviceErrorAry.length() || serviceWarnAry.length()) =>
"Currently there are " + serviceMsgError + serviceMsgWarn + "All other services operating normally." |
"All services are currently operating normally.";
// Build the SMS Service Status Message
smsMsgError = (serviceErrorAry.length()) => "Disrupted Services: " + smsError + ". " | "";
smsMsgWarn = (serviceWarnAry.length()) => "Performance Issues: " + smsWarn + ". " | "";
smsStatusMsg = (serviceErrorAry.length() || serviceWarnAry.length()) =>
"CloudStatus: " + smsMsgError + smsMsgWarn |
"CloudStatus: All services are currently operating normally.";
}
////////////////////////////////////////////
// Answer incoming call
rule inbound_call is active {
select when twilio inbound_call
{
twilio:say("Hello, welcome to CloudStatus") with voice = "woman";
twilio:pause(1);
twilio:say("Service status are updated every 5 minutes") with voice = "woman";
twilio:pause(1);
}
fired {
raise explicit event say_bad_service;
}
}
////////////////////////////////////////////
// Give summary of services with errors & warnings
rule say_bad_service is active {
select when explicit say_bad_service
{
twilio:say(serviceMsgBad) with voice = "woman";
}
fired {
raise explicit event givemenu;
}
}
////////////////////////////////////////////
// Say menu choices
rule givemenu is active {
select when explicit givemenu
pre {
menuMsg = "Press 1 to repeat CloudStatus summary," +
"2 for service disruptions only," +
"3 for performance issues only," +
"or 0 to end the call.";
}
{
twilio:gather_start("statuschoice") with numDigits = "1" and timeout = "10";
twilio:say(menuMsg) with voice = "woman";
twilio:gather_stop();
}
}
////////////////////////////////////////////
// Give summary of services with errors & warnings
rule say_service_summary is active {
select when twilio statuschoice Digits "1"
{
twilio:say(serviceMsgBad) with voice = "woman";
}
}
////////////////////////////////////////////
// Services which are disrupted
rule say_service_disrupted is active {
select when twilio statuschoice Digits "2"
if (serviceErrorAry.length()) then {
noop();
}
fired {
raise explicit event serviceerrors;
} else {
raise explicit event noserviceerrors;
}
}
////////////////////////////////////////////
// There ARE disruptions (errors)
rule service_error is active {
select when explicit serviceerrors
{
twilio:say("Currently there are") with voice = "woman";
twilio:say(serviceMsgError) with voice = "woman";
}
}
////////////////////////////////////////////
// There are no disruptions (errors)
rule no_service_error is active {
select when explicit noserviceerrors
{
twilio:say("Currently there are no service disruptions.") with voice = "woman";
}
}
////////////////////////////////////////////
// Services with performance issues
rule say_service_performance is active {
select when twilio statuschoice Digits "3"
if (serviceWarnAry.length()) then {
noop();
}
fired {
raise explicit event servicewarning;
} else {
raise explicit event noservicewarning;
}
}
////////////////////////////////////////////
// There ARE performance issues (warning)
rule service_warning is active {
select when explicit servicewarning
{
twilio:say("Currently there are") with voice = "woman";
twilio:say(serviceMsgWarn) with voice = "woman";
}
}
////////////////////////////////////////////
// There are no performance issues (warning)
rule no_service_warning is active {
select when explicit noservicewarning
{
twilio:say("Currently no services have performance issues.") with voice = "woman";
}
}
////////////////////////////////////////////
// Caller is done
rule endcall is active {
select when twilio statuschoice Digits "0"
{
twilio:say("Thank you for calling CloudStatus, Goodbye!") with voice = "woman";
twilio:hangup();
}
}
////////////////////////////////////////////
// Repeat menu choices
rule backtomenu is active {
select when twilio statuschoice Digits "[123]"
noop();
fired {
raise explicit event givemenu;
}
}
////////////////////////////////////////////
// Invalid menu choice
rule invalidchoice is active {
select when twilio statuschoice Digits "([456789])" setting (badchoice)
{
twilio:say("#{badchoice} is not a valid status choice.");
}
fired {
raise explicit event givemenu;
}
}
////////////////////////////////////////////
// Incoming sms
rule inbound_sms is active {
select when twilio inbound_sms
{
twilio:sms(smsStatusMsg);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment