Created
November 29, 2010 20:44
-
-
Save tiegz/720576 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
ruleset APPID { | |
meta { | |
name "Say It (pronunciations)" | |
description << | |
You: SMS a word, Me: Call you with a pronunciation | |
>> | |
author "Tieg Zaharia" | |
logging on | |
key twilio { | |
"account_sid" : "YOUR_TWILIO_SID", | |
"auth_token" : "YOUR_TWILIO_AUTH_TOKEN" | |
} | |
// In your Twilio account, buy a phone number and add these webhooks: | |
// * VOICE: http://webhooks.kynetx.com:3098/t/APPID.dev/phoneinbound | |
// * SMS: http://webhooks.kynetx.com:3098/t/APPID.dev/smsinbound | |
} | |
dispatch {} | |
global { | |
datasource forvo:JSON <- "http://apifree.forvo.com/action/word-pronunciations/format/json/word/"; | |
} | |
rule smsinbound is active { | |
select when twilio smsinbound or webhook smsinbound | |
pre { | |
body = event:param("Body"); | |
from = event:param("From"); | |
} | |
twilio:place_call(from, "+1_YOUR_TWILIO_NUMBER", "http://webhooks.kynetx.com:3098/t/APPID.dev/phoneinbound?w=#{body}"); | |
} | |
rule phoneinbound is active { | |
select when pageview ".*" or twilio phoneinbound or webhook phoneinbound | |
pre { | |
word = event:param("w"); | |
resp = datasource:forvo("#{word}/language/en/key/YOUR_FORVO_API_KEY/"); | |
total = resp.pick("$..total"); | |
url = resp.pick("$..items[0].pathmp3"); | |
} | |
if (total neq "0") then { | |
twilio:say("The pronunciation is ") with voice="female"; | |
twilio:play(url); | |
twilio:play(url); | |
twilio:play(url); | |
} | |
fired { | |
log "Success"; | |
} else { | |
raise explicit event word_not_found; | |
} | |
} | |
rule word_not_found is active { | |
select when explicit word_not_found | |
twilio:say("That word was not found."); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment