Skip to content

Instantly share code, notes, and snippets.

@rsbohn
Created September 27, 2011 11:08
Show Gist options
  • Select an option

  • Save rsbohn/1244827 to your computer and use it in GitHub Desktop.

Select an option

Save rsbohn/1244827 to your computer and use it in GitHub Desktop.
Hello Monkey
ruleset a1764x27 {
meta {
name "Chapter 10 Hello Monkey"
description <<
An example Twilio app. Give Twilio following URL to try it out:
http://webhooks.kynetxapps.net/t/a1764x27/inbound_call
>>
author "randy"
logging on
use module a421x70 alias Regression
errors to a421x70
}
dispatch {
// domain "exampley.com"
}
global {
look_up = function(phone) {
dir = {
"+14158675309":"Curious George",
"+14158675310":"Boots",
"+14158675311":"Virgil",
"+14158675312":"Marcel"};
caller = dir.pick("$.#{phone}");
(caller.as('str') neq '[]') => caller | "Monkey"
};
}
rule regression0 {
select when web pageview ".*"
Regression:begin("#main")
}
rule check_phonebook {
select when web pageview ".*"
pre {
test_num = defaction(phone, monkey) {
Regression:isEqual(phone, monkey, look_up(phone))
}
}
{
test_num("+14158675309", "Curious George");
test_num("+14158675310", "Boots");
test_num("+14158675300", "Monkey");
}
}
rule answer is active {
select when twilio inbound_call
pre {
callerid = event:param("From");
_name = look_up(callerid)
}
{
twilio:say("Hello #{_name}");
twilio:gather_start("monkey_handle")
with numDigits="1";
twilio:say("What is your favorite number?");
twilio:gather_stop();
}
}
rule picked is active {
select when twilio monkey_handle
pre {
favorite = event:param("Digits");
}
{
twilio:say("Your favorite number is #{favorite}.");
twilio:hangup();
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment