Class: Tropo::Generator

Inherits:
Object show all
Includes:
Helpers
Defined in:
lib/tropo-webapi-ruby/tropo-webapi-ruby.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeObject #initialize(params) ⇒ Object #initialize(params, &block) ⇒ Object

Initializes the Generator class

Overloads:

  • #initialize(params) ⇒ Object

    Parameters:

    • voice (String)

      sets the value of the default voice

    • pass (Object)

      in an object that may be accessed inside the block

  • #initialize(params, &block) ⇒ Object

    Parameters:

    • pass (Object)

      in an object that may be accessed inside the block

    • voice (String)

      sets the value of the default voice

    • a (Block)

      block of code to execute (optional)



35
36
37
38
39
40
41
42
43
44
45
46
47
# File 'lib/tropo-webapi-ruby/tropo-webapi-ruby.rb', line 35

def initialize(params={}, &block)
  @response = { :tropo => Array.new }
  @voice = params[:voice] if params[:voice]
  @recognizer = params[:recognizer] if params[:recognizer]
  
  if block_given?
    # Lets us know were are in the midst of building a block, so we only rendor the JSON
    # response at the end of executing the block, rather than at each action
    @building = true
    instance_exec(&block)
    render_response
  end
end

Instance Attribute Details

#recognizerObject

Set a couple of Booleans to indicate the session type as a convenience Set a default voice for speech synthesis Set a default recognizer for speech recognition



10
11
12
# File 'lib/tropo-webapi-ruby/tropo-webapi-ruby.rb', line 10

def recognizer
  @recognizer
end

#text_sessionObject (readonly)

Set a couple of Booleans to indicate the session type as a convenience Set a default voice for speech synthesis Set a default recognizer for speech recognition



10
11
12
# File 'lib/tropo-webapi-ruby/tropo-webapi-ruby.rb', line 10

def text_session
  @text_session
end

#voiceObject

Set a couple of Booleans to indicate the session type as a convenience Set a default voice for speech synthesis Set a default recognizer for speech recognition



10
11
12
# File 'lib/tropo-webapi-ruby/tropo-webapi-ruby.rb', line 10

def voice
  @voice
end

#voice_sessionObject (readonly)

Set a couple of Booleans to indicate the session type as a convenience Set a default voice for speech synthesis Set a default recognizer for speech recognition



10
11
12
# File 'lib/tropo-webapi-ruby/tropo-webapi-ruby.rb', line 10

def voice_session
  @voice_session
end

Class Method Details

.method_missing(method_id, *args, &block) ⇒ Object



17
18
19
20
# File 'lib/tropo-webapi-ruby/tropo-webapi-ruby.rb', line 17

def method_missing(method_id, *args, &block)
  g = Generator.new
  g.send(method_id, *args, &block)
end

Instance Method Details

#answer(params) ⇒ String? #answer(params, &block) ⇒ String?

Prompts initiates a new answer.

Overloads:

  • #answer(params) ⇒ String?

    Parameters:

    • params (Hash)

      the options to create a answer action request with.

    Options Hash (params):

    • :headers (optional, Hash)

      A set of key/values

  • #answer(params, &block) ⇒ String?

    Parameters:

    • params (Hash)

      the options to create an answer action request with.

    • takes (Block)

      a block so that you may trigger actions, such as a say, on a specific event

    Options Hash (params):

    • :headers (optional, Hash)

      A set of key/values

Returns:

  • (String, nil)

    the JSON string to be passed back to Tropo or nil if the method has been called from inside a block



152
153
154
155
156
157
158
159
160
161
162
163
164
# File 'lib/tropo-webapi-ruby/tropo-webapi-ruby.rb', line 152

def answer(params={}, &block)
  if block_given?
    create_nested_hash('answer', params)
    instance_exec(&block)
    @response[:tropo] << @nested_hash
    @nested_hash = nil
    @nested_name = nil
  else
    hash = build_action('answer', params)
    @response[:tropo] << hash
  end
  render_response if @building.nil?
end

#ask(params) ⇒ String? #ask(params, &block) ⇒ String? Also known as: prompt

Prompts the user (audio file or text to speech) and optionally waits for a response from the user. If collected, responses may be in the form of DTMF, speech recognition or text using a grammar or free-form text.

Overloads:

  • #ask(params) ⇒ String?

    Parameters:

    • params (Hash)

      the options to create an ask action request with.

    Options Hash (params):

    • :choices (required, Object)

      indicates the structure of the expected data and acceptable modes of input - value, mode, terminator

    • :say (required, Object)

      determines what is played or sent to the caller - also takes an event key to determine if prompt will be played based on a nomatch or timeout

    • :allowSignals (optional, String or Array)

      allows you to assign a signal to ask which can be used with REST to interrupt the function

    • :name (optional, String)

      this is the key used to identify the result of an operation, so you can differentiate between multiple results

    • :attempts (optional, Integer) — default: 1

      the number of times to prompt the user for input

    • :bargein (optional, Boolean) — default: true

      allows a user to say or enter a key to stop the prompt from playing further

    • :interdigitTimeout (optional, Integer) — default: Default: 5.0

      defines how long to wait between key presses to determine the user has stopped entering input

    • :minConfidence (optional, Integer) — default: 30

      the minimum confidence by which to accept the response, as opposed to asking again

    • :required (optional, Boolean) — default: true

      determines whether Tropo should move on to the next verb - if true, Tropo will only move on if the current operation completed

    • :sensitivity (optional, Float) — default: 0.5

      determines how loud or soft audio needs to be before detecting as an attempt to answer the question

    • : (optional, Float)

      speechCompleteTimeout (0.5) determines how long the application should wait - in seconds - after input before determining a match

    • : (optional, Float)

      speechIncompleteTimeout (0.5) determines how long the application should wait - in seconds - after partial input before determining a “no match”

    • :timeout (optional, Integer) — default: 30

      the amount of time, in seconds, to wait for a response before moving on

    • :recognizer (optional, String)

      this tells Tropo what language to listen for

    • :voice (optional, String) — default: allison

      specifies the voice to be used when speaking text to a user

    • :promptLogSecurity (optional, String)

      Controls whether Tropo logs the text to speech string used by the method.

    • :asrLogSecurity (optional, String)

      Control whether Tropo should log the input from the user in response to the ask method.

    • :maskTemplate (optional, String)

      When asrLogSecurity is set to “mask”, this parameter defines the pattern that should be masked.

  • #ask(params, &block) ⇒ String?

    Parameters:

    • params (Hash)

      the options to create an ask action request with.

    • takes (Block)

      a block so that you may trigger actions, such as a say, on a specific event

    Options Hash (params):

    • :choices (required, Object)

      indicates the structure of the expected data and acceptable modes of input - value, mode, terminator

    • :say (required, Object)

      determines what is played or sent to the caller - also takes an event key to determine if prompt will be played based on a nomatch or timeout

    • :allowSignals (optional, String or Array)

      allows you to assign a signal to ask which can be used with REST to interrupt the function

    • :name (optional, String)

      this is the key used to identify the result of an operation, so you can differentiate between multiple results

    • :attempts (optional, Integer) — default: 1

      the number of times to prompt the user for input

    • :bargein (optional, Boolean) — default: true

      allows a user to say or enter a key to stop the prompt from playing further

    • :interdigitTimeout (optional, Integer) — default: Default: 5.0

      defines how long to wait between key presses to determine the user has stopped entering input

    • :minConfidence (optional, Integer) — default: 30

      the minimum confidence by which to accept the response, as opposed to asking again

    • :required (optional, Boolean) — default: true

      determines whether Tropo should move on to the next verb - if true, Tropo will only move on if the current operation completed

    • :sensitivity (optional, Float) — default: 0.5

      determines how loud or soft audio needs to be before detecting as an attempt to answer the question

    • : (optional, Float)

      speechCompleteTimeout (0.5) determines how long the application should wait - in seconds - after input before determining a match

    • : (optional, Float)

      speechIncompleteTimeout (0.5) determines how long the application should wait - in seconds - after partial input before determining a “no match”

    • :timeout (optional, Integer) — default: 30

      the amount of time, in seconds, to wait for a response before moving on

    • :recognizer (optional, String)

      this tells Tropo what language to listen for

    • :voice (optional, String) — default: allison

      specifies the voice to be used when speaking text to a user

    • :promptLogSecurity (optional, String)

      Controls whether Tropo logs the text to speech string used by the method.

    • :asrLogSecurity (optional, String)

      Control whether Tropo should log the input from the user in response to the ask method.

    • :maskTemplate (optional, String)

      When asrLogSecurity is set to “mask”, this parameter defines the pattern that should be masked.

Returns:

  • (String, nil)

    the JSON string to be passed back to Tropo or nil if the method has been called from inside a block



97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
# File 'lib/tropo-webapi-ruby/tropo-webapi-ruby.rb', line 97

def ask(params={}, &block)
  params = set_language(params)
  if block_given?
    @ask_hash = {:ask => build_elements(params)}
    #create_nested_hash('ask', params)
    instance_exec(&block)
    has_params?(@ask_hash[:ask], 'ask', ['choices', 'say'])
    if @nested_on_hash
      if @nested_on_hash[:on][0][:ask].nil?
        @nested_on_hash[:on][0][:ask] = @ask_hash[:ask]
      elsif @nested_on_hash[:on][0][:ask].is_a? Array
        @nested_on_hash[:on][0][:ask] << @ask_hash[:ask]
      else
        ask = @nested_on_hash[:on][0][:ask]
        @nested_on_hash[:on][0][:ask] = Array.new
        @nested_on_hash[:on][0][:ask] << ask
        @nested_on_hash[:on][0][:ask] << @ask_hash[:ask]
      end
    else
      @response[:tropo] << @ask_hash
      @ask_hash = nil
    end
  else
    hash = build_action('ask', params)
    if @nested_on_hash
      if @nested_on_hash[:on][0][:ask].nil?
        @nested_on_hash[:on][0][:ask] = hash[:ask]
      elsif @nested_on_hash[:on][0][:ask].is_a? Array
        @nested_on_hash[:on][0][:ask] << hash[:ask]
      else
        ask = @nested_on_hash[:on][0][:ask]
        @nested_on_hash[:on][0][:ask] = Array.new
        @nested_on_hash[:on][0][:ask] << ask
        @nested_on_hash[:on][0][:ask] << hash[:ask]
      end
    else
      @response[:tropo] << hash
    end
  end
  render_response if @building.nil?
end

#call(params) ⇒ String? #call(params, &block) ⇒ String?

Prompts initiates a new call. May only be used when no call is active.

Overloads:

  • #call(params) ⇒ String?

    Parameters:

    • params (Hash)

      the options to create a call action request with.

    Options Hash (params):

    • :name (required, String)

      this is the key used to identify the result of an operation, so you can differentiate between multiple results

    • :to (required, String or Array)

      the destination of the call, may be a phone number, SMS number or IM address

    • :from (optional, String)

      the phone number or IM address the call will come from

    • :network (optional, String)

      which network the call will be initiated with, such as SMS

    • :channel (optional, String)

      the channel the call will be initiated over, may be TEXT or VOICE

    • :timeout (optional, Float) — default: 30

      the amount of time, in seconds, to wait for a response before moving on

    • :answerOnMedia (optional, Boolean) — default: false

      if true, the call will be concisdered answered and audio will being playing as soon as media is received (ringing, busy, etc)

    • :headers (optional, Hash)

      A set of key/values to apply as customer SIP headers to the outgoing call

    • :machineDetection (optional, Boolean or Hash) — default: false

      determines if a call is coming from machine or human

    • :required (optional, Boolean) — default: true

      determines whether Tropo should move on to the next verb - if true, Tropo will only move on if the current operation completed

    • :allowSignals (optional, String or Array)

      allows you to assign a signal to call which can be used with REST to interrupt the function

    • :voice (optional, String)

      “”(undefined) sets the voice in a call; all prompt action within the call will inherit the same voice defined here

    • :callbackUrl (optional, String)

      Configures a URL for a webhook for CDRs to be sent at the completion of the call.

    • :promptLogSecurity (optional, String)

      Controls whether Tropo logs the text to speech string used by the method.

    • :label (optional, String)

      Set by you, an arbitrary label for this call. The label you set will appear in your CDR, allowing you to track a CDR by a string you define.

  • #call(params, &block) ⇒ String?

    Parameters:

    • params (Hash)

      the options to create an call action request with.

    • takes (Block)

      a block so that you may trigger actions, such as a say, on a specific event

    Options Hash (params):

    • :name (required, String)

      this is the key used to identify the result of an operation, so you can differentiate between multiple results

    • :to (required, String or Array)

      the destination of the call, may be a phone number, SMS number or IM address

    • :from (optional, String)

      the phone number or IM address the call will come from

    • :network (optional, String)

      which network the call will be initiated with, such as SMS

    • :channel (optional, String) — default: voice

      the channel the call will be initiated over, may be TEXT or VOICE

    • :timeout (optional, Float) — default: 30

      the amount of time, in seconds, to wait for a response before moving on

    • :answerOnMedia (optional, Boolean) — default: false

      if true, the call will be concisdered answered and audio will being playing as soon as media is received (ringing, busy, etc)

    • :headers (optional, Hash)

      A set of key/values to apply as customer SIP headers to the outgoing call

    • :machineDetection (optional, Boolean or Hash) — default: false

      determines if a call is coming from machine or human

    • :required (optional, Boolean) — default: true

      determines whether Tropo should move on to the next verb - if true, Tropo will only move on if the current operation completed

    • :allowSignals (optional, String or Array)

      allows you to assign a signal to call which can be used with REST to interrupt the function

    • :voice (optional, String)

      “”(undefined) sets the voice in a call; all prompt action within the call will inherit the same voice defined here

    • :callbackUrl (optional, String)

      Configures a URL for a webhook for CDRs to be sent at the completion of the call.

    • :promptLogSecurity (optional, String)

      Controls whether Tropo logs the text to speech string used by the method.

    • :label (optional, String)

      Set by you, an arbitrary label for this call. The label you set will appear in your CDR, allowing you to track a CDR by a string you define.

Returns:

  • (String, nil)

    the JSON string to be passed back to Tropo or nil if the method has been called from inside a block



207
208
209
210
211
212
213
214
215
216
217
218
219
# File 'lib/tropo-webapi-ruby/tropo-webapi-ruby.rb', line 207

def call(params={}, &block)
  if block_given?
    create_nested_hash('call', params)
    instance_exec(&block)
    @response[:tropo] << @nested_hash
    @nested_hash = nil
    @nested_name = nil
  else
    hash = build_action('call', params)
    @response[:tropo] << hash
  end
  render_response if @building.nil?
end

#choices(params = {}) ⇒ Object

Choices to give the user on input

Parameters:

  • params (Hash) (defaults to: {})

    the options used to construct the grammar for the user

  • [String, (Hash)

    a customizable set of options

Options Hash (params):

  • :value (String)

    this is the grammar which determines the type of expected data, such as [DIGITS]

  • :mode (optional, String) — default: ANY

    the mode to use when asking the user [DTMF, SPEECH or ANY]

  • :terminator (optional, String) — default: #thehe user may enter a keypad entry to stop the request

    #) the user may enter a keypad entry to stop the request



230
231
232
233
234
235
236
237
238
239
240
241
# File 'lib/tropo-webapi-ruby/tropo-webapi-ruby.rb', line 230

def choices(params={})
  hash = build_action('choices', params)
  
  if @ask_hash
    @ask_hash[:ask].merge!(hash)
  elsif @nested_hash
    @nested_hash[@nested_name.to_sym].merge!(hash)
  else
    @response[:tropo] << hash
    render_response if @building.nil?
  end
end

#conference(params) ⇒ String? #conference(params, &block) ⇒ String?

Creates a conference or pushes a user to an existing conference

Overloads:

  • #conference(params) ⇒ String?

    Parameters:

    • params (Hash)

      the options to create a conference with.

    Options Hash (params):

    • :name (required, String)

      this is the key used to identify the result of an operation, so you can differentiate between multiple results

    • :id (required, String)

      the number to assign to the conference room

    • :interdigitTimeout (optional, Float) — default: 5.0

      defines how long to wait between key presses to determine the user has stopped entering input

    • :joinPrompt (optional, Boolean or Hash) — default: false

      determines a prompt that plays to all participants of a conference when someone joins the conference

    • :leavePrompt (optional, Boolean or Hash) — default: false

      determines a prompt that plays to all participants of a conference when someone leaves the conference

    • :mute (optional, Boolean) — default: false

      whether to mute this caller in the conference

    • :playTones (optional, Boolean) — default: false

      whether to allow the DTMF input from a user to play into the conference

    • :terminator (optional, String)

      this is the touch-tone key (DTMF) used to exit the conference

    • :required (optional, Boolean) — default: true

      determines whether Tropo should move on to the next verb - if true, Tropo will only move on if the current operation completed

    • :allowSignals (optional, String or Array)

      allows you to assign a signal to conference which can be used with REST to interrupt the function

    • :promptLogSecurity (optional, String)

      Controls whether Tropo logs the text to speech string used by the method.

  • #conference(params, &block) ⇒ String?

    Parameters:

    • params (Hash)

      the options to create a conference with.

    • takes (Block)

      a block so that you may trigger actions, such as a say, on a specific event

    Options Hash (params):

    • :name (required, String)

      this is the key used to identify the result of an operation, so you can differentiate between multiple results

    • :id (required, String)

      the number to assign to the conference room

    • :interdigitTimeout (optional, Float) — default: 5.0

      defines how long to wait between key presses to determine the user has stopped entering input

    • :joinPrompt (optional, Boolean or Hash) — default: false

      determines a prompt that plays to all participants of a conference when someone joins the conference

    • :leavePrompt (optional, Boolean or Hash) — default: false

      determines a prompt that plays to all participants of a conference when someone leaves the conference

    • :mute (optional, Boolean) — default: false

      whether to mute this caller in the conference

    • :playTones (optional, Boolean) — default: false

      whether to allow the DTMF input from a user to play into the conference

    • :terminator (optional, String)

      this is the touch-tone key (DTMF) used to exit the conference

    • :required (optional, Boolean) — default: true

      determines whether Tropo should move on to the next verb - if true, Tropo will only move on if the current operation completed

    • :allowSignals (optional, String or Array)

      allows you to assign a signal to conference which can be used with REST to interrupt the function

    • :promptLogSecurity (optional, String)

      Controls whether Tropo logs the text to speech string used by the method.

Returns:

  • (String, nil)

    the JSON string to be passed back to Tropo or nil if the method has been called from inside a block



275
276
277
278
279
280
281
282
283
284
285
286
287
# File 'lib/tropo-webapi-ruby/tropo-webapi-ruby.rb', line 275

def conference(params={}, &block)
  if block_given?
    create_nested_hash('conference', params)
    instance_exec(&block)
    @response[:tropo] << @nested_hash
    @nested_hash = nil
    @nested_name = nil
  else
    hash = build_action('conference', params)
    @response[:tropo] << hash
  end
  render_response if @building.nil?
end

#generalLogSecurity(params) ⇒ String? #generalLogSecurity(params, &block) ⇒ String?

that can turn off all logging on the Tropo platform

Overloads:

  • #generalLogSecurity(params) ⇒ String?

    Parameters:

    • params (Hash)

      the options to create a message with.

    Options Hash (params):

    • :state (required, String)

      Set to “suppress” to disable all logging in Tropo. Set to “none” to turn off log suppression and begin logging again.

  • #generalLogSecurity(params, &block) ⇒ String?

    Parameters:

    • params (Hash)

      the options to create a message with.

    • takes (Block)

      a block so that you may trigger actions, such as a say, on a specific event

    Options Hash (params):

    • :state (required, String)

      Set to “suppress” to disable all logging in Tropo. Set to “none” to turn off log suppression and begin logging again.

Returns:

  • (String, nil)

    the JSON string to be passed back to Tropo or nil if the method has been called from inside a block



891
892
893
894
895
896
897
898
899
900
901
# File 'lib/tropo-webapi-ruby/tropo-webapi-ruby.rb', line 891

def generalLogSecurity(params={}, &block)
  if block_given?
    create_nested_hash('generalLogSecurity', params)
    instance_exec(&block)
    @response[:tropo] << @nested_hash
  else
    hash = build_action('generalLogSecurity', params)
    @response[:tropo] << hash
  end
  render_response if @building.nil?
end

#getConceptByActionName(resultactions, actionName) ⇒ String

Returns a String representing the value field ‘concept’ of action named actionName.

Parameters:

  • : (resultactions)

    result object actions

  • : (actionName)

    action name

Returns:

  • (String)

    a String representing the value field ‘concept’ of action named actionName



488
489
490
# File 'lib/tropo-webapi-ruby/tropo-webapi-ruby.rb', line 488

def getConceptByActionName(resultactions, actionName)
  resultactions[actionName]['concept']
end

#getDispositionByActionName(resultactions, actionName) ⇒ String

Returns a String representing the value field ‘disposition’ of action named actionName.

Parameters:

  • : (resultactions)

    result object actions

  • : (actionName)

    action name

Returns:

  • (String)

    a String representing the value field ‘disposition’ of action named actionName



461
462
463
# File 'lib/tropo-webapi-ruby/tropo-webapi-ruby.rb', line 461

def getDispositionByActionName(resultactions, actionName)
  resultactions[actionName]['disposition']
end

#getFieldValueByActionNameFieldName(resultactions, actionName, fieldName) ⇒ String

Returns a String representing the value field of fieldName of action named actionName.

Parameters:

  • : (resultactions)

    result object actions

  • : (actionName)

    action name

  • : (fieldName)

    field name

Returns:

  • (String)

    a String representing the value field of fieldName of action named actionName



498
499
500
# File 'lib/tropo-webapi-ruby/tropo-webapi-ruby.rb', line 498

def getFieldValueByActionNameFieldName(resultactions, actionName, fieldName)
  resultactions[actionName][fieldName]
end

#getInterpretationByActionName(resultactions, actionName) ⇒ String

Returns a String representing the value field ‘interpretation’ of action named actionName.

Parameters:

  • : (resultactions)

    result object actions

  • : (actionName)

    action name

Returns:

  • (String)

    a String representing the value field ‘interpretation’ of action named actionName



470
471
472
# File 'lib/tropo-webapi-ruby/tropo-webapi-ruby.rb', line 470

def getInterpretationByActionName(resultactions, actionName)
  resultactions[actionName]['interpretation']
end

#getUploadStatusByActionName(resultactions, actionName) ⇒ String

Returns a String representing the value field ‘uploadStatus’ of action named actionName.

Parameters:

  • : (resultactions)

    result object actions

  • : (actionName)

    action name

Returns:

  • (String)

    a String representing the value field ‘uploadStatus’ of action named actionName



452
453
454
# File 'lib/tropo-webapi-ruby/tropo-webapi-ruby.rb', line 452

def getUploadStatusByActionName(resultactions, actionName)
  resultactions[actionName]['uploadStatus']
end

#getUtteranceByActionName(resultactions, actionName) ⇒ String

Returns a String representing the value field ‘utterance’ of action named actionName.

Parameters:

  • : (resultactions)

    result object actions

  • : (actionName)

    action name

Returns:

  • (String)

    a String representing the value field ‘utterance’ of action named actionName



479
480
481
# File 'lib/tropo-webapi-ruby/tropo-webapi-ruby.rb', line 479

def getUtteranceByActionName(resultactions, actionName)
  resultactions[actionName]['utterance']
end

#getValueByActionName(resultactions, actionName) ⇒ String

Returns a String representing the value field ‘value’ of action named actionName.

Parameters:

  • : (resultactions)

    result object actions

  • : (actionName)

    action name

Returns:

  • (String)

    a String representing the value field ‘value’ of action named actionName



443
444
445
# File 'lib/tropo-webapi-ruby/tropo-webapi-ruby.rb', line 443

def getValueByActionName(resultactions, actionName)
  resultactions[actionName]['value']
end

#hangupString? Also known as: disconnect

This function instructs Tropo to “hang-up” or disconnect the current session.

May trigger these events:

- hangup
- error

Returns:

  • (String, nil)

    returns the JSON string to hangup/stop the current session or nil if the method has been called from inside a block



297
298
299
300
# File 'lib/tropo-webapi-ruby/tropo-webapi-ruby.rb', line 297

def hangup
  @response[:tropo] << { :hangup => nil }
  render_response if @building.nil? 
end

#message(params) ⇒ String? #message(params, &block) ⇒ String?

Message initiates a new message to a destination and then hangs up on that destination. Also takes a say method in order to deliver a message to that desintation and then hangup.

Overloads:

  • #message(params) ⇒ String?

    Parameters:

    • params (Hash)

      the options to create a message action request with.

    Options Hash (params):

    • :name (required, String)

      this is the key used to identify the result of an operation, so you can differentiate between multiple results

    • :say (required, Object)

      determines what is played or sent to the caller

    • :voice (optional, String) — default: allison

      specifies the voice to be used when speaking text to a user

    • :to (required, String or Array)

      the destination of the call, may be a phone number, SMS number or IM address

    • :from (optional, String)

      the phone number or IM address the call will come from

    • :network (optional, String)

      which network the call will be initiated with, such as SMS

    • :channel (optional, String) — default: VOICE

      the channel the call will be initiated over, may be TEXT or VOICE

    • :timeout (optional, Float) — default: 30

      the amount of time, in seconds, to wait for a response before moving on

    • :required (optional, Boolean) — default: true

      determines whether Tropo should move on to the next verb - if true, Tropo will only move on if the current operation completed

    • :answerOnMedia (optional, Boolean) — default: false

      if true, the call will be concisdered answered and audio will being playing as soon as media is received (ringing, busy, etc)

    • :promptLogSecurity (optional, String)

      Controls whether Tropo logs the text to speech string used by the method. Possible values are “none” (the default) and “suppress”, which disables output logging for this method.

  • #message(params, &block) ⇒ String?

    Parameters:

    • params (Hash)

      the options to create an message action request with.

    • takes (Block)

      a block so that you may trigger actions, such as a say, on a specific event

    Options Hash (params):

    • :name (required, String)

      this is the key used to identify the result of an operation, so you can differentiate between multiple results

    • :say (required, Object)

      determines what is played or sent to the caller

    • :voice (optional, String) — default: allison

      specifies the voice to be used when speaking text to a user

    • :to (required, String or Array)

      the destination of the call, may be a phone number, SMS number or IM address

    • :from (optional, String)

      the phone number or IM address the call will come from

    • :network (optional, String)

      which network the call will be initiated with, such as SMS

    • :channel (optional, String) — default: VOICE

      the channel the call will be initiated over, may be TEXT or VOICE

    • :timeout (optional, Float) — default: 30

      the amount of time, in seconds, to wait for a response before moving on

    • :required (optional, Boolean) — default: true

      determines whether Tropo should move on to the next verb - if true, Tropo will only move on if the current operation completed

    • :answerOnMedia (optional, Boolean) — default: false

      if true, the call will be concisdered answered and audio will being playing as soon as media is received (ringing, busy, etc)

    • :promptLogSecurity (optional, String)

      Controls whether Tropo logs the text to speech string used by the method. Possible values are “none” (the default) and “suppress”, which disables output logging for this method.

Returns:

  • (String, nil)

    the JSON string to be passed back to Tropo or nil if the method has been called from inside a block



336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
# File 'lib/tropo-webapi-ruby/tropo-webapi-ruby.rb', line 336

def message(params={}, &block)
  if block_given?
    @nested_hash = {:message => build_elements(params)}
    @nested_name = 'message'
    instance_exec(&block)
    has_params?(@nested_hash[:message], 'message', ['say', 'to', 'name'])
    @response[:tropo] << @nested_hash
    @nested_hash = nil
    @nested_name = nil
  else
    hash = build_action('message', params)
    @response[:tropo] << hash
  end
  render_response if @building.nil?
end

#initialize(params) ⇒ Object #initialize(params, &block) ⇒ Object

Sets event handlers to call a REST resource when a particular event occurs

Overloads:

  • #initialize(params) ⇒ Object

    Parameters:

    • params (Hash)

      the options to create a message with.

    Options Hash (params):

    • :event (required, String)

      the event name that should trigger the callback

    • :next (optional, String)

      the resource to send the callback to, such as ‘/error.json’

    • :say (optional, String)

      determines what is played or sent to the caller

    • :post (optional, String)

      This parameter is only available in the ‘connect’ event of transfer.

  • #initialize(params, &block) ⇒ Object

    Parameters:

    • params (Hash)

      the options to create a message with.

    • takes (Block)

      a block so that you may trigger actions, such as a say, on a specific event

    Options Hash (params):

    • :event (required, String)

      the event name that should trigger the callback

    • :next (optional, String)

      the resource to send the callback to, such as ‘/error.json’

    • :say (optional, String)

      determines what is played or sent to the caller

    • :post (optional, String)

      This parameter is only available in the ‘connect’ event of transfer.

Parameters:

  • [String, (Hash)

    a customizable set of options



370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
# File 'lib/tropo-webapi-ruby/tropo-webapi-ruby.rb', line 370

def on(params={}, &block)
  if block_given?
    if @nested_hash
      create_nested_on_hash(params)
      instance_exec(&block)
      if @nested_hash[@nested_name.to_sym][:on].nil?
        @nested_hash[@nested_name.to_sym][:on] = Array.new
      end
      @nested_on_hash[:on].each do |hash|
        @nested_hash[@nested_name.to_sym][:on] << hash
      end
      @nested_on_hash = nil
      @nested_on_hash_cnt = nil
    else
      @on_hash = { :on => build_action('on', params)}
      instance_exec(&block)
      @response[:tropo] << @on_hash
      @on_hash = nil
    end
  else
    create_on_hash
    hash = build_action('on', params)
#        @on_hash[:on] << hash
    if @nested_hash
      if @nested_hash[@nested_name.to_sym][:on].nil?
        @nested_hash[@nested_name.to_sym][:on] = Array.new
      end
      @nested_hash[@nested_name.to_sym][:on] << hash
    else
      @on_hash = nil
      @response[:tropo] << { :on => hash }
      render_response if @building.nil?
    end
  end
end

#parse(response) ⇒ Hash

Parses the JSON string recieved from Tropo into a Ruby Hash, or if already a Ruby Hash parses it with the nicities provided by the gem

Parameters:

  • a (String or Hash)

    JSON string or a Ruby Hash

Returns:

  • (Hash)

    a Hash representing the formatted response from Tropo



413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
# File 'lib/tropo-webapi-ruby/tropo-webapi-ruby.rb', line 413

def parse(response)
  response = JSON.parse(response) if response.class == String

  # Check to see what type of response we are working with
  if response['session']
    transformed_response = { 'session' => { } }
    
    response['session'].each_pair do |key, value|
      value = transform_hash value if value.kind_of? Hash
      transformed_response['session'].merge!(transform_pair(key, value))
    end
    
  elsif response['result']
    transformed_response = { 'result' => { } }

    response['result'].each_pair do |key, value|
      value = transform_hash value if value.kind_of? Hash
      value = transform_array value  if value.kind_of? Array
      transformed_response['result'].merge!(transform_pair(key, value))
    end
  end

  transformed_response = Hashie::Mash.new(transformed_response)
end

#record(params) ⇒ Object #record(params, &block) ⇒ Object

Plays a prompt (audio file or text to speech) and optionally waits for a response from the caller that is recorded. If collected, responses may be in the form of DTMF or speech recognition using a simple grammar format defined below. The record funtion is really an alias of the prompt function, but one which forces the record option to true regardless of how it is (or is not) initially set. At the conclusion of the recording, the audio file may be automatically sent to an external server via FTP or an HTTP POST/Multipart Form. If specified, the audio file may also be transcribed and the text returned to you via an email address or HTTP POST/Multipart Form.

Overloads:

  • #record(params) ⇒ Object

    Parameters:

    • params (Hash)

      the options to create a message with.

    Options Hash (params):

    • :attempts (optional, Integer) — default: 1

      the number of times to prompt the user for input

    • :asyncUpload (optional, Boolean) — default: false

      instruct Tropo to upload the recording file in the background as soon as the recording is completed

    • :allowSignals (optional, String or Array)

      allows you to assign a signal to record which can be used with REST to interrupt the function

    • :bargein (optional, Boolean) — default: true

      allows a user to say or enter a key to stop the prompt from playing further

    • :beep (optional, Boolean) — default: true

      when true, callers will hear a tone indicating the recording has begun

    • :choices (optional, Object)

      when used with record, this defines the terminator

    • :say (optional, Object)

      determines what is played or sent to the caller

    • :voice (optional, String) — default: allison

      specifies the voice to be used when speaking text to a user

    • :format (optional, String) — default: audio/wav

      the audio format to record in, either a wav or mp3

    • :maxSilence (optional, Float) — default: 5.0

      the max amount of time in seconds to wait for silence before considering the user finished speaking

    • :maxTime (optional, Float) — default: 30.0

      the max amount of time in seconds the user is allotted for input

    • :method (optional, String) — default: POST

      this defines how to send the audio file, either POST or PUT, and only applies to HTTP

    • :name (required, String)

      this is the key used to identify the result of an operation, so you can differentiate between multiple results

    • :required (optional, Boolean) — default: true

      determines whether Tropo should move on to the next verb - if true, Tropo will only move on if the current operation completed

    • :transcription (optional, Array or Object)

      allows you to submit a recording to be transcribed - takes parameters id, url and emailFormat

    • :url (required, String)

      the destination URL to send the recording, either via FTP or HTTP

    • :username (optional, String)

      if posting to FTP, the username for the FTP server

    • :password (optional, String)

      if posting to FTP, the password for the FTP server

    • :timeout (optional, Float) — default: 30.0

      amount of time Tropo will wait–in seconds and after sending or playing the prompt–for the user to begin a response

    • :interdigitTimeout (optional, Float) — default: 5.0

      defines how long to wait between key presses to determine the user has stopped entering input

    • :promptLogSecurity (optional, String)

      Controls whether Tropo logs the text to speech string used by the method. Possible values are “none” (the default) and “suppress”, which disables output logging for this method.

  • #record(params, &block) ⇒ Object

    Parameters:

    • params (Hash)

      the options to create a message with.

    • takes (Block)

      a block so that you may trigger actions, such as a say, on a specific event

    Options Hash (params):

    • :attempts (optional, Integer) — default: 1

      the number of times to prompt the user for input

    • :asyncUpload (optional, Boolean) — default: false

      instruct Tropo to upload the recording file in the background as soon as the recording is completed

    • :allowSignals (optional, String or Array)

      allows you to assign a signal to record which can be used with REST to interrupt the function

    • :bargein (optional, Boolean) — default: true

      allows a user to say or enter a key to stop the prompt from playing further

    • :beep (optional, Boolean) — default: true

      when true, callers will hear a tone indicating the recording has begun

    • :choices (optional, Object)

      when used with record, this defines the terminator

    • :say (optional, Object)

      determines what is played or sent to the caller

    • :voice (optional, String) — default: allison

      specifies the voice to be used when speaking text to a user

    • :format (optional, String) — default: audio/wav

      the audio format to record in, either a wav or mp3

    • :maxSilence (optional, Float) — default: 5.0

      the max amount of time in seconds to wait for silence before considering the user finished speaking

    • :maxTime (optional, Float) — default: 30.0

      the max amount of time in seconds the user is allotted for input

    • :method (optional, String) — default: POST

      this defines how to send the audio file, either POST or PUT, and only applies to HTTP

    • :name (required, String)

      this is the key used to identify the result of an operation, so you can differentiate between multiple results

    • :required (optional, Boolean) — default: true

      determines whether Tropo should move on to the next verb - if true, Tropo will only move on if the current operation completed

    • :transcription (optional, Array or Object)

      allows you to submit a recording to be transcribed - takes parameters id, url and emailFormat

    • :url (required, String)

      the destination URL to send the recording, either via FTP or HTTP

    • :username (optional, String)

      if posting to FTP, the username for the FTP server

    • :password (optional, String)

      if posting to FTP, the password for the FTP server

    • :timeout (optional, Float) — default: 30.0

      amount of time Tropo will wait–in seconds and after sending or playing the prompt–for the user to begin a response

    • :interdigitTimeout (optional, Float) — default: 5.0

      defines how long to wait between key presses to determine the user has stopped entering input

    • :promptLogSecurity (optional, String)

      Controls whether Tropo logs the text to speech string used by the method. Possible values are “none” (the default) and “suppress”, which disables output logging for this method.

Parameters:

  • [String, (Hash)

    a customizable set of options



566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
# File 'lib/tropo-webapi-ruby/tropo-webapi-ruby.rb', line 566

def record(params={}, &block)
  if block_given?
    @nested_hash = {:record => build_elements(params)}
    @nested_name = 'record'
    instance_exec(&block)
    has_params?(@nested_hash[:record], 'record', ['url'])
    @response[:tropo] << @nested_hash
    @nested_hash = nil
    @nested_name = nil
  else
    hash = build_action('record', params)
    @response[:tropo] << hash
  end
  render_response if @building.nil?
end

#redirect(params = {}) ⇒ String?

The redirect function forwards an incoming SIP call to another destination before answering it. The redirect function must be called before answer is called; redirect expects that a call be in the ringing or answering state. Use transfer when working with active answered calls.

Parameters:

  • params (Hash) (defaults to: {})

    the options to create a message with. @option params [required, String] :name this is the key used to identify the result of an operation, so you can differentiate between multiple results @option params [optional, Boolean] :required (true) determines whether Tropo should move on to the next verb - if true, Tropo will only move on if the current operation completed @option params [required, String] :to where to redirect the session to

Returns:

  • (String, nil)

    the JSON string to redirect the current session or nil if the method has been called from inside a block



594
595
596
597
598
# File 'lib/tropo-webapi-ruby/tropo-webapi-ruby.rb', line 594

def redirect(params={})
  hash = build_action('redirect', params)
  @response[:tropo] << hash
  render_response if @building.nil?
end

#rejectString?

Allows Tropo applications to reject incoming calls before they are answered. For example, an application could inspect the callerID variable to determine if the caller is known, and then use the reject call accordingly.

Returns:

  • (String, nil)

    the JSON string to reject the current session or nil if the method has been called from inside a block



607
608
609
610
# File 'lib/tropo-webapi-ruby/tropo-webapi-ruby.rb', line 607

def reject
  @response[:tropo] << { :reject => nil }
  render_response if @building.nil?
end

#resetnil

Resets the action hash if one desires to reuse the same Generator object

Returns:

  • (nil)


624
625
626
627
628
# File 'lib/tropo-webapi-ruby/tropo-webapi-ruby.rb', line 624

def reset
  @response = { :tropo => Array.new }
  @voice_session = false
  @text_session = false
end

#responseString

Renders the JSON string to be sent to Tropo to execute a set of actions

Returns:

  • (String)

    the JSON string to be sent to the Tropo Remote API



616
617
618
# File 'lib/tropo-webapi-ruby/tropo-webapi-ruby.rb', line 616

def response
  @response.to_json
end

#say(params) ⇒ String? #say(params, &block) ⇒ String?

Plays a prompt (audio file, text to speech or text for IM/SMS). There is no ability to wait for a response from a user. An audio file used for playback may be in one of the following two formats:

Wav 8bit 8khz Ulaw
MP3

Overloads:

  • #say(params) ⇒ String?

    Parameters:

    • params (Hash)

      the options to create a message with.

    Options Hash (params):

    • :value (required, String)

      the text or audio to be spoken or played back to the user

    • :voice (optional, String) — default: allison

      specifies the voice to be used when speaking text to a user

    • :name (required, String)

      this is the key used to identify the result of an operation, so you can differentiate between multiple results

    • :required (optional, Boolean) — default: true

      determines whether Tropo should move on to the next verb - if true, Tropo will only move on if the current operation completed

    • :as (optional, String)

      specifies the type of data being spoken, so the TTS Engine can interpret it correctly. The possible values are “DATE”, “DIGITS” and “NUMBER”

    • :allowSignals (optional, String or Array)

      allows you to assign a signal to say which can be used with REST to interrupt the function

    • :promptLogSecurity (optional, String)

      Controls whether Tropo logs the text to speech string used by the method. Possible values are “none” (the default) and “suppress”, which disables output logging for this method.

  • #say(params, &block) ⇒ String?

    Parameters:

    • params (Hash)

      the options to create a message with.

    • takes (Block)

      a block so that you may trigger actions, such as a say, on a specific event

    Options Hash (params):

    • :value (required, String)

      the text or audio to be spoken or played back to the user

    • :voice (optional, String) — default: allison

      specifies the voice to be used when speaking text to a user

    • :name (required, String)

      this is the key used to identify the result of an operation, so you can differentiate between multiple results

    • :required (optional, Boolean) — default: true

      determines whether Tropo should move on to the next verb - if true, Tropo will only move on if the current operation completed

    • :as (optional, String)

      specifies the type of data being spoken, so the TTS Engine can interpret it correctly. The possible values are “DATE”, “DIGITS” and “NUMBER”

    • :allowSignals (optional, String or Array)

      allows you to assign a signal to say which can be used with REST to interrupt the function

    • :promptLogSecurity (optional, String)

      Controls whether Tropo logs the text to speech string used by the method. Possible values are “none” (the default) and “suppress”, which disables output logging for this method.

Returns:

  • (String, nil)

    the JSON string to be passed back to Tropo or nil if the method has been called from inside a block



657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
# File 'lib/tropo-webapi-ruby/tropo-webapi-ruby.rb', line 657

def say(value=nil, params={})
  
  # This will allow a string to be passed to the say, as opposed to always having to specify a :value key/pair,
  # or still allow a hash or Array to be passed as well
  if value.kind_of? String
    params[:value] = value
  elsif value.kind_of? Hash
    params = value
  elsif value.kind_of? Array
    params = value
  else
    raise ArgumentError, "An invalid paramater type #{value.class} has been passed"
  end
  
  response = { :say => Array.new }

  if params.kind_of? Array
    params.each do |param|
      param = set_language(param)
      hash = build_action('nestedSay', param)
      response[:say] << hash
    end
  else
    params = set_language(params)
    if @on_hash || @ask_hash || @nested_hash
      hash = build_action('nestedSay', params)
    else
      hash = build_action('say', params)
    end
    response = { :say => hash }
  end
  
  if @ask_hash
    if @ask_hash[:ask][:say].nil?
      @ask_hash[:ask][:say] = response[:say]
    elsif @ask_hash[:ask][:say].is_a? Array
      @ask_hash[:ask][:say] << response[:say]
    else
      say = @ask_hash[:ask][:say]
      @ask_hash[:ask][:say] = Array.new
      @ask_hash[:ask][:say] << say
      @ask_hash[:ask][:say] << response[:say]
    end
  elsif @on_hash && @nested_on_hash.nil?
    @on_hash[:on].merge!(response)
  elsif @nested_hash && @nested_on_hash.nil?
    @nested_hash[@nested_name.to_sym].merge!(response)
  elsif @nested_on_hash
    if @nested_on_hash[:on][0][:say].nil?
      @nested_on_hash[:on][0][:say] = response[:say]
    elsif @nested_on_hash[:on][0][:say].is_a? Array
      @nested_on_hash[:on][0][:say] << response[:say]
    else
      say = @nested_on_hash[:on][0][:say]
      @nested_on_hash[:on][0][:say] = Array.new
      @nested_on_hash[:on][0][:say] << say
      @nested_on_hash[:on][0][:say] << response[:say]
    end
#        @nested_on_hash[:on][@nested_on_hash_cnt].merge!(response)
#        @nested_on_hash_cnt += 1
  else
    @response[:tropo] << response
    render_response if @building.nil?
  end
end

#start_recording(params = {}) ⇒ String? Also known as: start_call_recording

Allows Tropo applications to begin recording the current session. The resulting recording may then be sent via FTP or an HTTP POST/Multipart Form.

Parameters:

  • params (Hash) (defaults to: {})

    the options to create a message with.

Options Hash (params):

  • :asyncUpload (optional, Boolean) — default: false

    instruct Tropo to upload the recording file in the background as soon as the recording is completed

  • :url (required, String)

    a valid URI, an HTTP, FTP or email address to POST the recording file to

  • :format (optional, String) — default: audio/wav

    the audio format to record in, either a wav or mp3

  • :username (optional, String)

    if posting to FTP, the username for the FTP server

  • :password (optional, String)

    if posting to FTP, the password for the FTP server

  • :transcriptionEmailFormat (optional, String)

    specifies the encoding used when delivering transcriptions via e-mail

  • :transcriptionID (optional, String)

    determines user definable ID that can be included when the transcription is posted to transcriptionOutURI

  • :transcriptionOutURI (optional, String)

    determines to anything enables transcription on this recording

  • :method (optional, String) — default: POST

    defines how to send the audio file - values are POST or PUT and applies only to HTTP

Returns:

  • (String, nil)

    returns the JSON string to start the recording of a session or nil if the method has been called from inside a block



739
740
741
742
743
744
745
746
747
748
749
750
751
# File 'lib/tropo-webapi-ruby/tropo-webapi-ruby.rb', line 739

def start_recording(params={})
  if block_given?
    create_nested_hash('start_recording', params)
    instance_exec(&block)
    @response[:tropo] << @nested_hash
    @nested_hash = nil
    @nested_name = nil
  else
    hash = build_action('start_recording', params)
    @response[:tropo] << hash
  end
  render_response if @building.nil?
end

#stop_recordingString? Also known as: stop_call_recording

Stops the recording of the current session after startCallRecording has been called

Returns:

  • (String, nil)

    returns the JSON string to stop the recording of a session or nil if the method has been called from inside a block



759
760
761
762
# File 'lib/tropo-webapi-ruby/tropo-webapi-ruby.rb', line 759

def stop_recording
  @response[:tropo] << { :stopRecording => nil }
  render_response if @building.nil?
end

#to_hashHash

Returns the current hash object of the response, as opposed to JSON

Returns:

  • (Hash)

    the current hash of the response



841
842
843
# File 'lib/tropo-webapi-ruby/tropo-webapi-ruby.rb', line 841

def to_hash
  @response
end

#transfer(params) ⇒ nil, String #transfer(params, &block) ⇒ nil, String

Transfers an already answered call to another destination / phone number. Call may be transferred to another phone number or SIP address, which is set through the “to” parameter and is in URL format. Supported formats include:

tel: classic phone number (See RFC 2896), must be proceeded by a + and the country code (ie - +14155551212 for a US #)
sip: SIP protocol address

When this method is called the following occurs:

The audio file specified in playvalue is played to the existing call. This could be "hold music", a ring-back sound, etc. The audio file is played up to playrepeat times.
While audio is playing, a new call is initiated to the specified "to" address using the callerID specified.
If answerOnMedia is true, the audio from the new call is connected to the existing call immediately.
The system waits for an answer or other event from the new call up to the timeout.
If the call successfully completes within the timeout, the existing call and new call will be connected, onSuccess will be called, and the transfer call will return a success event.
If the call fails before the timeout, onCallFailure will be called and the method will return an onCallFailure event.
If the call fails due to the timeout elapsing, onTimeout will be called and the method will return a timeout event

Overloads:

  • #transfer(params) ⇒ nil, String

    Parameters:

    • params (Hash)

      the options to create a transfer action request with

    Options Hash (params):

    • :to (required, String or Array)

      the new destination for the incoming call as a URL

    • :from (optional, String)

      set the from id for the session when redirecting

    • :ringRepeat (optional, Integer) — default: 1

      This specifies the number of times the audio file specified in the ring event will repeat itself.

    • :name (required, String)

      this is the key used to identify the result of an operation, so you can differentiate between multiple results

    • :required (optional, Boolean) — default: true

      determines whether Tropo should move on to the next verb - if true, Tropo will only move on if the current operation completed

    • :timeout (optional, Float) — default: 30

      amount of time Tropo will wait–in seconds–for the other party to answer the call

    • :interdigitTimeout (optional, Float) — default: 5.0

      defines how long to wait between key presses to determine the user has stopped entering input

    • :allowSignals (optional, String or Array)

      allows you to assign a signal to record which can be used with REST to interrupt the function

    • :machineDetection (optional, Boolean or Hash) — default: false

      determines if a call is coming from machine or human

    • :on (optional, Object)

      adds event callback to enable “ring” event, which allows you to play an audio file or say something while the outbound call rings

    • :answerOnMedia (optional, Boolean) — default: false

      if true, the call will be concisdered answered and audio will being playing as soon as media is received (ringing, busy, etc)

    • :headers (optional, Hash)

      A set of key/values to apply as customer SIP headers to the outgoing call

    • :choices (optional, Object)

      when used with transfer, this defines the terminator

    • :playTones (optional, Boolean) — default: true

      Controls whether or not each party can hear the tone generated when a key on the phone is pressed by the other party.

    • :voice (optional, String) — default: allison

      Specifies the default voice to be used when speaking text back to a user.

    • :callbackUrl (optional, String)

      Configures a URL for a webhook for CDRs to be sent at the completion of the call.

    • :promptLogSecurity (optional, String)

      Controls whether Tropo logs the text to speech string used by the method. Possible values are “none” (the default) and “suppress”, which disables output logging for this method

    • :label (optional, String)

      Set by you, an arbitrary label for this call. The label you set will appear in your CDR, allowing you to track a CDR by a string you define

  • #transfer(params, &block) ⇒ nil, String

    Parameters:

    • params (Hash)

      the options to create a transfer action request with

    • takes (Block)

      a block so that you may trigger actions, such as a say, on a specific event

    Options Hash (params):

    • :to (required, String or Array)

      the new destination for the incoming call as a URL

    • :from (optional, String)

      set the from id for the session when redirecting

    • :ringRepeat (optional, Integer) — default: 1

      This specifies the number of times the audio file specified in the ring event will repeat itself.

    • :name (required, String)

      this is the key used to identify the result of an operation, so you can differentiate between multiple results

    • :required (optional, Boolean) — default: true

      determines whether Tropo should move on to the next verb - if true, Tropo will only move on if the current operation completed

    • :timeout (optional, Float) — default: 30

      amount of time Tropo will wait–in seconds–for the other party to answer the call

    • :interdigitTimeout (optional, Float) — default: 5.0

      defines how long to wait between key presses to determine the user has stopped entering input

    • :allowSignals (optional, String or Array)

      allows you to assign a signal to record which can be used with REST to interrupt the function

    • :machineDetection (optional, Boolean or Hash) — default: false

      determines if a call is coming from machine or human

    • :on (optional, Object)

      adds event callback to enable “ring” event, which allows you to play an audio file or say something while the outbound call rings

    • :answerOnMedia (optional, Boolean) — default: false

      if true, the call will be concisdered answered and audio will being playing as soon as media is received (ringing, busy, etc)

    • :headers (optional, Hash)

      A set of key/values to apply as customer SIP headers to the outgoing call

    • :choices (optional, Object)

      when used with transfer, this defines the terminator

    • :playTones (optional, Boolean) — default: true

      Controls whether or not each party can hear the tone generated when a key on the phone is pressed by the other party.

    • :voice (optional, String) — default: allison

      Specifies the default voice to be used when speaking text back to a user.

    • :callbackUrl (optional, String)

      Configures a URL for a webhook for CDRs to be sent at the completion of the call.

    • :promptLogSecurity (optional, String)

      Controls whether Tropo logs the text to speech string used by the method. Possible values are “none” (the default) and “suppress”, which disables output logging for this method

    • :label (optional, String)

      Set by you, an arbitrary label for this call. The label you set will appear in your CDR, allowing you to track a CDR by a string you define

Returns:

  • (nil, String)


823
824
825
826
827
828
829
830
831
832
833
834
835
# File 'lib/tropo-webapi-ruby/tropo-webapi-ruby.rb', line 823

def transfer(params={}, &block)
  if block_given?
    create_nested_hash('transfer', params)
    instance_exec(&block)
    @response[:tropo] << @nested_hash
    @nested_hash = nil
    @nested_name = nil
  else
    hash = build_action('transfer', params)
    @response[:tropo] << hash
  end
  render_response if @building.nil?
end

#wait(params) ⇒ String? #wait(params, &block) ⇒ String?

The wait function suspends the script’s current thread of execution for the specified length of time, or until the active session changes state (such as a user hanging up), whichever occurs first.

Overloads:

  • #wait(params) ⇒ String?

    Parameters:

    • params (Hash)

      the options to create a message with.

    Options Hash (params):

    • :allowSignals (optional, String or Array)

      This parameter allows you to assign a signal to this function.

    • :milliseconds (required, Integer)

      This defines the time to wait for a state change. Defaults to 0ms if the parameter is skipped.

  • #wait(params, &block) ⇒ String?

    Parameters:

    • params (Hash)

      the options to create a message with.

    • takes (Block)

      a block so that you may trigger actions, such as a say, on a specific event

    Options Hash (params):

    • :allowSignals (optional, String or Array)

      This parameter allows you to assign a signal to this function.

    • :milliseconds (required, Integer)

      This defines the time to wait for a state change. Defaults to 0ms if the parameter is skipped.

Returns:

  • (String, nil)

    the JSON string to be passed back to Tropo or nil if the method has been called from inside a block



867
868
869
870
871
872
873
874
875
876
877
# File 'lib/tropo-webapi-ruby/tropo-webapi-ruby.rb', line 867

def wait(params={}, &block)
  if block_given?
    create_nested_hash('wait', params)
    instance_exec(&block)
    @response[:tropo] << @nested_hash
  else
    hash = build_action('wait', params)
    @response[:tropo] << hash
  end
  render_response if @building.nil?
end