Module: FreeswitchApplications

Included in:
FreecBase
Defined in:
lib/freeswitch_applications.rb

Instance Method Summary collapse

Instance Method Details

#answerObject

Answers the call.



4
5
6
# File 'lib/freeswitch_applications.rb', line 4

def answer
  execute_app('answer')
end

#bridge(number_or_numbers, options = {}) ⇒ Object

Bridges the call to the given number or numbers (this param can be a number or an array of numbers).



28
29
30
31
# File 'lib/freeswitch_applications.rb', line 28

def bridge(number_or_numbers, options = {})
  number_or_numbers = number_or_numbers.join(",") if number_or_numbers.is_a?(Array)
  execute_app("bridge", "#{number_or_numbers}")
end

#execute_app(app, pars = '', lock = true, unique_id = nil) ⇒ Object

Executes an app using the sendmsg command of Freeswitch. Use this if there is no method for the application you want to run.

Params:

  • app is the application name

  • pars is a string of arguments of the app

  • lock can be set to false so Freeswitch won’t wait for this app to finish before running the next one



91
92
93
94
95
96
97
98
99
100
# File 'lib/freeswitch_applications.rb', line 91

def execute_app(app, pars = '', lock = true, unique_id = nil)
  @last_app_executed = app
  unique_id = @unique_id unless unique_id
  cmd = "sendmsg #{unique_id}"
  cmd << "\ncall-command: execute"
  cmd << "\nexecute-app-name: #{app}"
  cmd << "\nexecute-app-arg: #{pars}" unless pars.blank?
  cmd << "\nevent-lock:#{lock}"
  send_data cmd
end

#hangupObject

Hangs up the call.



80
81
82
# File 'lib/freeswitch_applications.rb', line 80

def hangup
  execute_app('hangup', 'USER_BUSY')
end

#playback(file_name) ⇒ Object

Plays the file in file_name file_name is either an absolute path or path relative to the sound_prefix variable set in Freeswitch’s vars.xml configuration file.



11
12
13
# File 'lib/freeswitch_applications.rb', line 11

def playback(file_name)
  execute_app('playback', file_name)
end

#read(file_name, options = {}) ⇒ Object

Plays the file in file_name and reads input (key presses) from the user.

Options:

  • :terminators option to set a different terminator or terminators (defaults to ‘#’)

  • :variable to set the variable where the results is put (defaults to call_vars)

  • :timeout to override the default timeout value (which is 10 seconds)

  • :min and :max options to override the default maximum and minimum of characters that will be read (both default to 1)



56
57
58
59
60
# File 'lib/freeswitch_applications.rb', line 56

def read(file_name, options = {})
  options[:terminators] = [options[:terminators]] if options[:terminators].is_a?(String)
  options = {timeout: 10, variable: 'input', min: 1, max: 1, terminators: ['#']}.merge(options)
  execute_app("read", "#{options[:min]} #{options[:max]} #{file_name} #{options[:variable]} #{options[:timeout] * 1000} #{options[:terminators].join(',')}")
end

#record(file_name, options = {}) ⇒ Object

Records the call to a file with the given file_name file_name is either an absolute path or path relative to the sound_prefix variable set in Freeswitch’s vars.xml configuration file.

Options:

  • :time_limit_secs overrides the default timeout, which is 600 seconds



44
45
46
47
# File 'lib/freeswitch_applications.rb', line 44

def record(file_name, options = {})
  options = {time_limit_secs: 600}.merge(options) #no reverse_merge, no fun :-)
  execute_app("record", "#{file_name} #{options[:time_limit_secs]}")
end

#set_variable(name, value) ⇒ Object

Sets a variable with the give name to the given value.



75
76
77
# File 'lib/freeswitch_applications.rb', line 75

def set_variable(name, value)
  execute_app('set', "#{name}=#{value}")
end

#speak(string) ⇒ Object

Says the given string Don’t forget to set up your TTS engine and set variables tts_engine and tts_voice accordingly See e.g.: wiki.freeswitch.org/wiki/Mod_flite



23
24
25
# File 'lib/freeswitch_applications.rb', line 23

def speak(string)
  execute_app('speak', string)
end

#spell(string) ⇒ Object

Spells the string



16
17
18
# File 'lib/freeswitch_applications.rb', line 16

def spell(string)
  execute_app('phrase', "spell,#{string}")
end

#start_recording(file_name) ⇒ Object

Starts recording the call in file in file_name



64
65
66
# File 'lib/freeswitch_applications.rb', line 64

def start_recording(file_name)
  execute_app('record_session', file_name)
end

#stop_recording(file_name) ⇒ Object

Stops recording the call in file in file_name



70
71
72
# File 'lib/freeswitch_applications.rb', line 70

def stop_recording(file_name)
  execute_app('stop_record_session', file_name)
end

#transfer(extension) ⇒ Object

Transfers the call to the given extension



34
35
36
# File 'lib/freeswitch_applications.rb', line 34

def transfer(extension)
  execute_app("transfer", "#{extension}")
end