Created
June 9, 2010 23:20
-
-
Save PeterBloom/432340 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
# This script is called via HTTP. | |
# This is to demo Tropo conferencing functionality (via hosted script). | |
# Define Global Options | |
applicationCallerID = "6502916707" | |
# Method to create timeStamp as our conferenceID | |
def get_conference_id() | |
timeVar = Time.new | |
formattedTime = timeVar.strftime("%Y%H%M%S") | |
return formattedTime | |
end | |
# Setup some mapped 'call', 'say', 'conference', and 'choice' options | |
callOptions = { :channel => "VOICE", | |
:answerOnMedia => false, | |
:timeout => 30.0, | |
:callerID => applicationCallerID | |
} | |
sayOptions = { :voice => "kate"} | |
conferenceOptions = { :mute => false, | |
:playTones => false, | |
:terminator => "*", | |
:joinPrompt => "Connecting now.", | |
:leavePrompt => "We hope you enjoyed your call!" | |
} | |
choiceOptions = { :choices => 'yes( 1, yes), no( 2, no)', | |
:repeat => 3 | |
} | |
# Before any calls, create conference ID and log it. | |
conferenceID = get_conference_id() | |
log "@"*20 + ": " + conferenceID | |
# Make an outbound call to BANDMEMBER (first leg) with callOptions 'merge' into parameters hash. | |
call 'tel:+1' + $bandmemberNumberToDial, | |
{ :onAnswer => lambda{|event| | |
log "@"*5 + "BANDMEMBER has answered" | |
# Ask BANDMEMBER if they want to talk to a fan now. | |
wait(2000) | |
say("<prosody rate='-10%'>This is band call calling with a lucky fan connection! Would you like to connect to your fan now?</prosody>", sayOptions) | |
result = ask 'To connect, just say yes! or press 1. For no, just say no, or press 2.', choiceOptions | |
if result.name == 'choice' | |
case result.value | |
# YES, Bandmember wants to talk | |
when 'yes' | |
say('OK, we are connecting you with a fan right now. The fans name is ' + $fanName + ', Please hold while we connect your call. You can press star at any time to disconnect.', sayOptions) | |
# Create second thread for call to second leg (FAN) | |
Thread.new do | |
log "@"*5 + "Start second tread: call to Fan" | |
call 'tel:+1'+ $fanNumberToDial, | |
{ :onAnswer => lambda{|event| | |
log "@"*5 + "FAN has answered" | |
newCall = event.value | |
# announce caller (Bandmember) to Fan | |
wait(2000) | |
newCall.say("This is band call calling with a lucky fan connection! You have a call from the rolling stones!", sayOptions) | |
# join Fan to conference | |
newCall.conference(conferenceID, conferenceOptions) | |
} | |
}.merge(callOptions) | |
end | |
when 'no' | |
say ('OK, we can try again later. Goodbye.') | |
hangup | |
end | |
end | |
newCall = event.value | |
# prompt Bandmember | |
wait(2000) | |
newCall.say("We are connecting to your fan now.", sayOptions) | |
# join Bandmember to conference | |
newCall.conference(conferenceID,conferenceOptions) | |
} | |
}.merge(callOptions) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment