Module: Librevox::Applications
- Included in:
- Listener::Outbound
- Defined in:
- lib/librevox/applications.rb
Overview
All applications should call application with the following parameters:
`name` - name of the application
`args` - arguments as a string to be sent to FreeSWITCH (optional)
`params` - parameters for tweaking the command (optional)
Instance Method Summary collapse
-
#answer ⇒ Object
Answers an incoming call or session.
-
#att_xfer(endpoint) ⇒ Object
Make an attended transfer.
-
#bind_meta_app(args = {}) ⇒ Object
Binds an application to the specified call legs.
-
#bridge(*args) ⇒ Object
Bridges an incoming call to an endpoint, optionally taking an array of channel variables to set.
-
#deflect(uri) ⇒ Object
Deflect a call by sending a REFER.
-
#export(var, args = {}) ⇒ Object
Exports a channel variable from the A leg to the B leg.
-
#gentones(tgml) ⇒ Object
Generate TGML tones.
-
#hangup(cause = "") ⇒ Object
Hang up current channel.
-
#multiset(vars) ⇒ Object
Sets multiple channel variables in a single application call.
-
#park ⇒ Object
Parks a call, keeping it active without routing it anywhere.
-
#play_and_get_digits(file, invalid_file, args = {}) ⇒ Object
Plays a sound file and reads DTMF presses.
-
#playback(file) ⇒ Object
Plays a sound file on the current channel.
-
#pre_answer ⇒ Object
Pre-answer establishes early media but does not answer.
- #read(file, args = {}) ⇒ Object
-
#record(path, params = {}) ⇒ Object
Records a message, with an optional limit on the maximum duration of the recording.
-
#redirect(uri) ⇒ Object
Redirect a channel to another endpoint.
-
#respond(code) ⇒ Object
Send SIP session respond code.
-
#set(variable, value) ⇒ Object
Sets a channel variable.
-
#transfer(context) ⇒ Object
Transfers the current channel to a new context.
-
#unbind_meta_app(key) ⇒ Object
Unbinds a previously bound key with bind_meta_app.
-
#unset(variable) ⇒ Object
Unset a channel variable.
Instance Method Details
#answer ⇒ Object
Answers an incoming call or session.
13 14 15 |
# File 'lib/librevox/applications.rb', line 13 def answer application "answer" end |
#att_xfer(endpoint) ⇒ Object
Add support for origination_cancel_key
Make an attended transfer
28 29 30 |
# File 'lib/librevox/applications.rb', line 28 def att_xfer(endpoint) application "att_xfer", endpoint end |
#bind_meta_app(args = {}) ⇒ Object
Binds an application to the specified call legs.
40 41 42 43 44 45 46 |
# File 'lib/librevox/applications.rb', line 40 def (args = {}) arg_string = args.values_at(:key, :listen_to, :respond_on, :application).join(" ") arg_string += "::#{args[:parameters]}" if args[:parameters] application "bind_meta_app", arg_string end |
#bridge(*args) ⇒ Object
Bridges an incoming call to an endpoint, optionally taking an array of channel variables to set. If given an array of arrays, each contained array of endpoints will be called simultaneously, with the next array of endpoints as failover. See the examples below for different constructs and the callstring it sends to FreeSWITCH.
63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 |
# File 'lib/librevox/applications.rb', line 63 def bridge(*args) variables = if args.last.is_a? Hash pairs = args.pop.map {|k,v| "#{k}=#{v}"} "{#{pairs.join(",")}}" else "" end endpoints = if args.first.is_a? Array args.map {|e| e.join(",")}.join("|") else args.join "," end application "bridge", variables + endpoints end |
#deflect(uri) ⇒ Object
90 91 92 |
# File 'lib/librevox/applications.rb', line 90 def deflect(uri) application "deflect", uri end |
#export(var, args = {}) ⇒ Object
Exports a channel variable from the A leg to the B leg. Variables and their values will be replicated in any new channels created from the one export was called.
Set local: false if the variable should only be exported to the B-leg.
105 106 107 108 109 |
# File 'lib/librevox/applications.rb', line 105 def export(var, args = {}) nolocal = args[:local] == false ? "nolocal:" : "" application "export", "#{nolocal}#{var}" end |
#gentones(tgml) ⇒ Object
Generate TGML tones
117 118 119 |
# File 'lib/librevox/applications.rb', line 117 def gentones(tgml) application "gentones", tgml end |
#hangup(cause = "") ⇒ Object
Hang up current channel
127 128 129 |
# File 'lib/librevox/applications.rb', line 127 def hangup(cause = "") application "hangup", cause end |
#multiset(vars) ⇒ Object
Sets multiple channel variables in a single application call.
233 234 235 236 |
# File 'lib/librevox/applications.rb', line 233 def multiset(vars) args = "^^|" + vars.map { |k, v| "#{k}=#{v}" }.join("|") application "multiset", args end |
#park ⇒ Object
Parks a call, keeping it active without routing it anywhere.
19 20 21 |
# File 'lib/librevox/applications.rb', line 19 def park application "park" end |
#play_and_get_digits(file, invalid_file, args = {}) ⇒ Object
Plays a sound file and reads DTMF presses.
141 142 143 144 145 146 147 148 149 150 151 152 153 154 |
# File 'lib/librevox/applications.rb', line 141 def play_and_get_digits(file, invalid_file, args = {}) min = args[:min] || 1 max = args[:max] || 2 tries = args[:tries] || 3 terminators = args[:terminators] || "#" timeout = args[:timeout] || 5000 variable = args[:variable] || "read_digits_var" regexp = args[:regexp] || "\\d+" args = [min, max, tries, timeout, terminators, file, invalid_file, variable, regexp].join " " application "play_and_get_digits", args, variable: variable end |
#playback(file) ⇒ Object
Plays a sound file on the current channel.
160 161 162 |
# File 'lib/librevox/applications.rb', line 160 def playback(file) application "playback", file end |
#pre_answer ⇒ Object
Pre-answer establishes early media but does not answer.
168 169 170 |
# File 'lib/librevox/applications.rb', line 168 def pre_answer application "pre_answer" end |
#read(file, args = {}) ⇒ Object
173 174 175 176 177 178 179 180 181 182 183 184 |
# File 'lib/librevox/applications.rb', line 173 def read(file, args = {}) min = args[:min] || 1 max = args[:max] || 2 terminators = args[:terminators] || "#" timeout = args[:timeout] || 5000 variable = args[:variable] || "read_digits_var" arg_string = "%s %s %s %s %s %s" % [min, max, file, variable, timeout, terminators] application "read", arg_string, variable: variable end |
#record(path, params = {}) ⇒ Object
Records a message, with an optional limit on the maximum duration of the recording.
193 194 195 196 |
# File 'lib/librevox/applications.rb', line 193 def record(path, params = {}) args = [path, params[:limit]].compact.join(" ") application "record", args end |
#redirect(uri) ⇒ Object
Redirect a channel to another endpoint. You must take care to not redirect incompatible channels, as that wont have the desired effect. I.e. if you redirect to a SIP URI, it should be a SIP channel.
#redirect can only be used on non-established calls, i.e. calls that has not been answered with the #answer application yet. If the call has been answered, use #deflect instead.
209 210 211 |
# File 'lib/librevox/applications.rb', line 209 def redirect(uri) application "redirect", uri end |
#respond(code) ⇒ Object
Send SIP session respond code.
217 218 219 |
# File 'lib/librevox/applications.rb', line 217 def respond(code) application "respond", code.to_s end |
#set(variable, value) ⇒ Object
Sets a channel variable.
225 226 227 |
# File 'lib/librevox/applications.rb', line 225 def set(variable, value) application "set", "#{variable}=#{value}" end |
#transfer(context) ⇒ Object
Transfers the current channel to a new context.
242 243 244 |
# File 'lib/librevox/applications.rb', line 242 def transfer(context) application "transfer", context end |
#unbind_meta_app(key) ⇒ Object
Unbinds a previously bound key with bind_meta_app
250 251 252 |
# File 'lib/librevox/applications.rb', line 250 def (key) application "unbind_meta_app", key.to_s end |
#unset(variable) ⇒ Object
Unset a channel variable.
258 259 260 |
# File 'lib/librevox/applications.rb', line 258 def unset(variable) application "unset", variable end |