freeswitcher 0.6.12 → 0.6.13

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.
@@ -0,0 +1,66 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require File.expand_path('../../lib/fsr', __FILE__)
4
+ require "fsr/listener/outbound"
5
+ $stdout.flush
6
+
7
+ # Example of a single Outbound Socket listener which dispatches the call
8
+ # based on a freeswitch variable ("action", in this case).
9
+ # With this you can use the following in a dialplan:
10
+ #
11
+ # <extension name="dtmf_demo">
12
+ # <condition field="destination_number" expression="^97701$">
13
+ # <action application="set" data="action=echo_dtmf" />
14
+ # <action application="socket" data="localhost:8184 sync full" />
15
+ # </condition>
16
+ # </extension>
17
+ #
18
+ # Then dialing 97701 would send you to the 'echo_dtmf' method in this class.
19
+ #
20
+ # The power is being able to reuse that :8184 socket with this single listener
21
+ # to handle many tasks, by setting the 'action' variable in the dialplan before
22
+ # calling the socket application. Have fun with this, feedback desired in #rubyists on
23
+ # freenode about what it takes to overwhelm one listener.
24
+
25
+ class OutboundRouter < FSR::Listener::Outbound
26
+
27
+ def session_initiated
28
+ @exten = @session.headers[:caller_caller_id_number]
29
+ FSR::Log.info "Answering incoming call from #{@exten}"
30
+
31
+ if action = @session.headers[:variable_action]
32
+ FSR::Log.info "Action is #{action}"
33
+ send(action) if respond_to?(action)
34
+ else
35
+ FSR::Log.info "No action specified, hanging up"
36
+ hangup
37
+ end
38
+ end
39
+
40
+ def echo_dtmf
41
+ answer do
42
+ FSR::Log.info "Reading DTMF from #{@exten}"
43
+ #######################################################
44
+ ## NOTE YOU MUST MAKE SURE YOU PASS A VALID WAV FILE ##
45
+ #######################################################
46
+ read("ivr/8000/ivr-please_enter_extension_followed_by_pound.wav", 4, 10, "input", 7000) do |read_var|
47
+ FSR::Log.info "Success, grabbed #{read_var.to_s.strip} from #{@exten}"
48
+ # Tell the caller what they entered
49
+ # If you have mod_flite installed you should hear speech
50
+ fs_sleep(1000) {
51
+ playback("ivr/8000/ivr-you_entered.wav") {
52
+ say(read_var.to_s.strip, say_method: 'iterated') { hangup }
53
+ }
54
+ }
55
+ end
56
+ end
57
+ end
58
+
59
+ def receive_reply(reply)
60
+ FSR::Log.info "Received #{reply.inspect}"
61
+ end
62
+
63
+
64
+ end
65
+
66
+ FSR.start_oes! OutboundRouter, :port => 8184, :host => "127.0.0.1"
@@ -0,0 +1,23 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require File.join(File.dirname(__FILE__), "..", 'lib', 'fsr')
4
+ require "fsr/listener/outbound"
5
+ $stdout.flush
6
+
7
+ class InboundCallerId < FSR::Listener::Outbound
8
+
9
+ def session_initiated
10
+ caller_number = @session.headers[:caller_caller_id_number]
11
+ FSR::Log.info "*** Answering incoming call from #{exten}"
12
+
13
+ answer do
14
+ # Lookup number in the database
15
+ caller_name = Ldap.find(telephoneNumber: caller_number).givenName
16
+ set(caller_caller_id_name: caller_name) { continue }
17
+ end
18
+
19
+ end
20
+
21
+ end
22
+
23
+ FSR.start_oes! InboundCallerId, :port => 8084, :host => "127.0.0.1"
@@ -1,34 +1,26 @@
1
1
  #!/usr/bin/env ruby
2
2
 
3
- require File.join(File.dirname(__FILE__), "..", 'lib', 'fsr')
3
+ require 'fsr'
4
4
  require "fsr/listener/outbound"
5
- $stdout.flush
5
+ require 'securerandom'
6
6
 
7
7
  class PlayAndGetDigitsDemo < FSR::Listener::Outbound
8
+ SWEET_WAV = "/usr/local/freeswitch/sounds/music/8000/sweet.wav"
9
+ NOT_WAV = "/usr/local/freeswitch/sounds/music/8000/not.wav"
8
10
 
9
11
  def session_initiated
10
12
  exten = @session.headers[:caller_caller_id_number]
11
13
  FSR::Log.info "*** Answering incoming call from #{exten}"
12
14
 
13
15
  answer do
14
- FSR::Log.info "***Reading DTMF from #{exten}"
15
- #######################################################
16
- ## NOTE YOU MUST MAKE SURE YOU PASS A VALID WAV FILE ##
17
- #######################################################
18
- play_and_get_digits("/usr/local/freeswitch/sounds/music/8000/sweet.wav","/usr/local/freeswitch/sounds/music/8000/not.wav", :chan_var => rand(10000).to_s) do |read_var|
19
- FSR::Log.info "***Success, grabbed #{read_var.to_s.strip} from #{exten}"
20
- # Tell the caller what they entered
21
- # If you have mod_flite installed you should hear speech
22
- speak("Got the DTMF of: #{read_var.to_s.strip}") { hangup }
23
- end
24
- end
16
+ FSR::Log.info "*** Reading DTMF from #{exten}"
25
17
 
26
- def receive_reply(reply)
27
- FSR::Log.info "Received #{reply.inspect}"
18
+ play_and_get_digits(SWEET_WAV, NOT_WAV, chan_var: SecureRandom.uuid) do |digits|
19
+ FSR::Log.info "*** Success, grabbed #{digits.to_s.strip} from #{exten}"
20
+ speak("Got the DTMF of: #{digits.to_s.strip}") { hangup }
21
+ end
28
22
  end
29
-
30
23
  end
31
-
32
24
  end
33
25
 
34
- FSR.start_oes! PlayAndGetDigitsDemo, :port => 8084, :host => "0.0.0.0"
26
+ FSR.start_oes! PlayAndGetDigitsDemo, port: 8084, host: "0.0.0.0"
@@ -8,13 +8,8 @@ module FSR
8
8
  end
9
9
 
10
10
  def arguments
11
- @cause
11
+ [@cause]
12
12
  end
13
-
14
- def sendmsg
15
- "call-command: execute\nexecute-app-name: %s\nexecute-app-arg: %s\n\n" % [app_name, arguments]
16
- end
17
-
18
13
  end
19
14
 
20
15
  register(:hangup, Hangup)
@@ -0,0 +1,26 @@
1
+
2
+ require "fsr/app"
3
+ module FSR
4
+ module App
5
+ class Say < Application
6
+ # http://wiki.freeswitch.org/wiki/Misc._Dialplan_Tools_say
7
+ attr_reader :message
8
+
9
+ def initialize(message, opts = {})
10
+ # wav file you wish to play, full path
11
+ @message = message
12
+ @language = opts[:language] || "en"
13
+ @data_type = opts[:data_type] || "number"
14
+ @say_method = opts[:say_method] || "pronounced"
15
+ @gender = opts[:gender] || "feminine"
16
+ end
17
+
18
+ def arguments
19
+ [@language, @data_type, @say_method, @gender, @message]
20
+ end
21
+
22
+ end
23
+
24
+ register(:say, Say)
25
+ end
26
+ end
data/lib/fsr/cmd/calls.rb CHANGED
@@ -23,13 +23,8 @@ module FSR
23
23
  unless resp["body"] == "0 total."
24
24
  call_info, count = resp["body"].split("\n\n")
25
25
  require "fsr/model/call"
26
- begin
27
- require "fastercsv"
28
- @calls = FCSV.parse(call_info)
29
- rescue LoadError
30
- require "csv"
31
- @calls = CSV.parse(call_info)
32
- end
26
+ require "csv"
27
+ @calls = CSV.parse(call_info)
33
28
  return @calls[1 .. -1].map { |c| FSR::Model::Call.new(@calls[0],*c) }
34
29
  end
35
30
  []
@@ -11,8 +11,9 @@ module FSR
11
11
  end
12
12
  end
13
13
 
14
- def initialize(fs_socket = nil, distinct = true)
15
- @distinct = distinct
14
+ def initialize(fs_socket = nil, filter = nil)
15
+ @filter = filter
16
+ @filter = nil if filter === true && filter === false
16
17
  @fs_socket = fs_socket # FSR::CommandSocket obj
17
18
  end
18
19
 
@@ -24,21 +25,22 @@ module FSR
24
25
  unless resp["body"] == "0 total."
25
26
  call_info, count = resp["body"].split("\n\n")
26
27
  require "fsr/model/channel"
27
- begin
28
- require "fastercsv"
29
- @channels = FCSV.parse(call_info)
30
- rescue LoadError
31
- require "csv"
32
- @channels = CSV.parse(call_info)
28
+ require "csv"
29
+ channels = CSV.parse(call_info)
30
+ headers = channels[0]
31
+ @channels = channels[1 .. -1].map { |c| FSR::Model::Channel.new(headers ,*c) }
32
+ if @filter
33
+ return @channels.select { |f| f.match @filter }
34
+ else
35
+ return @channels
33
36
  end
34
- return @channels[1 .. -1].map { |c| FSR::Model::Channel.new(@channels[0],*c) }
35
37
  end
36
38
  []
37
39
  end
38
40
 
39
41
  # This method builds the API command to send to the freeswitch event socket
40
42
  def raw
41
- orig_command = @distinct ? "show distinct_channels" : "show channels"
43
+ "show channels"
42
44
  end
43
45
  end
44
46
 
@@ -0,0 +1,25 @@
1
+ require "fsr/app"
2
+ module FSR
3
+ module Cmd
4
+ class ValetInfo < Command
5
+
6
+ def initialize(fs_socket = nil)
7
+ @fs_socket = fs_socket # FSR::CommandSocket obj
8
+ end
9
+
10
+ # Send the command to the event socket, using bgapi by default.
11
+ def run(api_method = :api)
12
+ orig_command = "%s %s" % [api_method, raw]
13
+ Log.debug "saying #{orig_command}"
14
+ @fs_socket.say(orig_command)
15
+ end
16
+
17
+ # This method builds the API command to send to the freeswitch event socket
18
+ def raw
19
+ orig_command = "valet_info"
20
+ end
21
+ end
22
+
23
+ register(:valet_info, ValetInfo)
24
+ end
25
+ end
@@ -85,7 +85,10 @@ module FSR
85
85
  hash_content = headers_2_hash(content).merge(:body => content.split("\n\n",2)[1].to_s)
86
86
  when "text/event-json"
87
87
  require "json"
88
- hash_content = JSON.parse(content)
88
+ hash_content = {}
89
+ JSON.parse(content).each do |k, v|
90
+ hash_content[k.downcase.gsub(/-/,"_").intern] = v
91
+ end
89
92
  when "auth/request"
90
93
  FSR::Log.info "#{@host} Authorizing..."
91
94
  return
data/lib/fsr/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module FSR
2
- VERSION = "0.6.12"
2
+ VERSION = "0.6.13"
3
3
  end
@@ -0,0 +1,11 @@
1
+ require 'spec/helper'
2
+ require "fsr/app"
3
+ FSR::App.load_application("say")
4
+
5
+ describe "Testing FSR::App::Say" do
6
+ it "Says number, pronounced, masculine" do
7
+ say = FSR::App::Say.new("12345", language: "en", data_type: "number", say_method: "pronounced", gender: "masculine")
8
+ say.sendmsg.should == "call-command: execute\nexecute-app-name: say\nexecute-app-arg: en number pronounced masculine 12345\n\n"
9
+ end
10
+
11
+ end
@@ -0,0 +1,11 @@
1
+ require 'spec/helper'
2
+ require "fsr/app"
3
+ FSR::App.load_application("speak")
4
+
5
+ describe "Testing FSR::App::Speak" do
6
+ it "Speaks a string" do
7
+ speak = FSR::App::Speak.new("Say my name", engine: "flite", voice: "cms")
8
+ speak.sendmsg.should == "call-command: execute\nexecute-app-name: speak\nexecute-app-arg: flite|cms|Say my name\nevent-lock:true\n\n"
9
+ end
10
+
11
+ end
@@ -5,14 +5,19 @@ FSR::Cmd.load_command("channels")
5
5
  describe "Testing FSR::Cmd::Channels" do
6
6
  ## Channels ##
7
7
  # Interface to channels
8
- it "FSR::Cmd::Channels should send show channels" do
8
+ it "FSR::Cmd::Channels (false as the filter) should send show channels" do
9
9
  sofia = FSR::Cmd::Channels.new(nil, false)
10
10
  sofia.raw.should == "show channels"
11
11
  end
12
12
 
13
- it "FSR::Cmd::Channels should send show channels" do
13
+ it "FSR::Cmd::Channels (true as the filter) should send show channels" do
14
14
  sofia = FSR::Cmd::Channels.new(nil, true)
15
- sofia.raw.should == "show distinct_channels"
15
+ sofia.raw.should == "show channels"
16
+ end
17
+
18
+ it "FSR::Cmd::Channels (regex as the filter) should send show channels" do
19
+ sofia = FSR::Cmd::Channels.new(nil, /something/)
20
+ sofia.raw.should == "show channels"
16
21
  end
17
22
 
18
23
  end
@@ -0,0 +1,13 @@
1
+ require 'spec/helper'
2
+ require "fsr/cmd"
3
+ FSR::Cmd.load_command("valet_info")
4
+
5
+ describe "Testing FSR::Cmd::ValetInfo" do
6
+ ## ValetInfo ##
7
+ # Interface to valet_info
8
+ it "FSR::Cmd::ValetInfo should send valet_info" do
9
+ cmd = FSR::Cmd::ValetInfo.new
10
+ cmd.raw.should == "valet_info"
11
+ end
12
+
13
+ end
data/spec/fsr/loading.rb CHANGED
@@ -4,7 +4,7 @@ require 'spec/helper'
4
4
  describe "Testing FSR module loading methods" do
5
5
  # When you add applications you must modify the expected apps_loaded behavior
6
6
  it "Loads all applications" do
7
- all_apps = [:play_and_get_digits, :uuid_dump, :uuid_setvar, :uuid_getvar, :read, :set, :transfer, :speak, :fs_sleep, :playback, :answer, :fifo, :bridge, :hangup, :conference, :fs_break, :log, :limit, :bind_meta_app, :execute_app, :callcenter, :ring_ready, :pre_answer, :valet_park]
7
+ all_apps = [:play_and_get_digits, :uuid_dump, :uuid_setvar, :uuid_getvar, :read, :set, :say, :transfer, :speak, :fs_sleep, :playback, :answer, :fifo, :bridge, :hangup, :conference, :fs_break, :log, :limit, :bind_meta_app, :execute_app, :callcenter, :ring_ready, :pre_answer, :valet_park]
8
8
  # Add any apps which will load to this set
9
9
  apps_loaded = FSR.load_all_applications
10
10
  apps_loaded.kind_of?(Array).should == true
@@ -16,7 +16,7 @@ describe "Testing FSR module loading methods" do
16
16
 
17
17
  # When you add commands you must modify the expected cmds_loaded behavior
18
18
  it "Loads all commands" do
19
- all_commands = [:uuid_dump, :originate, :sofia, :fsctl, :sofia_contact, :status, :calls, :call_center, :channels, :enum, :sched_hangup, :sched_transfer, :uuid_transfer, :uuid_send_dtmf, :conference] # If you add a command add it to this set
19
+ all_commands = [:uuid_dump, :originate, :sofia, :fsctl, :sofia_contact, :status, :calls, :call_center, :channels, :enum, :sched_hangup, :sched_transfer, :uuid_transfer, :uuid_send_dtmf, :conference, :valet_info] # If you add a command add it to this set
20
20
  cmds_loaded = FSR.load_all_commands
21
21
  cmds_loaded.kind_of?(Array).should == true
22
22
  all_commands.each do |cmd|
data/tasks/bacon.rake CHANGED
@@ -19,7 +19,7 @@ task :bacon => :install_dependencies do
19
19
  specs.each_with_index do |spec, idx|
20
20
  print(left_format % [idx + 1, specs_size, spec])
21
21
 
22
- Open3.popen3(RUBY, spec) do |sin, sout, serr|
22
+ Open3.popen3(FileUtils::RUBY, spec) do |sin, sout, serr|
23
23
  out = sout.read.strip
24
24
  err = serr.read.strip
25
25
 
data/tasks/gem.rake CHANGED
@@ -1,4 +1,4 @@
1
- require 'rake/gempackagetask'
1
+ require 'rubygems/package_task'
2
2
 
3
3
  desc "make a gemspec"
4
4
  task :gemspec => [:manifest, :changelog, :authors] do
@@ -17,7 +17,7 @@ task :uninstall => [:clean] do
17
17
  sh %{gem uninstall -x #{GEMSPEC.name}}
18
18
  end
19
19
 
20
- Rake::GemPackageTask.new(GEMSPEC) do |p|
20
+ Gem::PackageTask.new(GEMSPEC) do |p|
21
21
  p.need_tar = true
22
22
  p.need_zip = true
23
23
  end
metadata CHANGED
@@ -1,12 +1,8 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: freeswitcher
3
3
  version: !ruby/object:Gem::Version
4
- prerelease: false
5
- segments:
6
- - 0
7
- - 6
8
- - 12
9
- version: 0.6.12
4
+ prerelease:
5
+ version: 0.6.13
10
6
  platform: ruby
11
7
  authors:
12
8
  - Jayson Vaughn
@@ -17,7 +13,7 @@ autorequire:
17
13
  bindir: bin
18
14
  cert_chain: []
19
15
 
20
- date: 2011-04-28 00:00:00 -05:00
16
+ date: 2012-01-10 00:00:00 -06:00
21
17
  default_executable:
22
18
  dependencies:
23
19
  - !ruby/object:Gem::Dependency
@@ -28,8 +24,6 @@ dependencies:
28
24
  requirements:
29
25
  - - ">="
30
26
  - !ruby/object:Gem::Version
31
- segments:
32
- - 0
33
27
  version: "0"
34
28
  type: :runtime
35
29
  version_requirements: *id001
@@ -42,7 +36,10 @@ extensions: []
42
36
  extra_rdoc_files: []
43
37
 
44
38
  files:
39
+ - .gems
45
40
  - .gitignore
41
+ - .rvmrc
42
+ - .travis.yml
46
43
  - AUTHORS
47
44
  - CHANGELOG
48
45
  - License.txt
@@ -50,6 +47,8 @@ files:
50
47
  - NEWS
51
48
  - README
52
49
  - Rakefile
50
+ - examples/generic_outbound_router.rb
51
+ - examples/inbound_callerid_app.rb
53
52
  - examples/inbound_event_socket.rb
54
53
  - examples/inbound_socket_events.rb
55
54
  - examples/outbound_event_socket.rb
@@ -74,6 +73,7 @@ files:
74
73
  - lib/fsr/app/pre_answer.rb
75
74
  - lib/fsr/app/read.rb
76
75
  - lib/fsr/app/ring_ready.rb
76
+ - lib/fsr/app/say.rb
77
77
  - lib/fsr/app/set.rb
78
78
  - lib/fsr/app/speak.rb
79
79
  - lib/fsr/app/transfer.rb
@@ -99,6 +99,7 @@ files:
99
99
  - lib/fsr/cmd/uuid_dump.rb
100
100
  - lib/fsr/cmd/uuid_send_dtmf.rb
101
101
  - lib/fsr/cmd/uuid_transfer.rb
102
+ - lib/fsr/cmd/valet_info.rb
102
103
  - lib/fsr/command_socket.rb
103
104
  - lib/fsr/database.rb
104
105
  - lib/fsr/database/call_limit.rb
@@ -156,7 +157,9 @@ files:
156
157
  - spec/fsr/app/playback.rb
157
158
  - spec/fsr/app/pre_answer.rb
158
159
  - spec/fsr/app/ring_ready.rb
160
+ - spec/fsr/app/say.rb
159
161
  - spec/fsr/app/set.rb
162
+ - spec/fsr/app/speak.rb
160
163
  - spec/fsr/app/transfer.rb
161
164
  - spec/fsr/app/valet_park.rb
162
165
  - spec/fsr/cmd.rb
@@ -173,6 +176,7 @@ files:
173
176
  - spec/fsr/cmd/uuid_dump.rb
174
177
  - spec/fsr/cmd/uuid_send_dtmf.rb
175
178
  - spec/fsr/cmd/uuid_transfer.rb
179
+ - spec/fsr/cmd/valet_info.rb
176
180
  - spec/fsr/file_methods.rb
177
181
  - spec/fsr/listener.rb
178
182
  - spec/fsr/listener/header_and_content_response.rb
@@ -374,21 +378,17 @@ required_ruby_version: !ruby/object:Gem::Requirement
374
378
  requirements:
375
379
  - - ">="
376
380
  - !ruby/object:Gem::Version
377
- segments:
378
- - 0
379
381
  version: "0"
380
382
  required_rubygems_version: !ruby/object:Gem::Requirement
381
383
  none: false
382
384
  requirements:
383
385
  - - ">="
384
386
  - !ruby/object:Gem::Version
385
- segments:
386
- - 0
387
387
  version: "0"
388
388
  requirements: []
389
389
 
390
390
  rubyforge_project: freeswitcher
391
- rubygems_version: 1.3.7
391
+ rubygems_version: 1.6.2
392
392
  signing_key:
393
393
  specification_version: 3
394
394
  summary: A library for interacting with the "FreeSWITCH":http://freeswitch.org telephony platform
@@ -410,7 +410,9 @@ test_files:
410
410
  - spec/fsr/app/playback.rb
411
411
  - spec/fsr/app/pre_answer.rb
412
412
  - spec/fsr/app/ring_ready.rb
413
+ - spec/fsr/app/say.rb
413
414
  - spec/fsr/app/set.rb
415
+ - spec/fsr/app/speak.rb
414
416
  - spec/fsr/app/transfer.rb
415
417
  - spec/fsr/app/valet_park.rb
416
418
  - spec/fsr/cmd.rb
@@ -427,6 +429,7 @@ test_files:
427
429
  - spec/fsr/cmd/uuid_dump.rb
428
430
  - spec/fsr/cmd/uuid_send_dtmf.rb
429
431
  - spec/fsr/cmd/uuid_transfer.rb
432
+ - spec/fsr/cmd/valet_info.rb
430
433
  - spec/fsr/file_methods.rb
431
434
  - spec/fsr/listener.rb
432
435
  - spec/fsr/listener/header_and_content_response.rb