tropo-webapi-sdk-ruby 15.10.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/.document +5 -0
- data/LICENSE +21 -0
- data/README.md +249 -0
- data/Rakefile +53 -0
- data/VERSION +1 -0
- data/examples/sinatra_server.rb +194 -0
- data/lib/tropo-webapi-ruby/object_patch.rb +13 -0
- data/lib/tropo-webapi-ruby/tropo-webapi-ruby-helpers.rb +253 -0
- data/lib/tropo-webapi-ruby/tropo-webapi-ruby.rb +903 -0
- data/lib/tropo-webapi-ruby.rb +5 -0
- data/spec/spec.opts +4 -0
- data/spec/spec_helper.rb +7 -0
- data/spec/tropo-webapi-ruby_spec.rb +637 -0
- data/tropo-webapi-ruby.gemspec +58 -0
- metadata +99 -0
@@ -0,0 +1,903 @@
|
|
1
|
+
# @author Jason Goecke
|
2
|
+
module Tropo
|
3
|
+
class Generator
|
4
|
+
include Tropo::Helpers
|
5
|
+
|
6
|
+
##
|
7
|
+
# Set a couple of Booleans to indicate the session type as a convenience
|
8
|
+
# Set a default voice for speech synthesis
|
9
|
+
# Set a default recognizer for speech recognition
|
10
|
+
attr_reader :voice_session, :text_session, :voice, :recognizer
|
11
|
+
|
12
|
+
##
|
13
|
+
# Defines the actions on self so that we may call them individually
|
14
|
+
#
|
15
|
+
# @return [nil]
|
16
|
+
class << self
|
17
|
+
def method_missing(method_id, *args, &block)
|
18
|
+
g = Generator.new
|
19
|
+
g.send(method_id, *args, &block)
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
##
|
24
|
+
# Initializes the Generator class
|
25
|
+
#
|
26
|
+
# @overload initialize()
|
27
|
+
# @overload initialize(params)
|
28
|
+
# @param [String] voice sets the value of the default voice
|
29
|
+
# @param [Object] pass in an object that may be accessed inside the block
|
30
|
+
# @overload initialize(params, &block)
|
31
|
+
# @param [Object] pass in an object that may be accessed inside the block
|
32
|
+
# @param [String] voice sets the value of the default voice
|
33
|
+
# @param [Block] a block of code to execute (optional)
|
34
|
+
# @return [Object] a new Generator object
|
35
|
+
def initialize(params={}, &block)
|
36
|
+
@response = { :tropo => Array.new }
|
37
|
+
@voice = params[:voice] if params[:voice]
|
38
|
+
@recognizer = params[:recognizer] if params[:recognizer]
|
39
|
+
|
40
|
+
if block_given?
|
41
|
+
# Lets us know were are in the midst of building a block, so we only rendor the JSON
|
42
|
+
# response at the end of executing the block, rather than at each action
|
43
|
+
@building = true
|
44
|
+
instance_exec(&block)
|
45
|
+
render_response
|
46
|
+
end
|
47
|
+
end
|
48
|
+
|
49
|
+
##
|
50
|
+
# Prompts the user (audio file or text to speech) and optionally waits for a response from the user.
|
51
|
+
# If collected, responses may be in the form of DTMF, speech recognition or text using a grammar or
|
52
|
+
# free-form text.
|
53
|
+
#
|
54
|
+
# @overload ask(params)
|
55
|
+
# @param [Hash] params the options to create an ask action request with.
|
56
|
+
# @option params [required, Object] :choices indicates the structure of the expected data and acceptable modes of input - value, mode, terminator
|
57
|
+
# @option params [required, Object] :say 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
|
58
|
+
# @option params [optional, String or Array] :allowSignals allows you to assign a signal to ask which can be used with REST to interrupt the function
|
59
|
+
# @option params [optional, String] :name this is the key used to identify the result of an operation, so you can differentiate between multiple results
|
60
|
+
# @option params [optional, Integer] :attempts (1) the number of times to prompt the user for input
|
61
|
+
# @option params [optional, Boolean] :bargein (true) allows a user to say or enter a key to stop the prompt from playing further
|
62
|
+
# @option params [optional, Integer] :interdigitTimeout (Default: 5.0) defines how long to wait between key presses to determine the user has stopped entering input
|
63
|
+
# @option params [optional, Integer] :minConfidence (30) the minimum confidence by which to accept the response, as opposed to asking again
|
64
|
+
# @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
|
65
|
+
# @option params [optional, Float] :sensitivity (0.5) determines how loud or soft audio needs to be before detecting as an attempt to answer the question
|
66
|
+
# @option params [optional, Float]: speechCompleteTimeout (0.5) determines how long the application should wait - in seconds - after input before determining a match
|
67
|
+
# @option params [optional, Float]: speechIncompleteTimeout (0.5) determines how long the application should wait - in seconds - after partial input before determining a "no match"
|
68
|
+
# @option params [optional, Integer] :timeout (30) the amount of time, in seconds, to wait for a response before moving on
|
69
|
+
# @option params [optional, String] :recognizer this tells Tropo what language to listen for
|
70
|
+
# @option params [optional, String] :voice (allison) specifies the voice to be used when speaking text to a user
|
71
|
+
# @option params [optional, String] :promptLogSecurity Controls whether Tropo logs the text to speech string used by the method.
|
72
|
+
# @option params [optional, String] :asrLogSecurity Control whether Tropo should log the input from the user in response to the ask method.
|
73
|
+
# @option params [optional, String] :maskTemplate When asrLogSecurity is set to "mask", this parameter defines the pattern that should be masked.
|
74
|
+
# @overload ask(params, &block)
|
75
|
+
# @param [Hash] params the options to create an ask action request with.
|
76
|
+
# @param [Block] takes a block so that you may trigger actions, such as a say, on a specific event
|
77
|
+
# @option params [required, Object] :choices indicates the structure of the expected data and acceptable modes of input - value, mode, terminator
|
78
|
+
# @option params [required, Object] :say 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
|
79
|
+
# @option params [optional, String or Array] :allowSignals allows you to assign a signal to ask which can be used with REST to interrupt the function
|
80
|
+
# @option params [optional, String] :name this is the key used to identify the result of an operation, so you can differentiate between multiple results
|
81
|
+
# @option params [optional, Integer] :attempts (1) the number of times to prompt the user for input
|
82
|
+
# @option params [optional, Boolean] :bargein (true) allows a user to say or enter a key to stop the prompt from playing further
|
83
|
+
# @option params [optional, Integer] :interdigitTimeout (Default: 5.0) defines how long to wait between key presses to determine the user has stopped entering input
|
84
|
+
# @option params [optional, Integer] :minConfidence (30) the minimum confidence by which to accept the response, as opposed to asking again
|
85
|
+
# @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
|
86
|
+
# @option params [optional, Float] :sensitivity (0.5) determines how loud or soft audio needs to be before detecting as an attempt to answer the question
|
87
|
+
# @option params [optional, Float]: speechCompleteTimeout (0.5) determines how long the application should wait - in seconds - after input before determining a match
|
88
|
+
# @option params [optional, Float]: speechIncompleteTimeout (0.5) determines how long the application should wait - in seconds - after partial input before determining a "no match"
|
89
|
+
# @option params [optional, Integer] :timeout (30) the amount of time, in seconds, to wait for a response before moving on
|
90
|
+
# @option params [optional, String] :recognizer this tells Tropo what language to listen for
|
91
|
+
# @option params [optional, String] :voice (allison) specifies the voice to be used when speaking text to a user
|
92
|
+
# @option params [optional, String] :promptLogSecurity Controls whether Tropo logs the text to speech string used by the method.
|
93
|
+
# @option params [optional, String] :asrLogSecurity Control whether Tropo should log the input from the user in response to the ask method.
|
94
|
+
# @option params [optional, String] :maskTemplate When asrLogSecurity is set to "mask", this parameter defines the pattern that should be masked.
|
95
|
+
# @return [String, nil] the JSON string to be passed back to Tropo or nil
|
96
|
+
# if the method has been called from inside a block
|
97
|
+
def ask(params={}, &block)
|
98
|
+
params = set_language(params)
|
99
|
+
if block_given?
|
100
|
+
@ask_hash = {:ask => build_elements(params)}
|
101
|
+
#create_nested_hash('ask', params)
|
102
|
+
instance_exec(&block)
|
103
|
+
has_params?(@ask_hash[:ask], 'ask', ['choices', 'say'])
|
104
|
+
if @nested_on_hash
|
105
|
+
if @nested_on_hash[:on][0][:ask].nil?
|
106
|
+
@nested_on_hash[:on][0][:ask] = @ask_hash[:ask]
|
107
|
+
elsif @nested_on_hash[:on][0][:ask].is_a? Array
|
108
|
+
@nested_on_hash[:on][0][:ask] << @ask_hash[:ask]
|
109
|
+
else
|
110
|
+
ask = @nested_on_hash[:on][0][:ask]
|
111
|
+
@nested_on_hash[:on][0][:ask] = Array.new
|
112
|
+
@nested_on_hash[:on][0][:ask] << ask
|
113
|
+
@nested_on_hash[:on][0][:ask] << @ask_hash[:ask]
|
114
|
+
end
|
115
|
+
else
|
116
|
+
@response[:tropo] << @ask_hash
|
117
|
+
@ask_hash = nil
|
118
|
+
end
|
119
|
+
else
|
120
|
+
hash = build_action('ask', params)
|
121
|
+
if @nested_on_hash
|
122
|
+
if @nested_on_hash[:on][0][:ask].nil?
|
123
|
+
@nested_on_hash[:on][0][:ask] = hash[:ask]
|
124
|
+
elsif @nested_on_hash[:on][0][:ask].is_a? Array
|
125
|
+
@nested_on_hash[:on][0][:ask] << hash[:ask]
|
126
|
+
else
|
127
|
+
ask = @nested_on_hash[:on][0][:ask]
|
128
|
+
@nested_on_hash[:on][0][:ask] = Array.new
|
129
|
+
@nested_on_hash[:on][0][:ask] << ask
|
130
|
+
@nested_on_hash[:on][0][:ask] << hash[:ask]
|
131
|
+
end
|
132
|
+
else
|
133
|
+
@response[:tropo] << hash
|
134
|
+
end
|
135
|
+
end
|
136
|
+
render_response if @building.nil?
|
137
|
+
end
|
138
|
+
alias :prompt :ask
|
139
|
+
|
140
|
+
##
|
141
|
+
# Prompts initiates a new answer.
|
142
|
+
#
|
143
|
+
# @overload answer(params)
|
144
|
+
# @param [Hash] params the options to create a answer action request with.
|
145
|
+
# @option params [optional, Hash] :headers A set of key/values
|
146
|
+
# @overload answer(params, &block)
|
147
|
+
# @param [Hash] params the options to create an answer action request with.
|
148
|
+
# @param [Block] takes a block so that you may trigger actions, such as a say, on a specific event
|
149
|
+
# @option params [optional, Hash] :headers A set of key/values
|
150
|
+
# @return [String, nil] the JSON string to be passed back to Tropo or nil
|
151
|
+
# if the method has been called from inside a block
|
152
|
+
def answer(params={}, &block)
|
153
|
+
if block_given?
|
154
|
+
create_nested_hash('answer', params)
|
155
|
+
instance_exec(&block)
|
156
|
+
@response[:tropo] << @nested_hash
|
157
|
+
@nested_hash = nil
|
158
|
+
@nested_name = nil
|
159
|
+
else
|
160
|
+
hash = build_action('answer', params)
|
161
|
+
@response[:tropo] << hash
|
162
|
+
end
|
163
|
+
render_response if @building.nil?
|
164
|
+
end
|
165
|
+
|
166
|
+
|
167
|
+
##
|
168
|
+
# Prompts initiates a new call. May only be used when no call is active.
|
169
|
+
#
|
170
|
+
# @overload call(params)
|
171
|
+
# @param [Hash] params the options to create a call action request with.
|
172
|
+
# @option params [required, String] :name this is the key used to identify the result of an operation, so you can differentiate between multiple results
|
173
|
+
# @option params [required, String or Array] :to the destination of the call, may be a phone number, SMS number or IM address
|
174
|
+
# @option params [optional, String] :from the phone number or IM address the call will come from
|
175
|
+
# @option params [optional, String] :network which network the call will be initiated with, such as SMS
|
176
|
+
# @option params [optional, String] :channel the channel the call will be initiated over, may be TEXT or VOICE
|
177
|
+
# @option params [optional, Float] :timeout (30) the amount of time, in seconds, to wait for a response before moving on
|
178
|
+
# @option params [optional, Boolean] :answerOnMedia (false) if true, the call will be concisdered answered and audio will being playing as soon as media is received (ringing, busy, etc)
|
179
|
+
# @option params [optional, Hash] :headers A set of key/values to apply as customer SIP headers to the outgoing call
|
180
|
+
# @option params [optional, Boolean or Hash] :machineDetection (false) determines if a call is coming from machine or human
|
181
|
+
# @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
|
182
|
+
# @option params [optional, String or Array] :allowSignals allows you to assign a signal to call which can be used with REST to interrupt the function
|
183
|
+
# @option params [optional, String] :voice ""(undefined) sets the voice in a call; all prompt action within the call will inherit the same voice defined here
|
184
|
+
# @option params [optional, String] :callbackUrl Configures a URL for a webhook for CDRs to be sent at the completion of the call.
|
185
|
+
# @option params [optional, String] :promptLogSecurity Controls whether Tropo logs the text to speech string used by the method.
|
186
|
+
# @option params [optional, String] :label 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.
|
187
|
+
# @overload call(params, &block)
|
188
|
+
# @param [Hash] params the options to create an call action request with.
|
189
|
+
# @param [Block] takes a block so that you may trigger actions, such as a say, on a specific event
|
190
|
+
# @option params [required, String] :name this is the key used to identify the result of an operation, so you can differentiate between multiple results
|
191
|
+
# @option params [required, String or Array] :to the destination of the call, may be a phone number, SMS number or IM address
|
192
|
+
# @option params [optional, String] :from the phone number or IM address the call will come from
|
193
|
+
# @option params [optional, String] :network which network the call will be initiated with, such as SMS
|
194
|
+
# @option params [optional, String] :channel (voice) the channel the call will be initiated over, may be TEXT or VOICE
|
195
|
+
# @option params [optional, Float] :timeout (30) the amount of time, in seconds, to wait for a response before moving on
|
196
|
+
# @option params [optional, Boolean] :answerOnMedia (false) if true, the call will be concisdered answered and audio will being playing as soon as media is received (ringing, busy, etc)
|
197
|
+
# @option params [optional, Hash] :headers A set of key/values to apply as customer SIP headers to the outgoing call
|
198
|
+
# @option params [optional, Boolean or Hash] :machineDetection (false) determines if a call is coming from machine or human
|
199
|
+
# @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
|
200
|
+
# @option params [optional, String or Array] :allowSignals allows you to assign a signal to call which can be used with REST to interrupt the function
|
201
|
+
# @option params [optional, String] :voice ""(undefined) sets the voice in a call; all prompt action within the call will inherit the same voice defined here
|
202
|
+
# @option params [optional, String] :callbackUrl Configures a URL for a webhook for CDRs to be sent at the completion of the call.
|
203
|
+
# @option params [optional, String] :promptLogSecurity Controls whether Tropo logs the text to speech string used by the method.
|
204
|
+
# @option params [optional, String] :label 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.
|
205
|
+
# @return [String, nil] the JSON string to be passed back to Tropo or nil
|
206
|
+
# if the method has been called from inside a block
|
207
|
+
def call(params={}, &block)
|
208
|
+
if block_given?
|
209
|
+
create_nested_hash('call', params)
|
210
|
+
instance_exec(&block)
|
211
|
+
@response[:tropo] << @nested_hash
|
212
|
+
@nested_hash = nil
|
213
|
+
@nested_name = nil
|
214
|
+
else
|
215
|
+
hash = build_action('call', params)
|
216
|
+
@response[:tropo] << hash
|
217
|
+
end
|
218
|
+
render_response if @building.nil?
|
219
|
+
end
|
220
|
+
|
221
|
+
##
|
222
|
+
# Choices to give the user on input
|
223
|
+
#
|
224
|
+
# @param [Hash] params the options used to construct the grammar for the user
|
225
|
+
# @option params [String] :value this is the grammar which determines the type of expected data, such as [DIGITS]
|
226
|
+
# @option params [optional, String] :mode (ANY) the mode to use when asking the user [DTMF, SPEECH or ANY]
|
227
|
+
# @option params [optional, String] :terminator (#) the user may enter a keypad entry to stop the request
|
228
|
+
# @option [String, nil] the JSON string to be passed back to Tropo or nil
|
229
|
+
# if the method has been called from inside a block
|
230
|
+
def choices(params={})
|
231
|
+
hash = build_action('choices', params)
|
232
|
+
|
233
|
+
if @ask_hash
|
234
|
+
@ask_hash[:ask].merge!(hash)
|
235
|
+
elsif @nested_hash
|
236
|
+
@nested_hash[@nested_name.to_sym].merge!(hash)
|
237
|
+
else
|
238
|
+
@response[:tropo] << hash
|
239
|
+
render_response if @building.nil?
|
240
|
+
end
|
241
|
+
end
|
242
|
+
|
243
|
+
##
|
244
|
+
# Creates a conference or pushes a user to an existing conference
|
245
|
+
#
|
246
|
+
# @overload conference(params)
|
247
|
+
# @param [Hash] params the options to create a conference with.
|
248
|
+
# @option params [required, String] :name this is the key used to identify the result of an operation, so you can differentiate between multiple results
|
249
|
+
# @option params [required, String] :id the number to assign to the conference room
|
250
|
+
# @option params [optional, Float] :interdigitTimeout (5.0) defines how long to wait between key presses to determine the user has stopped entering input
|
251
|
+
# @option params [optional, Boolean or Hash] :joinPrompt (false) determines a prompt that plays to all participants of a conference when someone joins the conference
|
252
|
+
# @option params [optional, Boolean or Hash] :leavePrompt (false) determines a prompt that plays to all participants of a conference when someone leaves the conference
|
253
|
+
# @option params [optional, Boolean] :mute (false) whether to mute this caller in the conference
|
254
|
+
# @option params [optional, Boolean] :playTones (false) whether to allow the DTMF input from a user to play into the conference
|
255
|
+
# @option params [optional, String] :terminator this is the touch-tone key (DTMF) used to exit the conference
|
256
|
+
# @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
|
257
|
+
# @option params [optional, String or Array] :allowSignals allows you to assign a signal to conference which can be used with REST to interrupt the function
|
258
|
+
# @option params [optional, String] :promptLogSecurity Controls whether Tropo logs the text to speech string used by the method.
|
259
|
+
# @overload conference(params, &block)
|
260
|
+
# @param [Hash] params the options to create a conference with.
|
261
|
+
# @param [Block] takes a block so that you may trigger actions, such as a say, on a specific event
|
262
|
+
# @option params [required, String] :name this is the key used to identify the result of an operation, so you can differentiate between multiple results
|
263
|
+
# @option params [required, String] :id the number to assign to the conference room
|
264
|
+
# @option params [optional, Float] :interdigitTimeout (5.0) defines how long to wait between key presses to determine the user has stopped entering input
|
265
|
+
# @option params [optional, Boolean or Hash] :joinPrompt (false) determines a prompt that plays to all participants of a conference when someone joins the conference
|
266
|
+
# @option params [optional, Boolean or Hash] :leavePrompt (false) determines a prompt that plays to all participants of a conference when someone leaves the conference
|
267
|
+
# @option params [optional, Boolean] :mute (false) whether to mute this caller in the conference
|
268
|
+
# @option params [optional, Boolean] :playTones (false) whether to allow the DTMF input from a user to play into the conference
|
269
|
+
# @option params [optional, String] :terminator this is the touch-tone key (DTMF) used to exit the conference
|
270
|
+
# @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
|
271
|
+
# @option params [optional, String or Array] :allowSignals allows you to assign a signal to conference which can be used with REST to interrupt the function
|
272
|
+
# @option params [optional, String] :promptLogSecurity Controls whether Tropo logs the text to speech string used by the method.
|
273
|
+
# @return [String, nil] the JSON string to be passed back to Tropo or nil
|
274
|
+
# if the method has been called from inside a block
|
275
|
+
def conference(params={}, &block)
|
276
|
+
if block_given?
|
277
|
+
create_nested_hash('conference', params)
|
278
|
+
instance_exec(&block)
|
279
|
+
@response[:tropo] << @nested_hash
|
280
|
+
@nested_hash = nil
|
281
|
+
@nested_name = nil
|
282
|
+
else
|
283
|
+
hash = build_action('conference', params)
|
284
|
+
@response[:tropo] << hash
|
285
|
+
end
|
286
|
+
render_response if @building.nil?
|
287
|
+
end
|
288
|
+
|
289
|
+
##
|
290
|
+
# This function instructs Tropo to "hang-up" or disconnect the current session.
|
291
|
+
#
|
292
|
+
# May trigger these events:
|
293
|
+
# - hangup
|
294
|
+
# - error
|
295
|
+
# @return [String, nil] returns the JSON string to hangup/stop the current session or nil
|
296
|
+
# if the method has been called from inside a block
|
297
|
+
def hangup
|
298
|
+
@response[:tropo] << { :hangup => nil }
|
299
|
+
render_response if @building.nil?
|
300
|
+
end
|
301
|
+
alias :disconnect :hangup
|
302
|
+
|
303
|
+
##
|
304
|
+
# Message initiates a new message to a destination and then hangs up on that destination. Also takes a say method
|
305
|
+
# in order to deliver a message to that desintation and then hangup.
|
306
|
+
#
|
307
|
+
# @overload message(params)
|
308
|
+
# @param [Hash] params the options to create a message action request with.
|
309
|
+
# @option params [required, String] :name this is the key used to identify the result of an operation, so you can differentiate between multiple results
|
310
|
+
# @option params [required, Object] :say determines what is played or sent to the caller
|
311
|
+
# @option params [optional, String] :voice (allison) specifies the voice to be used when speaking text to a user
|
312
|
+
# @option params [required, String or Array] :to the destination of the call, may be a phone number, SMS number or IM address
|
313
|
+
# @option params [optional, String] :from the phone number or IM address the call will come from
|
314
|
+
# @option params [optional, String] :network which network the call will be initiated with, such as SMS
|
315
|
+
# @option params [optional, String] :channel (VOICE) the channel the call will be initiated over, may be TEXT or VOICE
|
316
|
+
# @option params [optional, Float] :timeout (30) the amount of time, in seconds, to wait for a response before moving on
|
317
|
+
# @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
|
318
|
+
# @option params [optional, Boolean] :answerOnMedia (false) if true, the call will be concisdered answered and audio will being playing as soon as media is received (ringing, busy, etc)
|
319
|
+
# @option params [optional, String] :promptLogSecurity 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.
|
320
|
+
# @overload message(params, &block)
|
321
|
+
# @param [Hash] params the options to create an message action request with.
|
322
|
+
# @param [Block] takes a block so that you may trigger actions, such as a say, on a specific event
|
323
|
+
# @option params [required, String] :name this is the key used to identify the result of an operation, so you can differentiate between multiple results
|
324
|
+
# @option params [required, Object] :say determines what is played or sent to the caller
|
325
|
+
# @option params [optional, String] :voice (allison) specifies the voice to be used when speaking text to a user
|
326
|
+
# @option params [required, String or Array] :to the destination of the call, may be a phone number, SMS number or IM address
|
327
|
+
# @option params [optional, String] :from the phone number or IM address the call will come from
|
328
|
+
# @option params [optional, String] :network which network the call will be initiated with, such as SMS
|
329
|
+
# @option params [optional, String] :channel (VOICE) the channel the call will be initiated over, may be TEXT or VOICE
|
330
|
+
# @option params [optional, Float] :timeout (30) the amount of time, in seconds, to wait for a response before moving on
|
331
|
+
# @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
|
332
|
+
# @option params [optional, Boolean] :answerOnMedia (false) if true, the call will be concisdered answered and audio will being playing as soon as media is received (ringing, busy, etc)
|
333
|
+
# @option params [optional, String] :promptLogSecurity 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.
|
334
|
+
# @return [String, nil] the JSON string to be passed back to Tropo or nil
|
335
|
+
# if the method has been called from inside a block
|
336
|
+
def message(params={}, &block)
|
337
|
+
if block_given?
|
338
|
+
@nested_hash = {:message => build_elements(params)}
|
339
|
+
@nested_name = 'message'
|
340
|
+
instance_exec(&block)
|
341
|
+
has_params?(@nested_hash[:message], 'message', ['say', 'to', 'name'])
|
342
|
+
@response[:tropo] << @nested_hash
|
343
|
+
@nested_hash = nil
|
344
|
+
@nested_name = nil
|
345
|
+
else
|
346
|
+
hash = build_action('message', params)
|
347
|
+
@response[:tropo] << hash
|
348
|
+
end
|
349
|
+
render_response if @building.nil?
|
350
|
+
end
|
351
|
+
|
352
|
+
##
|
353
|
+
# Sets event handlers to call a REST resource when a particular event occurs
|
354
|
+
#
|
355
|
+
# @overload initialize(params)
|
356
|
+
# @param [Hash] params the options to create a message with.
|
357
|
+
# @option params [required, String] :event the event name that should trigger the callback
|
358
|
+
# @option params [optional, String] :next the resource to send the callback to, such as '/error.json'
|
359
|
+
# @option params [optional, String] :say determines what is played or sent to the caller
|
360
|
+
# @option params [optional, String] :post This parameter is only available in the 'connect' event of transfer.
|
361
|
+
# @overload initialize(params, &block)
|
362
|
+
# @param [Hash] params the options to create a message with.
|
363
|
+
# @param [Block] takes a block so that you may trigger actions, such as a say, on a specific event
|
364
|
+
# @option params [required, String] :event the event name that should trigger the callback
|
365
|
+
# @option params [optional, String] :next the resource to send the callback to, such as '/error.json'
|
366
|
+
# @option params [optional, String] :say determines what is played or sent to the caller
|
367
|
+
# @option params [optional, String] :post This parameter is only available in the 'connect' event of transfer.
|
368
|
+
# @option [String, nil] the JSON string to be passed back to Tropo or nil
|
369
|
+
# if the method has been called from inside a block
|
370
|
+
def on(params={}, &block)
|
371
|
+
if block_given?
|
372
|
+
if @nested_hash
|
373
|
+
create_nested_on_hash(params)
|
374
|
+
instance_exec(&block)
|
375
|
+
if @nested_hash[@nested_name.to_sym][:on].nil?
|
376
|
+
@nested_hash[@nested_name.to_sym][:on] = Array.new
|
377
|
+
end
|
378
|
+
@nested_on_hash[:on].each do |hash|
|
379
|
+
@nested_hash[@nested_name.to_sym][:on] << hash
|
380
|
+
end
|
381
|
+
@nested_on_hash = nil
|
382
|
+
@nested_on_hash_cnt = nil
|
383
|
+
else
|
384
|
+
@on_hash = { :on => build_action('on', params)}
|
385
|
+
instance_exec(&block)
|
386
|
+
@response[:tropo] << @on_hash
|
387
|
+
@on_hash = nil
|
388
|
+
end
|
389
|
+
else
|
390
|
+
create_on_hash
|
391
|
+
hash = build_action('on', params)
|
392
|
+
# @on_hash[:on] << hash
|
393
|
+
if @nested_hash
|
394
|
+
if @nested_hash[@nested_name.to_sym][:on].nil?
|
395
|
+
@nested_hash[@nested_name.to_sym][:on] = Array.new
|
396
|
+
end
|
397
|
+
@nested_hash[@nested_name.to_sym][:on] << hash
|
398
|
+
else
|
399
|
+
@on_hash = nil
|
400
|
+
@response[:tropo] << { :on => hash }
|
401
|
+
render_response if @building.nil?
|
402
|
+
end
|
403
|
+
end
|
404
|
+
end
|
405
|
+
|
406
|
+
##
|
407
|
+
# Parses the JSON string recieved from Tropo into a Ruby Hash, or
|
408
|
+
# if already a Ruby Hash parses it with the nicities provided by
|
409
|
+
# the gem
|
410
|
+
#
|
411
|
+
# @param [String or Hash] a JSON string or a Ruby Hash
|
412
|
+
# @return [Hash] a Hash representing the formatted response from Tropo
|
413
|
+
def parse(response)
|
414
|
+
response = JSON.parse(response) if response.class == String
|
415
|
+
|
416
|
+
# Check to see what type of response we are working with
|
417
|
+
if response['session']
|
418
|
+
transformed_response = { 'session' => { } }
|
419
|
+
|
420
|
+
response['session'].each_pair do |key, value|
|
421
|
+
value = transform_hash value if value.kind_of? Hash
|
422
|
+
transformed_response['session'].merge!(transform_pair(key, value))
|
423
|
+
end
|
424
|
+
|
425
|
+
elsif response['result']
|
426
|
+
transformed_response = { 'result' => { } }
|
427
|
+
|
428
|
+
response['result'].each_pair do |key, value|
|
429
|
+
value = transform_hash value if value.kind_of? Hash
|
430
|
+
value = transform_array value if value.kind_of? Array
|
431
|
+
transformed_response['result'].merge!(transform_pair(key, value))
|
432
|
+
end
|
433
|
+
end
|
434
|
+
|
435
|
+
transformed_response = Hashie::Mash.new(transformed_response)
|
436
|
+
end
|
437
|
+
|
438
|
+
##
|
439
|
+
#
|
440
|
+
# @param [resultactions]: result object actions
|
441
|
+
# @param [actionName]: action name
|
442
|
+
# @return [String] a String representing the value field 'value' of action named actionName
|
443
|
+
def getValueByActionName(resultactions, actionName)
|
444
|
+
resultactions[actionName]['value']
|
445
|
+
end
|
446
|
+
|
447
|
+
##
|
448
|
+
#
|
449
|
+
# @param [resultactions]: result object actions
|
450
|
+
# @param [actionName]: action name
|
451
|
+
# @return [String] a String representing the value field 'uploadStatus' of action named actionName
|
452
|
+
def getUploadStatusByActionName(resultactions, actionName)
|
453
|
+
resultactions[actionName]['uploadStatus']
|
454
|
+
end
|
455
|
+
|
456
|
+
##
|
457
|
+
#
|
458
|
+
# @param [resultactions]: result object actions
|
459
|
+
# @param [actionName]: action name
|
460
|
+
# @return [String] a String representing the value field 'disposition' of action named actionName
|
461
|
+
def getDispositionByActionName(resultactions, actionName)
|
462
|
+
resultactions[actionName]['disposition']
|
463
|
+
end
|
464
|
+
|
465
|
+
##
|
466
|
+
#
|
467
|
+
# @param [resultactions]: result object actions
|
468
|
+
# @param [actionName]: action name
|
469
|
+
# @return [String] a String representing the value field 'interpretation' of action named actionName
|
470
|
+
def getInterpretationByActionName(resultactions, actionName)
|
471
|
+
resultactions[actionName]['interpretation']
|
472
|
+
end
|
473
|
+
|
474
|
+
##
|
475
|
+
#
|
476
|
+
# @param [resultactions]: result object actions
|
477
|
+
# @param [actionName]: action name
|
478
|
+
# @return [String] a String representing the value field 'utterance' of action named actionName
|
479
|
+
def getUtteranceByActionName(resultactions, actionName)
|
480
|
+
resultactions[actionName]['utterance']
|
481
|
+
end
|
482
|
+
|
483
|
+
##
|
484
|
+
#
|
485
|
+
# @param [resultactions]: result object actions
|
486
|
+
# @param [actionName]: action name
|
487
|
+
# @return [String] a String representing the value field 'concept' of action named actionName
|
488
|
+
def getConceptByActionName(resultactions, actionName)
|
489
|
+
resultactions[actionName]['concept']
|
490
|
+
end
|
491
|
+
|
492
|
+
##
|
493
|
+
#
|
494
|
+
# @param [resultactions]: result object actions
|
495
|
+
# @param [actionName]: action name
|
496
|
+
# @param [fieldName]: field name
|
497
|
+
# @return [String] a String representing the value field of fieldName of action named actionName
|
498
|
+
def getFieldValueByActionNameFieldName(resultactions, actionName, fieldName)
|
499
|
+
resultactions[actionName][fieldName]
|
500
|
+
end
|
501
|
+
|
502
|
+
##
|
503
|
+
# Sets the default recognizer for the object
|
504
|
+
#
|
505
|
+
# @param [String] recognizer the value to set the default voice to
|
506
|
+
def recognizer=(recognizer)
|
507
|
+
@recognizer = recognizer
|
508
|
+
end
|
509
|
+
|
510
|
+
##
|
511
|
+
# Plays a prompt (audio file or text to speech) and optionally waits for a response from the caller that is recorded.
|
512
|
+
# If collected, responses may be in the form of DTMF or speech recognition using a simple grammar format defined below.
|
513
|
+
# 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.
|
514
|
+
# 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.
|
515
|
+
# If specified, the audio file may also be transcribed and the text returned to you via an email address or HTTP POST/Multipart Form.
|
516
|
+
#
|
517
|
+
# @overload record(params)
|
518
|
+
# @param [Hash] params the options to create a message with.
|
519
|
+
# @option params [optional, Integer] :attempts (1) the number of times to prompt the user for input
|
520
|
+
# @option params [optional, Boolean] :asyncUpload (false) instruct Tropo to upload the recording file in the background as soon as the recording is completed
|
521
|
+
# @option params [optional, String or Array] :allowSignals allows you to assign a signal to record which can be used with REST to interrupt the function
|
522
|
+
# @option params [optional, Boolean] :bargein (true) allows a user to say or enter a key to stop the prompt from playing further
|
523
|
+
# @option params [optional, Boolean] :beep (true) when true, callers will hear a tone indicating the recording has begun
|
524
|
+
# @option params [optional, Object] :choices when used with record, this defines the terminator
|
525
|
+
# @option params [optional, Object] :say determines what is played or sent to the caller
|
526
|
+
# @option params [optional, String] :voice (allison) specifies the voice to be used when speaking text to a user
|
527
|
+
# @option params [optional, String] :format (audio/wav) the audio format to record in, either a wav or mp3
|
528
|
+
# @option params [optional, Float] :maxSilence (5.0) the max amount of time in seconds to wait for silence before considering the user finished speaking
|
529
|
+
# @option params [optional, Float] :maxTime (30.0) the max amount of time in seconds the user is allotted for input
|
530
|
+
# @option params [optional, String] :method (POST) this defines how to send the audio file, either POST or PUT, and only applies to HTTP
|
531
|
+
# @option params [required, String] :name this is the key used to identify the result of an operation, so you can differentiate between multiple results
|
532
|
+
# @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
|
533
|
+
# @option params [optional, Array or Object] :transcription allows you to submit a recording to be transcribed - takes parameters id, url and emailFormat
|
534
|
+
# @option params [required, String] :url the destination URL to send the recording, either via FTP or HTTP
|
535
|
+
# @option params [optional, String] :username if posting to FTP, the username for the FTP server
|
536
|
+
# @option params [optional, String] :password if posting to FTP, the password for the FTP server
|
537
|
+
# @option params [optional, Float] :timeout (30.0) amount of time Tropo will wait--in seconds and after sending or playing the prompt--for the user to begin a response
|
538
|
+
# @option params [optional, Float] :interdigitTimeout (5.0) defines how long to wait between key presses to determine the user has stopped entering input
|
539
|
+
# @option params [optional, String] :promptLogSecurity 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.
|
540
|
+
# @overload record(params, &block)
|
541
|
+
# @param [Hash] params the options to create a message with.
|
542
|
+
# @param [Block] takes a block so that you may trigger actions, such as a say, on a specific event
|
543
|
+
# @option params [optional, Integer] :attempts (1) the number of times to prompt the user for input
|
544
|
+
# @option params [optional, Boolean] :asyncUpload (false) instruct Tropo to upload the recording file in the background as soon as the recording is completed
|
545
|
+
# @option params [optional, String or Array] :allowSignals allows you to assign a signal to record which can be used with REST to interrupt the function
|
546
|
+
# @option params [optional, Boolean] :bargein (true) allows a user to say or enter a key to stop the prompt from playing further
|
547
|
+
# @option params [optional, Boolean] :beep (true) when true, callers will hear a tone indicating the recording has begun
|
548
|
+
# @option params [optional, Object] :choices when used with record, this defines the terminator
|
549
|
+
# @option params [optional, Object] :say determines what is played or sent to the caller
|
550
|
+
# @option params [optional, String] :voice (allison) specifies the voice to be used when speaking text to a user
|
551
|
+
# @option params [optional, String] :format (audio/wav) the audio format to record in, either a wav or mp3
|
552
|
+
# @option params [optional, Float] :maxSilence (5.0) the max amount of time in seconds to wait for silence before considering the user finished speaking
|
553
|
+
# @option params [optional, Float] :maxTime (30.0) the max amount of time in seconds the user is allotted for input
|
554
|
+
# @option params [optional, String] :method (POST) this defines how to send the audio file, either POST or PUT, and only applies to HTTP
|
555
|
+
# @option params [required, String] :name this is the key used to identify the result of an operation, so you can differentiate between multiple results
|
556
|
+
# @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
|
557
|
+
# @option params [optional, Array or Object] :transcription allows you to submit a recording to be transcribed - takes parameters id, url and emailFormat
|
558
|
+
# @option params [required, String] :url the destination URL to send the recording, either via FTP or HTTP
|
559
|
+
# @option params [optional, String] :username if posting to FTP, the username for the FTP server
|
560
|
+
# @option params [optional, String] :password if posting to FTP, the password for the FTP server
|
561
|
+
# @option params [optional, Float] :timeout (30.0) amount of time Tropo will wait--in seconds and after sending or playing the prompt--for the user to begin a response
|
562
|
+
# @option params [optional, Float] :interdigitTimeout (5.0) defines how long to wait between key presses to determine the user has stopped entering input
|
563
|
+
# @option params [optional, String] :promptLogSecurity 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.
|
564
|
+
# @option [String, nil] the JSON string to be passed back to Tropo or nil
|
565
|
+
# if the method has been called from inside a block
|
566
|
+
def record(params={}, &block)
|
567
|
+
if block_given?
|
568
|
+
create_nested_hash('record', params)
|
569
|
+
instance_exec(&block)
|
570
|
+
@response[:tropo] << @nested_hash
|
571
|
+
@nested_hash = nil
|
572
|
+
@nested_name = nil
|
573
|
+
else
|
574
|
+
hash = build_action('record', params)
|
575
|
+
@response[:tropo] << hash
|
576
|
+
end
|
577
|
+
render_response if @building.nil?
|
578
|
+
end
|
579
|
+
|
580
|
+
##
|
581
|
+
# The redirect function forwards an incoming SIP call to another destination before answering it.
|
582
|
+
# The redirect function must be called before answer is called; redirect expects that a call be in the ringing or answering state.
|
583
|
+
# Use transfer when working with active answered calls.
|
584
|
+
#
|
585
|
+
#
|
586
|
+
# @param [Hash] params the options to create a message with.
|
587
|
+
# @option params [required, String] :name this is the key used to identify the result of an operation, so you can differentiate between multiple results
|
588
|
+
# @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
|
589
|
+
# @option params [required, String] :to where to redirect the session to
|
590
|
+
# @return [String, nil] the JSON string to redirect the current session or nil
|
591
|
+
# if the method has been called from inside a block
|
592
|
+
def redirect(params={})
|
593
|
+
hash = build_action('redirect', params)
|
594
|
+
@response[:tropo] << hash
|
595
|
+
render_response if @building.nil?
|
596
|
+
end
|
597
|
+
|
598
|
+
##
|
599
|
+
# Allows Tropo applications to reject incoming calls before they are answered.
|
600
|
+
# For example, an application could inspect the callerID variable to determine if the caller is known,
|
601
|
+
# and then use the reject call accordingly.
|
602
|
+
#
|
603
|
+
# @return [String, nil] the JSON string to reject the current session or nil
|
604
|
+
# if the method has been called from inside a block
|
605
|
+
def reject
|
606
|
+
@response[:tropo] << { :reject => nil }
|
607
|
+
render_response if @building.nil?
|
608
|
+
end
|
609
|
+
|
610
|
+
##
|
611
|
+
# Renders the JSON string to be sent to Tropo to execute a set of actions
|
612
|
+
#
|
613
|
+
# @return [String] the JSON string to be sent to the Tropo Remote API
|
614
|
+
def response
|
615
|
+
@response.to_json
|
616
|
+
end
|
617
|
+
|
618
|
+
##
|
619
|
+
# Resets the action hash if one desires to reuse the same Generator object
|
620
|
+
#
|
621
|
+
# @return [nil]
|
622
|
+
def reset
|
623
|
+
@response = { :tropo => Array.new }
|
624
|
+
@voice_session = false
|
625
|
+
@text_session = false
|
626
|
+
end
|
627
|
+
|
628
|
+
##
|
629
|
+
# 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.
|
630
|
+
# An audio file used for playback may be in one of the following two formats:
|
631
|
+
# Wav 8bit 8khz Ulaw
|
632
|
+
# MP3
|
633
|
+
#
|
634
|
+
# @overload say(params)
|
635
|
+
# @param [Hash] params the options to create a message with.
|
636
|
+
# @option params [required, String] :value the text or audio to be spoken or played back to the user
|
637
|
+
# @option params [optional, String] :voice (allison) specifies the voice to be used when speaking text to a user
|
638
|
+
# @option params [required, String] :name this is the key used to identify the result of an operation, so you can differentiate between multiple results
|
639
|
+
# @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
|
640
|
+
# @option params [optional, String] :as specifies the type of data being spoken, so the TTS Engine can interpret it correctly. The possible values are "DATE", "DIGITS" and "NUMBER"
|
641
|
+
# @option params [optional, String or Array] :allowSignals allows you to assign a signal to say which can be used with REST to interrupt the function
|
642
|
+
# @option params [optional, String] :promptLogSecurity 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.
|
643
|
+
# @overload say(params, &block)
|
644
|
+
# @param [Hash] params the options to create a message with.
|
645
|
+
# @param [Block] takes a block so that you may trigger actions, such as a say, on a specific event
|
646
|
+
# @option params [required, String] :value the text or audio to be spoken or played back to the user
|
647
|
+
# @option params [optional, String] :voice (allison) specifies the voice to be used when speaking text to a user
|
648
|
+
# @option params [required, String] :name this is the key used to identify the result of an operation, so you can differentiate between multiple results
|
649
|
+
# @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
|
650
|
+
# @option params [optional, String] :as specifies the type of data being spoken, so the TTS Engine can interpret it correctly. The possible values are "DATE", "DIGITS" and "NUMBER"
|
651
|
+
# @option params [optional, String or Array] :allowSignals allows you to assign a signal to say which can be used with REST to interrupt the function
|
652
|
+
# @option params [optional, String] :promptLogSecurity 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.
|
653
|
+
# @return [String, nil] the JSON string to be passed back to Tropo or nil
|
654
|
+
# if the method has been called from inside a block
|
655
|
+
def say(value=nil, params={})
|
656
|
+
|
657
|
+
# This will allow a string to be passed to the say, as opposed to always having to specify a :value key/pair,
|
658
|
+
# or still allow a hash or Array to be passed as well
|
659
|
+
if value.kind_of? String
|
660
|
+
params[:value] = value
|
661
|
+
elsif value.kind_of? Hash
|
662
|
+
params = value
|
663
|
+
elsif value.kind_of? Array
|
664
|
+
params = value
|
665
|
+
else
|
666
|
+
raise ArgumentError, "An invalid paramater type #{value.class} has been passed"
|
667
|
+
end
|
668
|
+
|
669
|
+
response = { :say => Array.new }
|
670
|
+
|
671
|
+
if params.kind_of? Array
|
672
|
+
params.each do |param|
|
673
|
+
param = set_language(param)
|
674
|
+
hash = build_action('nestedSay', param)
|
675
|
+
response[:say] << hash
|
676
|
+
end
|
677
|
+
else
|
678
|
+
params = set_language(params)
|
679
|
+
if @on_hash || @ask_hash || @nested_hash
|
680
|
+
hash = build_action('nestedSay', params)
|
681
|
+
else
|
682
|
+
hash = build_action('say', params)
|
683
|
+
end
|
684
|
+
response = { :say => hash }
|
685
|
+
end
|
686
|
+
|
687
|
+
if @ask_hash
|
688
|
+
if @ask_hash[:ask][:say].nil?
|
689
|
+
@ask_hash[:ask][:say] = response[:say]
|
690
|
+
elsif @ask_hash[:ask][:say].is_a? Array
|
691
|
+
@ask_hash[:ask][:say] << response[:say]
|
692
|
+
else
|
693
|
+
say = @ask_hash[:ask][:say]
|
694
|
+
@ask_hash[:ask][:say] = Array.new
|
695
|
+
@ask_hash[:ask][:say] << say
|
696
|
+
@ask_hash[:ask][:say] << response[:say]
|
697
|
+
end
|
698
|
+
elsif @on_hash && @nested_on_hash.nil?
|
699
|
+
@on_hash[:on].merge!(response)
|
700
|
+
elsif @nested_hash && @nested_on_hash.nil?
|
701
|
+
@nested_hash[@nested_name.to_sym].merge!(response)
|
702
|
+
elsif @nested_on_hash
|
703
|
+
if @nested_on_hash[:on][0][:say].nil?
|
704
|
+
@nested_on_hash[:on][0][:say] = response[:say]
|
705
|
+
elsif @nested_on_hash[:on][0][:say].is_a? Array
|
706
|
+
@nested_on_hash[:on][0][:say] << response[:say]
|
707
|
+
else
|
708
|
+
say = @nested_on_hash[:on][0][:say]
|
709
|
+
@nested_on_hash[:on][0][:say] = Array.new
|
710
|
+
@nested_on_hash[:on][0][:say] << say
|
711
|
+
@nested_on_hash[:on][0][:say] << response[:say]
|
712
|
+
end
|
713
|
+
# @nested_on_hash[:on][@nested_on_hash_cnt].merge!(response)
|
714
|
+
# @nested_on_hash_cnt += 1
|
715
|
+
else
|
716
|
+
@response[:tropo] << response
|
717
|
+
render_response if @building.nil?
|
718
|
+
end
|
719
|
+
end
|
720
|
+
|
721
|
+
##
|
722
|
+
# Allows Tropo applications to begin recording the current session.
|
723
|
+
# The resulting recording may then be sent via FTP or an HTTP POST/Multipart Form.
|
724
|
+
#
|
725
|
+
# @param [Hash] params the options to create a message with.
|
726
|
+
# @option params [optional, Boolean] :asyncUpload (false) instruct Tropo to upload the recording file in the background as soon as the recording is completed
|
727
|
+
# @option params [required, String] :url a valid URI, an HTTP, FTP or email address to POST the recording file to
|
728
|
+
# @option params [optional, String] :format (audio/wav) the audio format to record in, either a wav or mp3
|
729
|
+
# @option params [optional, String] :username if posting to FTP, the username for the FTP server
|
730
|
+
# @option params [optional, String] :password if posting to FTP, the password for the FTP server
|
731
|
+
# @option params [optional, String] :transcriptionEmailFormat specifies the encoding used when delivering transcriptions via e-mail
|
732
|
+
# @option params [optional, String] :transcriptionID determines user definable ID that can be included when the transcription is posted to transcriptionOutURI
|
733
|
+
# @option params [optional, String] :transcriptionOutURI determines to anything enables transcription on this recording
|
734
|
+
# @option params [optional, String] :method (POST) defines how to send the audio file - values are POST or PUT and applies only to HTTP
|
735
|
+
# @return [String, nil] returns the JSON string to start the recording of a session or nil
|
736
|
+
# if the method has been called from inside a block
|
737
|
+
def start_recording(params={})
|
738
|
+
if block_given?
|
739
|
+
create_nested_hash('start_recording', params)
|
740
|
+
instance_exec(&block)
|
741
|
+
@response[:tropo] << @nested_hash
|
742
|
+
@nested_hash = nil
|
743
|
+
@nested_name = nil
|
744
|
+
else
|
745
|
+
hash = build_action('start_recording', params)
|
746
|
+
@response[:tropo] << hash
|
747
|
+
end
|
748
|
+
render_response if @building.nil?
|
749
|
+
end
|
750
|
+
alias :start_call_recording :start_recording
|
751
|
+
|
752
|
+
##
|
753
|
+
# Stops the recording of the current session after startCallRecording has been called
|
754
|
+
#
|
755
|
+
# @return [String, nil] returns the JSON string to stop the recording of a session or nil
|
756
|
+
# if the method has been called from inside a block
|
757
|
+
def stop_recording
|
758
|
+
@response[:tropo] << { :stopRecording => nil }
|
759
|
+
render_response if @building.nil?
|
760
|
+
end
|
761
|
+
alias :stop_call_recording :stop_recording
|
762
|
+
|
763
|
+
##
|
764
|
+
# Transfers an already answered call to another destination / phone number.
|
765
|
+
# Call may be transferred to another phone number or SIP address, which is set through the "to" parameter and is in URL format.
|
766
|
+
# Supported formats include:
|
767
|
+
# tel: classic phone number (See RFC 2896), must be proceeded by a + and the country code (ie - +14155551212 for a US #)
|
768
|
+
# sip: SIP protocol address
|
769
|
+
#
|
770
|
+
# When this method is called the following occurs:
|
771
|
+
# 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.
|
772
|
+
# While audio is playing, a new call is initiated to the specified "to" address using the callerID specified.
|
773
|
+
# If answerOnMedia is true, the audio from the new call is connected to the existing call immediately.
|
774
|
+
# The system waits for an answer or other event from the new call up to the timeout.
|
775
|
+
# 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.
|
776
|
+
# If the call fails before the timeout, onCallFailure will be called and the method will return an onCallFailure event.
|
777
|
+
# If the call fails due to the timeout elapsing, onTimeout will be called and the method will return a timeout event
|
778
|
+
#
|
779
|
+
# @overload transfer(params)
|
780
|
+
# @param [Hash] params the options to create a transfer action request with
|
781
|
+
# @option params [required, String or Array] :to the new destination for the incoming call as a URL
|
782
|
+
# @option params [optional, String] :from set the from id for the session when redirecting
|
783
|
+
# @option params [optional, Integer] :ringRepeat (1) This specifies the number of times the audio file specified in the ring event will repeat itself.
|
784
|
+
# @option params [required, String] :name this is the key used to identify the result of an operation, so you can differentiate between multiple results
|
785
|
+
# @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
|
786
|
+
# @option params [optional, Float] :timeout (30) amount of time Tropo will wait--in seconds--for the other party to answer the call
|
787
|
+
# @option params [optional, Float] :interdigitTimeout (5.0) defines how long to wait between key presses to determine the user has stopped entering input
|
788
|
+
# @option params [optional, String or Array] :allowSignals allows you to assign a signal to record which can be used with REST to interrupt the function
|
789
|
+
# @option params [optional, Boolean or Hash] :machineDetection (false) determines if a call is coming from machine or human
|
790
|
+
# @option params [optional, Object] :on adds event callback to enable "ring" event, which allows you to play an audio file or say something while the outbound call rings
|
791
|
+
# @option params [optional, Boolean] :answerOnMedia (false) if true, the call will be concisdered answered and audio will being playing as soon as media is received (ringing, busy, etc)
|
792
|
+
# @option params [optional, Hash] :headers A set of key/values to apply as customer SIP headers to the outgoing call
|
793
|
+
# @option params [optional, Object] :choices when used with transfer, this defines the terminator
|
794
|
+
# @option params [optional, Boolean] :playTones (true) Controls whether or not each party can hear the tone generated when a key on the phone is pressed by the other party.
|
795
|
+
# @option params [optional, String] :voice (allison) Specifies the default voice to be used when speaking text back to a user.
|
796
|
+
# @option params [optional, String] :callbackUrl Configures a URL for a webhook for CDRs to be sent at the completion of the call.
|
797
|
+
# @option params [optional, String] :promptLogSecurity 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
|
798
|
+
# @option params [optional, String] :label 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
|
799
|
+
# @overload transfer(params, &block)
|
800
|
+
# @param [Hash] params the options to create a transfer action request with
|
801
|
+
# @param [Block] takes a block so that you may trigger actions, such as a say, on a specific event
|
802
|
+
# @option params [required, String or Array] :to the new destination for the incoming call as a URL
|
803
|
+
# @option params [optional, String] :from set the from id for the session when redirecting
|
804
|
+
# @option params [optional, Integer] :ringRepeat (1) This specifies the number of times the audio file specified in the ring event will repeat itself.
|
805
|
+
# @option params [required, String] :name this is the key used to identify the result of an operation, so you can differentiate between multiple results
|
806
|
+
# @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
|
807
|
+
# @option params [optional, Float] :timeout (30) amount of time Tropo will wait--in seconds--for the other party to answer the call
|
808
|
+
# @option params [optional, Float] :interdigitTimeout (5.0) defines how long to wait between key presses to determine the user has stopped entering input
|
809
|
+
# @option params [optional, String or Array] :allowSignals allows you to assign a signal to record which can be used with REST to interrupt the function
|
810
|
+
# @option params [optional, Boolean or Hash] :machineDetection (false) determines if a call is coming from machine or human
|
811
|
+
# @option params [optional, Object] :on adds event callback to enable "ring" event, which allows you to play an audio file or say something while the outbound call rings
|
812
|
+
# @option params [optional, Boolean] :answerOnMedia (false) if true, the call will be concisdered answered and audio will being playing as soon as media is received (ringing, busy, etc)
|
813
|
+
# @option params [optional, Hash] :headers A set of key/values to apply as customer SIP headers to the outgoing call
|
814
|
+
# @option params [optional, Object] :choices when used with transfer, this defines the terminator
|
815
|
+
# @option params [optional, Boolean] :playTones (true) Controls whether or not each party can hear the tone generated when a key on the phone is pressed by the other party.
|
816
|
+
# @option params [optional, String] :voice (allison) Specifies the default voice to be used when speaking text back to a user.
|
817
|
+
# @option params [optional, String] :callbackUrl Configures a URL for a webhook for CDRs to be sent at the completion of the call.
|
818
|
+
# @option params [optional, String] :promptLogSecurity 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
|
819
|
+
# @option params [optional, String] :label 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
|
820
|
+
# @return [nil, String]
|
821
|
+
def transfer(params={}, &block)
|
822
|
+
if block_given?
|
823
|
+
create_nested_hash('transfer', params)
|
824
|
+
instance_exec(&block)
|
825
|
+
@response[:tropo] << @nested_hash
|
826
|
+
@nested_hash = nil
|
827
|
+
@nested_name = nil
|
828
|
+
else
|
829
|
+
hash = build_action('transfer', params)
|
830
|
+
@response[:tropo] << hash
|
831
|
+
end
|
832
|
+
render_response if @building.nil?
|
833
|
+
end
|
834
|
+
|
835
|
+
##
|
836
|
+
# Returns the current hash object of the response, as opposed to JSON
|
837
|
+
#
|
838
|
+
# @return [Hash] the current hash of the response
|
839
|
+
def to_hash
|
840
|
+
@response
|
841
|
+
end
|
842
|
+
|
843
|
+
##
|
844
|
+
# Sets the default voice for the object
|
845
|
+
#
|
846
|
+
# @param [String] voice the value to set the default voice to
|
847
|
+
def voice=(voice)
|
848
|
+
@voice = voice
|
849
|
+
end
|
850
|
+
|
851
|
+
##
|
852
|
+
# 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.
|
853
|
+
#
|
854
|
+
# @overload wait(params)
|
855
|
+
# @param [Hash] params the options to create a message with.
|
856
|
+
# @option params [optional, String or Array] :allowSignals This parameter allows you to assign a signal to this function.
|
857
|
+
# @option params [required, Integer] :milliseconds This defines the time to wait for a state change. Defaults to 0ms if the parameter is skipped.
|
858
|
+
# @overload wait(params, &block)
|
859
|
+
# @param [Hash] params the options to create a message with.
|
860
|
+
# @param [Block] takes a block so that you may trigger actions, such as a say, on a specific event
|
861
|
+
# @option params [optional, String or Array] :allowSignals This parameter allows you to assign a signal to this function.
|
862
|
+
# @option params [required, Integer] :milliseconds This defines the time to wait for a state change. Defaults to 0ms if the parameter is skipped.
|
863
|
+
# @return [String, nil] the JSON string to be passed back to Tropo or nil
|
864
|
+
# if the method has been called from inside a block
|
865
|
+
def wait(params={}, &block)
|
866
|
+
if block_given?
|
867
|
+
create_nested_hash('wait', params)
|
868
|
+
instance_exec(&block)
|
869
|
+
@response[:tropo] << @nested_hash
|
870
|
+
else
|
871
|
+
hash = build_action('wait', params)
|
872
|
+
@response[:tropo] << hash
|
873
|
+
end
|
874
|
+
render_response if @building.nil?
|
875
|
+
end
|
876
|
+
|
877
|
+
##
|
878
|
+
# that can turn off all logging on the Tropo platform
|
879
|
+
#
|
880
|
+
# @overload generalLogSecurity(params)
|
881
|
+
# @param [Hash] params the options to create a message with.
|
882
|
+
# @option params [required, String] :state Set to "suppress" to disable all logging in Tropo. Set to "none" to turn off log suppression and begin logging again.
|
883
|
+
# @overload generalLogSecurity(params, &block)
|
884
|
+
# @param [Hash] params the options to create a message with.
|
885
|
+
# @param [Block] takes a block so that you may trigger actions, such as a say, on a specific event
|
886
|
+
# @option params [required, String] :state Set to "suppress" to disable all logging in Tropo. Set to "none" to turn off log suppression and begin logging again.
|
887
|
+
# @return [String, nil] the JSON string to be passed back to Tropo or nil
|
888
|
+
# if the method has been called from inside a block
|
889
|
+
def generalLogSecurity(params={}, &block)
|
890
|
+
if block_given?
|
891
|
+
create_nested_hash('generalLogSecurity', params)
|
892
|
+
instance_exec(&block)
|
893
|
+
@response[:tropo] << @nested_hash
|
894
|
+
else
|
895
|
+
hash = build_action('generalLogSecurity', params)
|
896
|
+
@response[:tropo] << hash
|
897
|
+
end
|
898
|
+
render_response if @building.nil?
|
899
|
+
end
|
900
|
+
|
901
|
+
|
902
|
+
end
|
903
|
+
end
|