Don't like ads? PRO users don't see any ads ;-)
Guest

Untitled

By: a guest on May 1st, 2012  |  syntax: None  |  size: 3.23 KB  |  hits: 13  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. # This script is called via HTTP.
  2. # This is to demo Tropo conferencing functionality (via hosted script).
  3.  
  4. # Set up call options and conference options.
  5.  
  6. callOptions = { :channel => "VOICE",
  7.                 :answerOnMedia => false,
  8.                 :timeout => 30.0,
  9.                 :callerID => "BandCall"
  10.               }
  11.  
  12. conferenceOptions = { :joinPrompt => "You are connected.",
  13.                       :terminator => "*",
  14.                       :leavePrompt => "We hope you enjoyed your call!"
  15.                     }
  16.  
  17. # Method to create timeStamp as our conferenceID.
  18.  
  19. def get_conference_id()
  20.   timeVar  = Time.new
  21.   returnValue = timeVar.strftime("%Y%H%M%S")
  22.   return returnValue
  23. end
  24.  
  25. # Below module contains method to set up the 2nd thread call (to fan)
  26.  
  27. # Before any calls, create conference ID and log it.
  28. conferenceID = get_conference_id()
  29. log "@"*20 + ": " + conferenceID
  30.  
  31. # Make an outbound call to BANDMEMBER with call options.
  32. event = call 'tel:+1' + $bandmemberNumberToDial, callOptions
  33.  
  34. if event.name == 'answer'
  35.   log 'Outgoing call gets answered by ' + event.value.calledID
  36.  
  37.   # Ask BANDMEMBER if they want to talk to a fan now.
  38.   wait(2000)
  39.   say ("<prosody rate='-40%'>
  40.     'This is band call calling with a lucky fan connection!
  41.      Would you like to connect to your fan now?'
  42.         </prosody>",{:voice => "allison"})
  43.  
  44.   ChoiceOptions = { :choices => 'yes( 1, yes), no( 2, no)',
  45.                     :repeat  => 3 }
  46.  
  47.   result = ask 'To connect, just say yes! or press 1.
  48.                 For no, just say no, or press 2.', ChoiceOptions
  49.  
  50.   if result.name == 'choice'
  51.   case result.value
  52.    when 'yes'
  53.      say ('OK, we are connecting you with a fan right now.
  54.            The fans name is'
  55.            $fanName
  56.           'Please hold while we connect your call.
  57.            You can press star at any time to disconnect.')
  58.      conference(conferenceID, conferenceOptions)
  59.  
  60.      #Create new thread and make outbound call to FAN with call options.
  61.      Thread.new do
  62.        event = call 'tel:+1' + $fanNumberToDial, callOptions
  63.        say ("<prosody rate='-40%'>
  64.             'This is band call calling with a lucky fan connection!'
  65.              $bandmemberName + 'from the band, the hackers!,
  66.              is calling you now!
  67.              Would you like to connect to your band right now?'
  68.              </prosody>",{:voice => "allison"})
  69.  
  70.              ChoiceOptions = { :choices => 'yes( 1, yes), no( 2, no)',
  71.                                :repeat  => 3 }
  72.  
  73.              result = ask 'To connect, just say yes! or press 1.
  74.                            For no, just say no, or press 2.',
  75.                            ChoiceOptions
  76.  
  77.              if result.name == 'choice'
  78.                case result.value
  79.                when 'yes'
  80.                  say ('OK, we are connecting you right now!')
  81.  
  82.                  # Create conference (with 1st Thread)
  83.                  log "@"*5 + " Start Conference ID: " + conferenceID
  84.                  conference(conferenceID, conferenceOptions)
  85.  
  86.                when 'no'
  87.                  say ('OK, Sorry we missed you. Goodbye.')
  88.                  hangup
  89.              end
  90.  
  91.      when 'no'
  92.        say ('OK, We will try again later. Goodbye.')
  93.        hangup
  94.    end
  95. end