From 376f3979d81c6398bb4029d5bf606bba7b07ae4b Mon Sep 17 00:00:00 2001 From: Ben Langfeld Date: Fri, 24 Dec 2010 18:39:11 +0000 Subject: [PATCH] Kill whitespace --- README.md | 418 ++++++++++++++++---------------- examples/adhearsion_dialplan.rb | 6 +- lib/tropo-agitate.rb | 208 ++++++++-------- lib/tropo.rb | 24 +- spec/spec_helper.rb | 2 +- spec/tropo-agitate_spec.rb | 68 +++--- spec/tropo-commands_spec.rb | 44 ++-- spec/tropo-evented_spec.rb | 20 +- 8 files changed, 395 insertions(+), 395 deletions(-) diff --git a/README.md b/README.md index 93000b8..89e8c1c 100644 --- a/README.md +++ b/README.md @@ -11,7 +11,7 @@ Provides a script to emulate the Fast Asterisk Gateway Interface [FastAGI]([http Installation ----------- -This project allows you to control the Tropo AGI via an Adhearsion dialplan context. +This project allows you to control the Tropo AGI via an Adhearsion dialplan context. * Create a free account at [Tropo](http://tropo.com "Tropo"). @@ -38,7 +38,7 @@ Instructions may be found [here](https://www.tropo.com/docs/scripting/quickstart * Set your Tropo app to use the [lib/tropo-agitate.rb](https://github.com/tropo/tropo-agitate/raw/master/lib/tropo-agitate.rb) script * Load the file directly to the Github file location [lib/tropo-agitate.rb](https://github.com/tropo/tropo-agitate/raw/master/lib/tropo-agitate.rb) - * Host the 'tropo-agitate.rb' yourself and provide a public URL for access + * Host the 'tropo-agitate.rb' yourself and provide a public URL for access * Add it to your Tropo FTP/WebDAV account * Modify the configuration file and post it to your Tropo FTP/WebDAV account @@ -57,60 +57,60 @@ Tropo supports placing outbound calls with the [Session API](https://www.tropo.c * destination - The destination to make a call to or send a message to. This may currently take one of the following forms: + The destination to make a call to or send a message to. This may currently take one of the following forms: - 14155551212 - The telephone number to dial with the country code. - sip:username@doamin.com - The SIP URI to dial - username - The IM or Twitter user name. + 14155551212 - The telephone number to dial with the country code. + sip:username@doamin.com - The SIP URI to dial + username - The IM or Twitter user name. - Some IM networks like Google Talk and Live Messenger include a domain as part of the user name. For those networks, include the domain: username@gmail.com + Some IM networks like Google Talk and Live Messenger include a domain as part of the user name. For those networks, include the domain: username@gmail.com - When making a voice call, you can specify dialing options as part of the number: + When making a voice call, you can specify dialing options as part of the number: - You can also list multiple phone numbers or SIP addresses (or both!) as a comma separated list + You can also list multiple phone numbers or SIP addresses (or both!) as a comma separated list * caller_id - The Caller ID for the session's origin. For example, if the number (407)555-1212 called (407)555-1000, the *1212 number would be the callerID. This also applies to IM account names; if IM account 'tropocloud' sends a message to 'foobar123', the callerID would be 'tropocloud'. + The Caller ID for the session's origin. For example, if the number (407)555-1212 called (407)555-1000, the *1212 number would be the callerID. This also applies to IM account names; if IM account 'tropocloud' sends a message to 'foobar123', the callerID would be 'tropocloud'. - The callerID can be manually set to a specific number; for voice calls, this can be any valid phone number, though for SMS and IM it must be a number/ID assigned to your account. + The callerID can be manually set to a specific number; for voice calls, this can be any valid phone number, though for SMS and IM it must be a number/ID assigned to your account. * channel - Channel tells Tropo whether the call is "voice" or "text". + Channel tells Tropo whether the call is "voice" or "text". * network - Network is used mainly by the text channels; values can be SMS when sending a text message, or a valid IM network name such as AIM, GTALK, MSN, JABBER, TWITTER and YAHOO. For IM network, you must have an IM account linked in your app. For example, if you try to send to AIM when you don't have an AIM username included in your app, your app will fail. + Network is used mainly by the text channels; values can be SMS when sending a text message, or a valid IM network name such as AIM, GTALK, MSN, JABBER, TWITTER and YAHOO. For IM network, you must have an IM account linked in your app. For example, if you try to send to AIM when you don't have an AIM username included in your app, your app will fail. * timeout - Timeout only applies to the voice channel and determines the amount of time Tropo will wait - in seconds - for the call to be answered before giving up. + Timeout only applies to the voice channel and determines the amount of time Tropo will wait - in seconds - for the call to be answered before giving up. * tropo_tag - An arbitrary unique identifier that you may use to identify the call once it is placed and passed to your AGI server. This value will appear in the tropo\_headers variable received at the beginning of the request to your AGI server in the JSON as tropo\_tag. - + An arbitrary unique identifier that you may use to identify the call once it is placed and passed to your AGI server. This value will appear in the tropo\_headers variable received at the beginning of the request to your AGI server in the JSON as tropo\_tag. + You may then invoke a call request via HTTP as follows: * GET
-	http://api.tropo.com/1.0/sessions?action=create&token=TOKEN&destination=NUMBER&caller\_id=CALLINGNUMBER&tropo_tag=1234
+  http://api.tropo.com/1.0/sessions?action=create&token=TOKEN&destination=NUMBER&caller\_id=CALLINGNUMBER&tropo_tag=1234
 
* POST
-	http://api.tropo.com/1.0/sessions
-	
-	
-		YOUR_TOKEN
-		
-		
-		
-	
-	
+  http://api.tropo.com/1.0/sessions
+  
+  
+    YOUR_TOKEN
+    
+    
+    
+  
+  
 
- + Supported Adhearsion & AGI Methods ---------------------------------- @@ -127,186 +127,186 @@ Adhearsion Dialplan Examples These Adhearsion dialplan examples are also available in the 'examples' directory of this project.
-	# The main AGI entry point
-	tropo_agi {
-	  answer
-	  +hello_world
-	  hangup
-	}
-
-
-	# Invokes the native Tropo ask for Speech Recognition / ASR
-	# Related Tropo method: https://www.tropo.com/docs/scripting/ask.htm
-	ask_example {
-	  result = execute 'ask', { :prompt  => 'Please enter your zip code', 
-	                            :choices => 'zipcode([5 DIGITS])' }.to_json
-	  # Get rid of the '200 result =' and then parse the JSON
-	  response = JSON.parse(result[11..-1])
-	  ahn_log.debug response
-	}
-
-	# We have lots of Asterisk sounds!
-	asterisk_sounds_example {
-	  play 'tt-monkeys'
-	}
-
-	# You may dial other SIP addresses, or telephone numbers as you like
-	# Formats may be:
-	#  SIP/
-	#  sip:
-	#  tel:+
-	# Related Tropo method: https://www.tropo.com/docs/scripting/transfer.htm
-	dial_example {
-	  dial 'sip:9991443146@sip.tropo.com'
-	}
-
-	hello_world {
-	  play 'tt-monkeys'
-	}
-
-	# Works as input should, only accepting DTMF
-	# Related Tropo method: https://www.tropo.com/docs/scripting/ask.htm
-	input_example {
-	  postal_code = input 5, :play         => 'Please enter your post code?',
-	                         :timeout      => 2
-
-	  ahn_log.postal_code.debug postal_code
-	  play "You entered"
-	  say_digits postal_code
-	}
-
-	# Find out if this is a Tropo session or an Asterisk one
-	is_tropo? {
-	  if type == 'TROPO'
-	    play "Yippeee! It is a Tropo call!"
-	  else
-	    play "No, this is a good old Asterisk call"
-	  end
-	}
-
-	# Related Tropo method: https://www.tropo.com/docs/scripting/say.htm
-	say_digits_example {
-	  say_digits '12345'
-	}
-
-	# Uses the native Tropo say method for Speech-Synthesis/TTS, will not play Asterisk sound files like play will
-	# Related Tropo method: https://www.tropo.com/docs/scripting/say.htm
-	say_example {
-	  execute 'say', { :prompt => 'I like to have weasels in my cloud.', :voice => 'simon' }.to_json
-	}
-
-	# If this is a Tropo call, then all of the SIP headers for the session are available
-	show_call_data {
-	  ahn_log.tropo_headers_str.debug tropo_headers
-	  tropo_headers = JSON.parse self.tropo_headers
-	  ahn_log.tropo_headers_hash.debug tropo_headers
-	  play "The content type is " + tropo_headers['Content-Type']
-	  +asterisk_sounds_example
-	}
-
-	# Monitor and Mixmonitor behave the same, may also be invoked as startCallRecording
-	# Related Tropo method: https://www.tropo.com/docs/scripting/startcallrecording.htm
-	monitor_example {
-	  play 'About to start call recording'
-	  execute 'monitor', { :uri                 => 'http://tropo-audiofiles-to-s3.heroku.com/post_audio_to_s3?filename=voicemail.mp3',
-	                       :format              => 'mp3',
-	                       :method              => 'POST',
-	                       :transcriptionOutURI => 'mailto:jsgoecke@voxeo.com' }.to_json
-	  play 'Call recording started!'
-	  play 'Thats it folks!'
-	  execute 'monitor_stop', ''
-	  play 'Recording stopped!'
-	}
-
-	# Related Tropo method: https://www.tropo.com/docs/scripting/record.htm
-	record_prompt_example {
-	  play 'Please record after the beep'
-	  record 'http://tropo-audiofiles-to-s3.heroku.com/post_audio_to_s3?filename=voicemail.mp3',
-	         :silence => 5, 
-	         :maxduration => 120
-	}
-
-	# Allows you to set and retrieve variables on the session
-	# These also get passed as custom SIP headers, prepended with 'x-tropo' when you dial/transfer a call
-	variables_example {
-	  set_variable('foobar', 'green')
-	  ahn_log.debug get_variable('foobar')
-	}
-
-	# We have lots of Asterisk sounds!
-	asterisk_sounds_example {
-	  play 'tt-monkeys'
-	}
-
-	# Allows you to send standard DTMF digits
-	send_dtmf_example {
-	  dtmf '1234567890#*'
-	}
-	
-	# Shows how to set the voice option for speech synthesis/TTS
-	set_voice_example {
-	  play 'Hello world!'
-	  execute "voice", "simon"
-	  play 'Hello world!'
-	  execute "voice", "default"
-	  play 'Hello world!'
-	}
-
-	# Shows how to set the voice option for speech synthesis/TTS
-	set_recognizer_example {
-	  execute "voice", "carmen"
-	  execute "recognizer", "es-es"
-	  result = execute 'ask', { :prompt  => 'Por favor, ingrese su código postal', 
-	                            :choices => 'zipcode([5 DIGITS])' }.to_json
-	  # Get rid of the '200 result =' and then parse the JSON
-	  response = JSON.parse(result[11..-1])
-	  ahn_log.debug response
-	}
-	
-	# Start menu example
-	# Related Tropo method: https://www.tropo.com/docs/scripting/ask.htm
-	menu_example {
-	  menu 'welcome', 'for spanish press 4',
-	       :timeout => 8.seconds, :tries => 3 do |link|
-	    link.shipment_status  1
-	    link.ordering         2
-	    link.representative   3
-	    link.spanish          4
-	    link.employee         500..599
-
-	    link.on_invalid { play 'invalid' }
-
-	    link.on_premature_timeout do |str|
-	      play 'sorry'
-	    end
-
-	    link.on_failure do
-	      play 'goodbye'
-	      hangup
-	    end
-	  end
-	}
-
-	shipment_status {
-	  play 'I surely do not know your shipment status.'
-	}
-
-	ordering {
-	  play 'Go somewhere else and order.'
-	}
-
-	representative {
-	  play 'No representatives here.'
-	}
-
-	spanish {
-	  play 'e 2 brutus?'
-	}
-
-	employee {
-	  play "The person at"
-	  say_digits extension
-	  play "went home for the day."
-	}
-	# End menu example
+  # The main AGI entry point
+  tropo_agi {
+    answer
+    +hello_world
+    hangup
+  }
+
+
+  # Invokes the native Tropo ask for Speech Recognition / ASR
+  # Related Tropo method: https://www.tropo.com/docs/scripting/ask.htm
+  ask_example {
+    result = execute 'ask', { :prompt  => 'Please enter your zip code',
+                              :choices => 'zipcode([5 DIGITS])' }.to_json
+    # Get rid of the '200 result =' and then parse the JSON
+    response = JSON.parse(result[11..-1])
+    ahn_log.debug response
+  }
+
+  # We have lots of Asterisk sounds!
+  asterisk_sounds_example {
+    play 'tt-monkeys'
+  }
+
+  # You may dial other SIP addresses, or telephone numbers as you like
+  # Formats may be:
+  #  SIP/
+  #  sip:
+  #  tel:+
+  # Related Tropo method: https://www.tropo.com/docs/scripting/transfer.htm
+  dial_example {
+    dial 'sip:9991443146@sip.tropo.com'
+  }
+
+  hello_world {
+    play 'tt-monkeys'
+  }
+
+  # Works as input should, only accepting DTMF
+  # Related Tropo method: https://www.tropo.com/docs/scripting/ask.htm
+  input_example {
+    postal_code = input 5, :play         => 'Please enter your post code?',
+                           :timeout      => 2
+
+    ahn_log.postal_code.debug postal_code
+    play "You entered"
+    say_digits postal_code
+  }
+
+  # Find out if this is a Tropo session or an Asterisk one
+  is_tropo? {
+    if type == 'TROPO'
+      play "Yippeee! It is a Tropo call!"
+    else
+      play "No, this is a good old Asterisk call"
+    end
+  }
+
+  # Related Tropo method: https://www.tropo.com/docs/scripting/say.htm
+  say_digits_example {
+    say_digits '12345'
+  }
+
+  # Uses the native Tropo say method for Speech-Synthesis/TTS, will not play Asterisk sound files like play will
+  # Related Tropo method: https://www.tropo.com/docs/scripting/say.htm
+  say_example {
+    execute 'say', { :prompt => 'I like to have weasels in my cloud.', :voice => 'simon' }.to_json
+  }
+
+  # If this is a Tropo call, then all of the SIP headers for the session are available
+  show_call_data {
+    ahn_log.tropo_headers_str.debug tropo_headers
+    tropo_headers = JSON.parse self.tropo_headers
+    ahn_log.tropo_headers_hash.debug tropo_headers
+    play "The content type is " + tropo_headers['Content-Type']
+    +asterisk_sounds_example
+  }
+
+  # Monitor and Mixmonitor behave the same, may also be invoked as startCallRecording
+  # Related Tropo method: https://www.tropo.com/docs/scripting/startcallrecording.htm
+  monitor_example {
+    play 'About to start call recording'
+    execute 'monitor', { :uri                 => 'http://tropo-audiofiles-to-s3.heroku.com/post_audio_to_s3?filename=voicemail.mp3',
+                         :format              => 'mp3',
+                         :method              => 'POST',
+                         :transcriptionOutURI => 'mailto:jsgoecke@voxeo.com' }.to_json
+    play 'Call recording started!'
+    play 'Thats it folks!'
+    execute 'monitor_stop', ''
+    play 'Recording stopped!'
+  }
+
+  # Related Tropo method: https://www.tropo.com/docs/scripting/record.htm
+  record_prompt_example {
+    play 'Please record after the beep'
+    record 'http://tropo-audiofiles-to-s3.heroku.com/post_audio_to_s3?filename=voicemail.mp3',
+           :silence => 5,
+           :maxduration => 120
+  }
+
+  # Allows you to set and retrieve variables on the session
+  # These also get passed as custom SIP headers, prepended with 'x-tropo' when you dial/transfer a call
+  variables_example {
+    set_variable('foobar', 'green')
+    ahn_log.debug get_variable('foobar')
+  }
+
+  # We have lots of Asterisk sounds!
+  asterisk_sounds_example {
+    play 'tt-monkeys'
+  }
+
+  # Allows you to send standard DTMF digits
+  send_dtmf_example {
+    dtmf '1234567890#*'
+  }
+
+  # Shows how to set the voice option for speech synthesis/TTS
+  set_voice_example {
+    play 'Hello world!'
+    execute "voice", "simon"
+    play 'Hello world!'
+    execute "voice", "default"
+    play 'Hello world!'
+  }
+
+  # Shows how to set the voice option for speech synthesis/TTS
+  set_recognizer_example {
+    execute "voice", "carmen"
+    execute "recognizer", "es-es"
+    result = execute 'ask', { :prompt  => 'Por favor, ingrese su código postal',
+                              :choices => 'zipcode([5 DIGITS])' }.to_json
+    # Get rid of the '200 result =' and then parse the JSON
+    response = JSON.parse(result[11..-1])
+    ahn_log.debug response
+  }
+
+  # Start menu example
+  # Related Tropo method: https://www.tropo.com/docs/scripting/ask.htm
+  menu_example {
+    menu 'welcome', 'for spanish press 4',
+         :timeout => 8.seconds, :tries => 3 do |link|
+      link.shipment_status  1
+      link.ordering         2
+      link.representative   3
+      link.spanish          4
+      link.employee         500..599
+
+      link.on_invalid { play 'invalid' }
+
+      link.on_premature_timeout do |str|
+        play 'sorry'
+      end
+
+      link.on_failure do
+        play 'goodbye'
+        hangup
+      end
+    end
+  }
+
+  shipment_status {
+    play 'I surely do not know your shipment status.'
+  }
+
+  ordering {
+    play 'Go somewhere else and order.'
+  }
+
+  representative {
+    play 'No representatives here.'
+  }
+
+  spanish {
+    play 'e 2 brutus?'
+  }
+
+  employee {
+    play "The person at"
+    say_digits extension
+    play "went home for the day."
+  }
+  # End menu example
 
diff --git a/examples/adhearsion_dialplan.rb b/examples/adhearsion_dialplan.rb index 3db1c4b..6c13aa8 100644 --- a/examples/adhearsion_dialplan.rb +++ b/examples/adhearsion_dialplan.rb @@ -9,7 +9,7 @@ # Invokes the native Tropo ask for Speech Recognition / ASR # Related Tropo method: https://www.tropo.com/docs/scripting/ask.htm ask_example { - result = execute 'ask', { :prompt => 'Please enter your zip code', + result = execute 'ask', { :prompt => 'Please enter your zip code', :choices => 'zipcode([5 DIGITS])' }.to_json # Get rid of the '200 result =' and then parse the JSON response = JSON.parse(result[11..-1]) @@ -40,7 +40,7 @@ input_example { postal_code = input 5, :play => 'Please enter your post code?', :timeout => 2 - + ahn_log.postal_code.debug postal_code play "You entered" say_digits postal_code @@ -93,7 +93,7 @@ record_prompt_example { play 'Please record after the beep' record 'http://tropo-audiofiles-to-s3.heroku.com/post_audio_to_s3?filename=voicemail.mp3', - :silence => 5, + :silence => 5, :maxduration => 120 } diff --git a/lib/tropo-agitate.rb b/lib/tropo-agitate.rb index c68e221..d37bfc9 100644 --- a/lib/tropo-agitate.rb +++ b/lib/tropo-agitate.rb @@ -32,9 +32,9 @@ def strip_quotes(text) text.reverse!.chop!.reverse! if text[0] == 34 text end - + private - + ## # Formats the output to the log for consistency # @@ -44,7 +44,7 @@ def strip_quotes(text) def show(str, var) log "====> #{str}: #{var.inspect} <====" end - + ## # Provides the current method's name # @@ -53,13 +53,13 @@ def self.this_method caller[0] # caller[0][/`([^']*)'/, 1] end - + end include Helpers class Commands include Helpers - + ## # Creates an instance of Command # @@ -83,7 +83,7 @@ def initialize(current_call, tropo_agi_config) end @asterisk_sound_files = asterisk_sound_files if @tropo_agi_config['asterisk']['sounds']['enabled'] end - + ## # Initiates an answer to the Tropo call object based on an answer request via AGI # AGI: http://www.voip-info.org/wiki/view/answer @@ -100,7 +100,7 @@ def answer rescue => e log_error(this_method, e) end - + ## # Initiates an ask to the Tropo call object # Tropo: https://www.tropo.com/docs/scripting/ask.htm @@ -110,10 +110,10 @@ def answer # @return [String] the response in AGI raw form def ask(options={}) check_state - + options[:args][:recognizer] = @tropo_recognizer if options[:args]['recognizer'].nil? options[:args][:voice] = @tropo_voice if options[:args]['voice'].nil? - + # Check for Asterisk sounds asterisk_sound_url = fetch_asterisk_sound(options[:args]['prompt']) if asterisk_sound_url @@ -121,7 +121,7 @@ def ask(options={}) else prompt = options[:args]['prompt'] end - + response = @current_call.ask prompt, options[:args] if response.value == 'NO_SPEECH' || response.value == 'NO_MATCH' result = { :interpretation => response.value } @@ -135,12 +135,12 @@ def ask(options={}) rescue => e log_error(this_method, e) end - + ## # Sets the callerid and calleridname params in Tropo # # @param [Hash] the options to be used when setting callerid/calleridname - # + # # @return [String] the response in AGI raw form def callerid(options={}) @user_vars[options[:command].downcase] = options[:args][0] @@ -148,7 +148,7 @@ def callerid(options={}) rescue => e log_error(this_method, e) end - + ## # Initiates a transfer on Tropo which corresopnds as a dial over AGI # AGI: http://www.voip-info.org/wiki/view/Asterisk+cmd+Dial @@ -158,8 +158,8 @@ def callerid(options={}) # # @return [String] the response in AGI raw form def dial(options={}) - check_state - + check_state + destinations = parse_destinations(options[:args]) options = { :callerID => '4155551212' } options['headers'] = set_headers @@ -179,7 +179,7 @@ def dial(options={}) # :timeout => 5, # :choices => '[5 DIGITS]', # :terminator => '#' }.to_json - # + # # ahn_log.postal_code.debug postal_code # play "You entered" # say_digits postal_code @@ -190,18 +190,18 @@ def dial(options={}) # @return [String] the response in AGI raw form def file(options={}) check_state - + @wait_for_digits_options = parse_input_string options[:args][0], 16 if @wait_for_digits_options.nil? options[:args][0] = options[:args][0][0..-15] - + asterisk_sound_url = fetch_asterisk_sound(options[:args][0]) if asterisk_sound_url prompt = asterisk_sound_url else prompt = options[:args][0] end - + response = @current_call.ask prompt, { 'choices' => '[1 DIGIT], *, #', 'choiceMode' => 'keypad' } end show 'File response', response @@ -209,7 +209,7 @@ def file(options={}) rescue => e log_error(this_method, e) end - + ## # Grabs all of the SIP headers off of the current session/call # This is a work around until the $currentCall.getHeaderMap works, currently a bug in the Ruby shim @@ -222,7 +222,7 @@ def getheaders hash.merge!({ :tropo_tag => $tropo_tag }) if $tropo_tag hash end - + ## # Initiates a hangup to the Tropo call object # AGI: http://www.voip-info.org/wiki/view/hangup @@ -235,7 +235,7 @@ def hangup rescue => e log_error(this_method, e) end - + ## # Initiates a conference # AGI: http://www.voip-info.org/wiki/view/Asterisk+cmd+MeetMe @@ -245,7 +245,7 @@ def hangup # @return [String] the response in AGI raw form def meetme(options={}) check_state - + options = options[:args][0].split('|') @current_call.conference options[0].chop @agi_response + "0\n" @@ -253,7 +253,7 @@ def meetme(options={}) log_error(this_method, e) end alias :conference :meetme - + ## # Traps any unknown/unsupported commands and logs an error mesage to the Tropo debugger # @@ -264,10 +264,10 @@ def method_missing(method, *args) show "Invalid or unknown command", args[1] return "510 result=Invalid or unknown Command\n" end - + ## # Initiates a recording of the call - # AGI: + # AGI: # - http://www.voip-info.org/index.php?content_id=3134 # - http://www.voip-info.org/wiki/view/Asterisk+cmd+MixMonitor # Tropo: https://www.tropo.com/docs/scripting/startcallrecording.htm @@ -277,7 +277,7 @@ def method_missing(method, *args) # @return [String] the response in AGI raw form def monitor(options={}) check_state - + @current_call.startCallRecording options[:args]['uri'], options[:args] @agi_response + "0\n" rescue => e @@ -285,7 +285,7 @@ def monitor(options={}) end alias :mixmonitor :monitor alias :startcallrecording :monitor - + ## # Initiates a playback to the Tropo call object for Speech Synthesis/TTS # AGI: http://www.voip-info.org/index.php?content_id=3168 @@ -296,7 +296,7 @@ def monitor(options={}) # @return [String] the response in AGI raw form def playback(options={}) check_state - + asterisk_sound_url = fetch_asterisk_sound(options[:args][0]) if asterisk_sound_url text = asterisk_sound_url @@ -310,7 +310,7 @@ def playback(options={}) end alias :saynumber :playback alias :say :playback - + ## # Used to change the voice being used for speech recognition/ASR # @@ -325,18 +325,18 @@ def recognizer(options={}) end @agi_response + "0\n" end - + ## # Records a user input # AGI: http://www.voip-info.org/index.php?content_id=3176 # Tropo: https://www.tropo.com/docs/scripting/record.htm # # @param [Hash] the options used for the record - # + # # @return [String] the response in AGI raw form def record(options={}) check_state - + options = options[:args][0].split silence_timeout = strip_quotes(options[options.length - 1]).split('=') beep = true if strip_quotes(options[5]) == 'BEEP' @@ -346,27 +346,27 @@ def record(options={}) :recordFormat => strip_quotes(options[1]), :terminator => strip_quotes(options[2]), :beep => beep } - ssml = + ssml = @current_call.record ' ', options @agi_response + "0\n" rescue => e log_error(this_method, e) end - + ## # Provides the ability to redirect a call after it is answered # Tropo: https://www.tropo.com/docs/scripting/redirect.htm # - # @return [String] the response in AGI raw form + # @return [String] the response in AGI raw form def redirect(options={}) check_state - + @current_call.redirect options[:args][0] @agi_response + "0\n" rescue => e log_error(this_method, e) end - + ## # Provides the ability to reject a call before it is answered # Tropo: https://www.tropo.com/docs/scripting/reject.htm @@ -378,9 +378,9 @@ def reject rescue => e log_error(this_method, e) end - + ## - # Provides a RAW say capability + # Provides a RAW say capability # Tropo: https://www.tropo.com/docs/scripting/say.htm # # @param [Hash] options used to build the say @@ -388,13 +388,13 @@ def reject # @return [String] the response in AGI raw form def say(options={}) check_state - + @current_call.say options[:args]['prompt'], options[:args] @agi_response + "0\n" rescue => e log_error(this_method, e) end - + ## # Plays back digits using SSML # AGI: http://www.voip-info.org/index.php?content_id=3182 @@ -404,25 +404,25 @@ def say(options={}) # @return [String] the response in AGI raw form def saydigits(options={}) check_state - + ssml = "#{options[:args][0]}" @current_call.say ssml, :voice => @tropo_voice @agi_response + "0\n" rescue => e log_error(this_method, e) end - + ## # Speaks back individual characters in a string # AGI: http://www.voip-info.org/wiki/index.php?page=Asterisk+cmd+SayPhonetic # Tropo: https://www.tropo.com/docs/scripting/say.htm # # @param [Hash] options used to build the say - # + # # @return [String] the response in AGI raw form def sayphonetic(options={}) check_state - + text = '' options[:args][0].split(//).each do |char| text = text + char + ' ' @@ -432,7 +432,7 @@ def sayphonetic(options={}) rescue => e log_error(this_method, e) end - + ## # ====> TO BE IMPLEMENTED <==== # @@ -445,12 +445,12 @@ def sayphonetic(options={}) # @return [String] the response in AGI raw form def saytime(options={}) check_state - + @agi_response + "0\n" rescue => e log_error(this_method, e) end - + ## # Plays DTMF/touch tone digits to the audio channel # AGI: http://www.voip-info.org/index.php?content_id=3184 @@ -461,7 +461,7 @@ def saytime(options={}) # @return [String] the response in AGI raw form def senddtmf(options={}) check_state - + base_uri = 'http://hosting.tropo.com/49767/www/audio/dtmf/' options[:args][0].split(//).each do |char| case char @@ -477,11 +477,11 @@ def senddtmf(options={}) rescue => e log_error(this_method, e) end - + ## # Returns the current state of the call # AGI: http://www.voip-info.org/wiki/view/channel+status - # + # # @return [String] the AGI response def status(options={}) case @current_call.state @@ -496,15 +496,15 @@ def status(options={}) rescue => e log_error(this_method, e) end - + ## # Returns the current state of the call # AGI: http://www.voip-info.org/wiki/view/channel+status - # + # # @return [String] the AGI response def stopcallrecording(options={}) check_state - + @current_call.stopCallRecording @agi_response + "0\n" rescue => e @@ -512,7 +512,7 @@ def stopcallrecording(options={}) end alias :monitor_stop :stopcallrecording alias :mixmonitor_stop :stopcallrecording - + ## # Handles the storing/retrieving of User Variables associated to the call # AGI: @@ -534,7 +534,7 @@ def user_vars(options={}) rescue => e log_error(this_method, e) end - + ## # Used to change the voice being used for speech synthesis/TTS # @@ -549,19 +549,19 @@ def voice(options={}) end @agi_response + "0\n" end - + ## # Provides the ability to wait a specified period of time # Tropo: https://www.tropo.com/docs/scripting/wait.htm # - # @return [String] the response in AGI raw form + # @return [String] the response in AGI raw form def wait(options={}) @current_call.wait options[:args][0].to_i @agi_response + "0\n" rescue => e log_error(this_method, e) end - + ## # Asks the user to input digits, may work with touch tones or speech recognition/ASR # AGI: http://www.voip-info.org/wiki/view/wait+for+digit @@ -572,12 +572,12 @@ def wait(options={}) # @return [String] the response in AGI raw form def wait_for_digits(options={}) check_state - + if @wait_for_digits_options.nil? timeout = strip_quotes(options[:args][0].split(' ')[1]).to_i timeout = 1000 if timeout == -1 timeout = timeout / 1000 - response = @current_call.ask('', { 'timeout' => timeout, + response = @current_call.ask('', { 'timeout' => timeout, 'choices' => '[1 DIGIT], *, #', 'choiceMode' => 'keypad' }) else @@ -587,7 +587,7 @@ def wait_for_digits(options={}) rescue => e log_error(this_method, e) end - + ## # Builds a hash of the available Asterisk Sound files from a JSON file stored on Tropo # @@ -595,9 +595,9 @@ def wait_for_digits(options={}) def asterisk_sound_files JSON.parse(Net::HTTP.get(URI.parse(@tropo_agi_config['asterisk']['sounds']['available_files']))) end - + private - + ## # Automatically answers the call/session if not explicityly done def check_state @@ -611,7 +611,7 @@ def check_state end true end - + ## # Returns the URI location of the Asterisk sound file if it is available # @@ -622,14 +622,14 @@ def fetch_asterisk_sound(text) text = strip_quotes text if @tropo_agi_config['asterisk']['sounds']['enabled'] if @asterisk_sound_files[text] - return @tropo_agi_config['asterisk']['sounds']['base_uri'] + '/' + - @tropo_agi_config['asterisk']['sounds']['language'] + '/' + + return @tropo_agi_config['asterisk']['sounds']['base_uri'] + '/' + + @tropo_agi_config['asterisk']['sounds']['language'] + '/' + @asterisk_sound_files[text] end end false end - + ## # This is a work around until the $currentCall.getHeaderMap works, currently a bug in the Ruby shim # @@ -638,17 +638,17 @@ def fetch_asterisk_sound(text) # @return [Hash] the converted native Ruby hash def hashmap_to_hash(hashmap) # We get the Java iterator off of the object - iter = hashmap.keySet.iterator + iter = hashmap.keySet.iterator hash = {} - + # We then iterate through the HashMap and build a native Ruby hash - while iter.hasNext - key = iter.next + while iter.hasNext + key = iter.next hash[key] = hashmap.get(key) end hash end - + ## # Logs formatted errors to the Tropo debugger # @@ -661,7 +661,7 @@ def log_error(action, error) show "Error: Unable to execute the #{action} request. call_active?", @current_call.isActive show 'Error output:', error @current_call.log '====> Tropo AGI ACTION ERROR - End <====' - + # Return an error based on the error encountered case error.to_s when '511 result=Command Not Permitted on a dead channel' @@ -670,11 +670,11 @@ def log_error(action, error) @agi_response + "-1\n" end end - + ## # Parses the destinations sent over the AGI protocol into an array of dialable destinations # Also converts the Asterisk style of SIP/ to sip:, the proper SIP URI format - # + # # @param [Array] the unformatted destinations to be parsed from AGI # # @return [Array] an array of destinations @@ -696,7 +696,7 @@ def parse_destinations(destinations) rescue => e show 'parse_destinations method error:', e end - + ## # Parses the STREAM FILE for input to see if it is a JSON string and if so return the Hash # @@ -708,10 +708,10 @@ def parse_input_string(string, leftchop) rescue => e nil end - + ## # ====> SHOULD BE USED TO EXTRACT AND USE THESE OPTIONS LATER <==== - # + # # Removes the options details on the dial string # # @param[String] the destination to strip any extraneous items from @@ -720,7 +720,7 @@ def parse_input_string(string, leftchop) def remove_options(destination) destination.split('"')[0] end - + ## # Preps @user_vars to be set as headers # @@ -733,7 +733,7 @@ def set_headers headers end end#end class Commands - + ## # Creates a new instance of TropoAGItate # @@ -755,10 +755,10 @@ def initialize(current_call, current_app) show 'Session sent to default backup location', 'Now aborting the script' abort end - + ## # Executes the loop that sends and receives the AGI messages to and from the AGI server - # + # # @return [Boolean] whether the socket is open or not def run if create_socket_connection @@ -795,7 +795,7 @@ def create_socket_connection failover(@tropo_agi_config['tropo']['next_sip_uri']) false end - + ## # Closes the socket # @@ -807,7 +807,7 @@ def close_socket end @agi_client.closed? end - + ## # Sends the initial AGI message to the AGI server # AGI: http://www.voip-info.org/wiki/view/Asterisk+AGI @@ -822,7 +822,7 @@ def initial_message(agi_host, agi_port, agi_context) headers = @commands.getheaders rdnis = 'unknown' rdnis = headers['x-sbc-diversion'] if headers['x-sbc-diversion'] - + <<-MSG agi_network: yes agi_network_script: #{agi_context} @@ -844,13 +844,13 @@ def initial_message(agi_host, agi_port, agi_context) agi_extension: 1 agi_priority: 1 agi_enhanced: 0.0 -agi_accountcode: +agi_accountcode: agi_threadid: #{@current_call.id} tropo_headers: #{headers.to_json if headers.keys.length > 0} MSG end - + ## # Executes the given command from AGI to Tropo # @@ -867,7 +867,7 @@ def execute_command(data) if options[:command].downcase == 'variable' @commands.user_vars(options) elsif options[:command].downcase == 'callerid' || options[:command].downcase == 'calleridname' - @commands.callerid(options) + @commands.callerid(options) end when 'exec', 'stream', 'channel' @commands.send(options[:command].downcase.to_sym, options) @@ -880,7 +880,7 @@ def execute_command(data) return "510 result=Invalid or unknown Command\n" end end - + ## # Takes the AGI response from the AGI server, breaks into the arguments # and returns the commands to be executed stripped of quotes @@ -899,7 +899,7 @@ def parse_command(data) show 'command', command command end - + ## # Parses the arguments to strip quotes, put into an array or a hash if JSON # @@ -910,7 +910,7 @@ def parse_args(parts) begin args = JSON.parse strip_quotes(parts.clone) rescue - # Split with a RegEx, since we may have commas inside of elements as well as + # Split with a RegEx, since we may have commas inside of elements as well as # delimitting them elements = parts.split(/(,|\r\n|\n|\r)(?=(?:[^\"]*\"[^\"]*\")*(?![^\"]*\"))/m) # Get rid of the extraneous commas @@ -922,7 +922,7 @@ def parse_args(parts) end args end - + ## # This method fails over to the backup SIP URI or plays the error message if no backup # provided @@ -943,7 +943,7 @@ def failover(location) end end end - + ## # Load the configuration from the current account FTP/WebDAV files of Tropo # @@ -951,16 +951,16 @@ def failover(location) def tropo_agi_config # Find the account number this app is running under account_data = fetch_account_data - + # Try from the www directory on the Tropo file system result = fetch_config_file "/#{account_data[1]}/www/tropo_agi_config/tropo_agi_config.yml" return YAML.load(result.body) if result.code == '200' show 'Can not find config file.', result.body - + # No config file found raise RuntimeError, "Configuration file not found" end - + ## # Fetches the account data # @@ -968,7 +968,7 @@ def tropo_agi_config def fetch_account_data @current_app.baseDir.to_s.match /(\d+)$/ end - + ## # Fetches the configuration file # @@ -981,12 +981,12 @@ def fetch_config_file(resource) http.get resource } end -end#end class TropoAGItate +end#end class TropoAGItate # Are we running as a spec, or is this live? if @tropo_testing.nil? log "====> Running Tropo-AGI <====" - + # If this is an outbound request place the call # see: https://www.tropo.com/docs/scripting/call.htm if $destination @@ -999,15 +999,15 @@ def fetch_config_file(resource) options[:network] = $network || 'SMS' # Time tropo will wait before hanging up, default is 30 options[:timeout] = $timeout if $timeout - + # If voice turn the phone number into a Tel URI, but only if not a SIP URI $destination = 'tel:+' + $destination if options[:channel].downcase == 'voice' && $destination[0..2] != 'sip' - + log "====> Calling to: #{$destination} - with these options: #{options.inspect} <====" # Place the call call $destination, options end - + # If we have an active call, start running the AGI client if $currentCall # Create the instance of TropoAGItate with Tropo's currentCall object diff --git a/lib/tropo.rb b/lib/tropo.rb index 993ffb6..278256d 100644 --- a/lib/tropo.rb +++ b/lib/tropo.rb @@ -12,18 +12,18 @@ def confidence def interpretation '94070' end - + def tag nil end end - + attr_reader :choice - + def initialize @choice = Choice.new end - + def value '94070' end @@ -34,14 +34,14 @@ class CurrentCall attr_reader :value attr_reader :isActive attr_reader :state - + def initialize @value = '94070' @headers = {} @isActive = true @state = 'RINGING' end - + def answer; @state ='ANSWERED'; end def ask(text, options); AskResponse.new; end def callerID; '4155551212'; end @@ -49,12 +49,12 @@ def callerName; 'Jason Goecke'; end def call(text, options); 'call response: ' + text.inspect; p options; end def conference(text); 'conference reponse: ' + text.inspect; end def getHeader(header); @headers[header]; end - + def hangup @isActive = false @state = 'DISCONNECTED' end - + def id; '1234'; end def log(text); text; end def meetme(text, *rest); "meetme: #{text.inspect}, #{rest.inspect}"; end @@ -75,14 +75,14 @@ def getApp 'Application[http://hosting.tropo.com/49767/www/tropo-agi.rb:cus] ver(1.0.45500)' end end - + def self.app GetApp.new end - + def baseDir @cnt = 0 if @cnt.nil? - + # This is only for testing JT!!! if @cnt < 3 @cnt += 1 @@ -97,7 +97,7 @@ def baseDir class IncomingCall include Java - + def getHeaderMap map = java.util.HashMap.new map.put "kermit", "green" diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index e7c476d..d134342 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -7,7 +7,7 @@ # em-spec/rspec Out for now since it is not Rspec 2.x compat RSpec.configure do |config| - + end # NOTE! diff --git a/spec/tropo-agitate_spec.rb b/spec/tropo-agitate_spec.rb index 0209184..ffae64d 100644 --- a/spec/tropo-agitate_spec.rb +++ b/spec/tropo-agitate_spec.rb @@ -5,24 +5,24 @@ before(:all) do # These tests are all local unit tests FakeWeb.allow_net_connect = false - + # Register where we expect our YAML config file to live - FakeWeb.register_uri(:get, "http://hosting.tropo.com/49767/www/tropo_agi_config/tropo_agi_config.yml", + FakeWeb.register_uri(:get, "http://hosting.tropo.com/49767/www/tropo_agi_config/tropo_agi_config.yml", :body => File.open('tropo_agi_config/tropo_agi_config.yml').read) - - # Register the hosted JSON file - FakeWeb.register_uri(:get, "http://hosting.tropo.com/49767/www/audio/asterisk_sounds/asterisk_sounds.json", + + # Register the hosted JSON file + FakeWeb.register_uri(:get, "http://hosting.tropo.com/49767/www/audio/asterisk_sounds/asterisk_sounds.json", :body => '{"tt-monkeys":"tt-monkeys.gsm"}') - + @current_call = CurrentCall.new $incomingCall = IncomingCall.new @tropo_agitate = TropoAGItate.new(@current_call, CurrentApp.new) end - + it "should create a TropoAGItate object" do @tropo_agitate.instance_of?(TropoAGItate).should == true end - + it "should create a properly formatted initial message" do agi_uri = URI.parse @tropo_agitate.tropo_agi_config['agi']['uri_for_local_tests'] message = @tropo_agitate.initial_message(agi_uri.host, agi_uri.port, agi_uri.path[1..-1]) @@ -47,102 +47,102 @@ agi_extension: 1 agi_priority: 1 agi_enhanced: 0.0 -agi_accountcode: +agi_accountcode: agi_threadid: #{@current_call.id} tropo_headers: {\"kermit\":\"green\",\"bigbird\":\"yellow\"} MSG message.should == @initial_message end - + it "should parse arguments stripping quotes" do result = @tropo_agitate.parse_args('"Hello LSRC!"') result[0].should == "Hello LSRC!" - + result = @tropo_agitate.parse_args('"{"prompt":"hi!","timeout":3}"') result.should == { "timeout" => 3, "prompt" => "hi!"} - + result = @tropo_agitate.parse_args('"1234","d",""') - + result[0].should == '1234' result[1].should == 'd' result[3].should == nil end - + it "should strip quotes from a string" do @tropo_agitate.strip_quotes('"foobar"').should == 'foobar' end - + it "should handle commas in non JSON args" do command = @tropo_agitate.parse_command('EXEC playback "Hello, LRSC!"') command.should == { :action => "exec", :command => "playback", :args => ["Hello, LRSC!"] } end - + it "should extract the appropriate commands from AGI" do command = @tropo_agitate.parse_command('ANSWER') command.should == { :action => "answer" } - + command = @tropo_agitate.parse_command('HANGUP') command.should == { :action => "hangup" } - + command = @tropo_agitate.parse_command('EXEC playback "Hello LRSC!"') command.should == { :action => "exec", :command => "playback", :args => ["Hello LRSC!"] } - + command = @tropo_agitate.parse_command('EXEC ask "{"prompt":"hi!","timeout":3}"') command.should == { :command => "ask", :action => "exec", :args => { "timeout" => 3, "prompt" => "hi!"} } - + command = @tropo_agitate.parse_command('EXEC Dial "sip:jsgoecke@yahoo.com","",""') command.should == { :command => "dial", :action => "exec", :args => ["sip:jsgoecke@yahoo.com", "", ""] } - + command = @tropo_agitate.parse_command('EXEC MeetMe "1234","d",""') command.should == { :command => "meetme", :action => "exec", :args => ["1234", "d", ""] } command = @tropo_agitate.parse_command('SET CALLERID "9095551234"') command.should == { :command => "callerid", :action => "set", :args => ["9095551234"] } - + command = @tropo_agitate.parse_command('SET MYVAR "foobar"') command.should == { :command => "myvar", :action => "set", :args => ["foobar"] } - + command = @tropo_agitate.parse_command('GET VARIABLE "myvar"') command.should == { :command => "variable", :action => "get", :args => ["myvar"] } - + command = @tropo_agitate.parse_command('EXEC monitor "{"method":"POST","uri":"http://localhost"}"') command.should == { :command => "monitor", :action => "exec", :args => { 'method' => 'POST', 'uri' => 'http://localhost' } } - + command = @tropo_agitate.parse_command('EXEC mixmonitor "{"method":"POST","uri":"http://localhost"}"') command.should == { :command => "mixmonitor", :action => "exec", :args => { 'method' => 'POST', 'uri' => 'http://localhost' } } end - + it "should execute the command" do command = @tropo_agitate.execute_command('EXEC MeetMe "1234","d",""') command.should == "200 result=0\n" command = @tropo_agitate.execute_command('SET CALLERID "9095551234"') command.should == "200 result=0\n" - + command = @tropo_agitate.execute_command('SET CALLERIDNAME "John Denver"') command.should == "200 result=0\n" - + command = @tropo_agitate.execute_command('GET VARIABLE "CALLERIDNAME"') command.should == "200 result=1 (John Denver)\n" - + command = @tropo_agitate.execute_command('SET VARIABLE FOOBAR "green"') command.should == "200 result=0\n" - + command = @tropo_agitate.execute_command('GET VARIABLE "FOOBAR"') command.should == "200 result=1 (green)\n" - + command = @tropo_agitate.execute_command("EXEC monitor #{{ 'method' => 'POST', 'uri' => 'http://localhost' }.to_json}") command.should == "200 result=0\n" - + command = @tropo_agitate.execute_command('EXEC voice "simon"') command.should == "200 result=0\n" - + command = @tropo_agitate.execute_command('EXEC recognizer "en-us"') command.should == "200 result=0\n" end - + it "should return the account data from a directory lookup" do @tropo_agitate.fetch_account_data[1].should == '49767' @tropo_agitate.fetch_account_data[1].should == '49768' diff --git a/spec/tropo-commands_spec.rb b/spec/tropo-commands_spec.rb index 34d0db1..8c268d2 100644 --- a/spec/tropo-commands_spec.rb +++ b/spec/tropo-commands_spec.rb @@ -1,34 +1,34 @@ require File.expand_path(File.dirname(__FILE__) + '/spec_helper') describe "TropoAGItate::TropoCommands" do - + before(:all) do # These tests are all local unit tests FakeWeb.allow_net_connect = false - + # Register where we expect our YAML config file to live - FakeWeb.register_uri(:get, "http://hosting.tropo.com/49767/www/tropo_agi_config/tropo_agi_config.yml", + FakeWeb.register_uri(:get, "http://hosting.tropo.com/49767/www/tropo_agi_config/tropo_agi_config.yml", :body => File.open('tropo_agi_config/tropo_agi_config.yml').read) - - # Register the hosted JSON file - FakeWeb.register_uri(:get, "http://hosting.tropo.com/49767/www/audio/asterisk_sounds/asterisk_sounds.json", + + # Register the hosted JSON file + FakeWeb.register_uri(:get, "http://hosting.tropo.com/49767/www/audio/asterisk_sounds/asterisk_sounds.json", :body => '{"tt-monkeys":"tt-monkeys.gsm"}') @tropo_agitate = TropoAGItate.new(@current_call, CurrentApp.new) @tropo_commands = TropoAGItate::Commands.new(CurrentCall.new, @tropo_agitate.tropo_agi_config) end - + it "should return the asterisk sound files" do @tropo_commands.asterisk_sound_files.should == { "tt-monkeys" => "tt-monkeys.gsm" } end - + it "should return a valid string on answer" do @tropo_commands.answer.should == "200 result=0\n" end - + it "should return a valid string on hangup" do @tropo_commands.hangup.should == "200 result=1\n" end - + it "should return a valid recognition on ask" do hash = { 'interpretation' => "94070", 'concept' => "zipcode", 'confidence' => "10.0", 'tag' => nil } options = { :command => "ask", :action => "exec", :args => { "timeout" => 3, "prompt" => "hi!"} } @@ -37,22 +37,22 @@ elements[0].should == '200 result' JSON.parse(elements[1]).should == hash end - + it "should return a valid agi response on playback" do options = { :action => "exec", :command => "playback", :args => ["Hello LRSC!"] } @tropo_commands.playback(options).should == "200 result=0\n" end - + it "should generate an error string if we pass an unknown command" do @tropo_commands.foobar.should == "510 result=Invalid or unknown Command\n" @tropo_commands.foobar('fooey').should == "510 result=Invalid or unknown Command\n" end - + it "should return a valid recognition on wait_for_digits" do options = { :action => "wait", :command => "for", :args => ["DIGIT \"-1\""] } @tropo_commands.wait_for_digits(options).should == "200 result=57\n" end - + it "should store and return a user variable" do result = @tropo_commands.user_vars({ :action => 'set', :args => ["\"foobar\" \"green\""]}) result.should == "200 result=0\n" @@ -61,27 +61,27 @@ result = @tropo_commands.user_vars({ :action => 'get', :args => ["\"novar\""]}) result.should == "200 result=-1\n" end - + it "should return a valid string when a dial is requested" do options = { :args => ["\"tel:+14153675082\"|\"\"|\"\""] } @tropo_commands.dial.should == "200 result=0\n" end - + it "should return a valid string when a file is requested" do options = { :args => ["\"hey there!\" \"1234567890*#\""] } @tropo_commands.file(options).should == "200 result=57 endpos=0\n" end - + it "should return a valid string when a meetme is requested" do options = { :args => ["\"1234\"|\"d\"|\"\""] } @tropo_commands.meetme(options).should == "200 result=0\n" end - + it "should return a valid string when we request a record" do options ={ :args => ['"http://tropo-audiofiles-to-s3.heroku.com/post_audio_to_s3?filename=voicemail" "mp3" "#" "120000" "0" "BEEP" "s=5"'] } @tropo_commands.record(options).should == "200 result=0\n" end - + it "should return a valid string when we reqeust a monitor/mixmonitor/startcallrecording" do options = { :args => { "uri" => "http://localhost/post_audio_to_s3?filename=voicemail.mp3", "method" => "POST", @@ -91,18 +91,18 @@ @tropo_commands.mixmonitor(options).should == "200 result=0\n" @tropo_commands.startcallrecording(options).should == "200 result=0\n" end - + it "should return a valid string when we request a stopcallrecording" do @tropo_commands.stopcallrecording.should == "200 result=0\n" @tropo_commands.monitor_stop.should == "200 result=0\n" @tropo_commands.mixmonitor_stop.should == "200 result=0\n" end - + it "should return a valid string when a voice is set" do options = { :args => ["simon"] } @tropo_commands.voice(options).should == "200 result=0\n" end - + it "should return a valid string when a recognizer is set" do options = { :args => ["en-us"] } @tropo_commands.recognizer(options).should == "200 result=0\n" diff --git a/spec/tropo-evented_spec.rb b/spec/tropo-evented_spec.rb index 723a9d2..ccc936e 100644 --- a/spec/tropo-evented_spec.rb +++ b/spec/tropo-evented_spec.rb @@ -7,19 +7,19 @@ before(:all) do # These tests are all local unit tests FakeWeb.allow_net_connect = false - - # Register the hosted JSON file - FakeWeb.register_uri(:get, "http://hosting.tropo.com/49767/www/audio/asterisk_sounds/asterisk_sounds.json", + + # Register the hosted JSON file + FakeWeb.register_uri(:get, "http://hosting.tropo.com/49767/www/audio/asterisk_sounds/asterisk_sounds.json", :body => '{"tt-monkeys":"tt-monkeys.gsm"}') - + @current_call = CurrentCall.new # @tropo_agi = TropoAGItate.new(@current_call, AGI_URI_FOR_LOCAL_TEST, ASTERISK_SOUNDS) end - + it "should execute a series of commands sent by an AGI Server" do pending('ALL OF THESE TESTS ARE PENDING, HAVE SOME STRANGENESS WITH EM AND RSPEC') module AgiServer - + def post_init @commands = [ { :command => 'Initial Session', :response => @initial_message }, { :command => "ANSWER\n", :response => "200 result=0\n" }, @@ -40,7 +40,7 @@ def post_init def receive_data data p data - case data + case data when "commands\n", "commands\r\n" p @commands send_data @commands.to_json + "\n" @@ -63,10 +63,10 @@ def unbind EventMachine::start_server "127.0.0.1", 4573, AgiServer } end - + @tropo_agi.run puts 'blah blah blah blah' - + @commands, @results = nil, nil tcp_client = TCPSocket.new("127.0.0.1", 4573) tcp_client.write("commands\n") @@ -74,7 +74,7 @@ def unbind tcp_client.write("responses\n") @results = JSON.parse(tcp_client.gets.rstrip) tcp_client.close - + @commands.each_with_index do |command, index| command['response'].should == @results[index] end