Created
March 26, 2010 19:32
-
-
Save zlu/345283 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
# example input: en, es, how are you, 16502437867. | |
# notice the comma as deliminator | |
%w(open-uri json).each do |lib| require lib; end | |
url = "http://ajax.googleapis.com/ajax/services/language/translate?v=1.0" | |
initialText = $currentCall.initialText.split(",") | |
initialText.each do |elem| elem.strip! end | |
log initialText | |
params = {"q" => initialText[2], "langpair" => initialText[0] + "|" + initialText[1]} | |
params.each {|k,v| url << "&"+k.to_s+"="+URI.escape(v.to_s)} | |
response = JSON.parse(open(url).read) | |
number_to_dial = initialText[3] | |
log number_to_dial | |
answer | |
if response["responseStatus"] == 200 | |
translation = response["responseData"]["translatedText"] | |
say "Success - #{response["responseData"]["translatedText"]}" | |
unless number_to_dial.nil? | |
# sadly the say comes out to IM, not voice. | |
call "tel:+" + number_to_dial, "PSTN", { :onAnswer => lambda { say translation }, :channel => "VOICE" } | |
end | |
else | |
say "Failure (#{response["responseStatus"]}) - #{response["responseDetails"]}" | |
end | |
hangup |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment