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(&block) ⇒ Object
Answers an incoming call or session.
-
#att_xfer(endpoint, &block) ⇒ Object
Make an attended transfer.
-
#bind_meta_app(args = {}, &block) ⇒ Object
Binds an application to the specified call legs.
-
#bridge(*args, &block) ⇒ Object
Bridges an incoming call to an endpoint, optionally taking an array of channel variables to set.
-
#deflect(uri, &block) ⇒ Object
Deflect a call by sending a REFER.
-
#export(var, args = {}, &block) ⇒ Object
Exports a channel variable from the A leg to the B leg.
-
#gentones(tgml, &block) ⇒ Object
Generate TGML tones.
-
#hangup(cause = "", &block) ⇒ Object
Hang up current channel.
-
#play_and_get_digits(file, invalid_file, args = {}, &block) ⇒ Object
Plays a sound file and reads DTMF presses.
-
#playback(file, &block) ⇒ Object
Plays a sound file on the current channel.
-
#pre_answer(&block) ⇒ Object
Pre-answer establishes early media but does not answer.
- #read(file, args = {}, &block) ⇒ Object
-
#record(path, params = {}, &block) ⇒ Object
Records a message, with an optional limit on the maximum duration of the recording.
-
#redirect(uri, &block) ⇒ Object
Redirect a channel to another endpoint.
-
#respond(code, &block) ⇒ Object
Send SIP session respond code.
-
#set(variable, value, &block) ⇒ Object
Sets a channel variable.
-
#transfer(context, &block) ⇒ Object
Transfers the current channel to a new context.
-
#unbind_meta_app(key, &block) ⇒ Object
Unbinds a previously bound key with bind_meta_app.
-
#unset(variable, &block) ⇒ Object
Unset a channel variable.
Instance Method Details
#answer(&block) ⇒ Object
Answers an incoming call or session.
11 12 13 |
# File 'lib/librevox/applications.rb', line 11 def answer &block application "answer", &block end |
#att_xfer(endpoint, &block) ⇒ Object
Add support for origination_cancel_key
Make an attended transfer
20 21 22 |
# File 'lib/librevox/applications.rb', line 20 def att_xfer endpoint, &block application "att_xfer", endpoint, &block end |
#bind_meta_app(args = {}, &block) ⇒ Object
Binds an application to the specified call legs.
32 33 34 35 36 37 38 |
# File 'lib/librevox/applications.rb', line 32 def args={}, &block 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, &block end |
#bridge(*args, &block) ⇒ 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.
56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 |
# File 'lib/librevox/applications.rb', line 56 def bridge *args, &block variables = if args.last.is_a? Hash # We need to sort the key/value pairs to facilitate testing. # This can be removed once 1.8-compat is dropped. key_value_pairs = args.pop.sort {|x,y| x.to_s <=> y.to_s} key_value_pairs.map! {|k,v| "#{k}=#{v}"} "{#{key_value_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, &block end |
#deflect(uri, &block) ⇒ Object
86 87 88 |
# File 'lib/librevox/applications.rb', line 86 def deflect uri, &block application "deflect", uri, &block end |
#export(var, args = {}, &block) ⇒ 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.
101 102 103 104 105 |
# File 'lib/librevox/applications.rb', line 101 def export var, args={}, &block nolocal = args[:local] == false ? "nolocal:" : "" # ugly!!111 application "export", "#{nolocal}#{var}", &block end |
#gentones(tgml, &block) ⇒ Object
Generate TGML tones
113 114 115 |
# File 'lib/librevox/applications.rb', line 113 def gentones tgml , &block application "gentones", tgml, &block end |
#hangup(cause = "", &block) ⇒ Object
Hang up current channel
123 124 125 |
# File 'lib/librevox/applications.rb', line 123 def hangup cause="", &block application "hangup", cause, &block end |
#play_and_get_digits(file, invalid_file, args = {}, &block) ⇒ Object
Plays a sound file and reads DTMF presses.
137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 |
# File 'lib/librevox/applications.rb', line 137 def play_and_get_digits file, invalid_file, args={}, &block 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 " " params = {:variable => variable} application "play_and_get_digits", args, params, &block end |
#playback(file, &block) ⇒ Object
Plays a sound file on the current channel.
158 159 160 |
# File 'lib/librevox/applications.rb', line 158 def playback file, &block application "playback", file, &block end |
#pre_answer(&block) ⇒ Object
Pre-answer establishes early media but does not answer.
166 167 168 |
# File 'lib/librevox/applications.rb', line 166 def pre_answer &block application "pre_answer", &block end |
#read(file, args = {}, &block) ⇒ Object
171 172 173 174 175 176 177 178 179 180 181 182 183 184 |
# File 'lib/librevox/applications.rb', line 171 def read file, args={}, &block 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] params = {:variable => variable} application "read", arg_string, params, &block end |
#record(path, params = {}, &block) ⇒ 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={}, &block args = [path, params[:limit]].compact.join(" ") application "record", args, &block end |
#redirect(uri, &block) ⇒ 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, &block application "redirect", uri, &block end |
#respond(code, &block) ⇒ Object
Send SIP session respond code.
217 218 219 |
# File 'lib/librevox/applications.rb', line 217 def respond code, &block application "respond", code.to_s, &block end |
#set(variable, value, &block) ⇒ Object
Sets a channel variable.
225 226 227 |
# File 'lib/librevox/applications.rb', line 225 def set variable, value, &block application "set", "#{variable}=#{value}", &block end |
#transfer(context, &block) ⇒ Object
Transfers the current channel to a new context.
233 234 235 |
# File 'lib/librevox/applications.rb', line 233 def transfer context, &block application "transfer", context, &block end |
#unbind_meta_app(key, &block) ⇒ Object
Unbinds a previously bound key with bind_meta_app
241 242 243 |
# File 'lib/librevox/applications.rb', line 241 def key, &block application "unbind_meta_app", key.to_s, &block end |
#unset(variable, &block) ⇒ Object
Unset a channel variable.
249 250 251 |
# File 'lib/librevox/applications.rb', line 249 def unset variable, &block application "unset", variable, &block end |