[Freeswitch-svn] [commit] r9229 - in freeswitch/trunk/scripts/contrib/jpalley/telegraph/trunk: . generators/voice_events_controller/templates lib/core lib/core/voice_events lib/core/voice_view lib/freeswitch lib/freeswitch/voice_model
Freeswitch SVN
jpalley at freeswitch.org
Wed Aug 6 12:17:31 EDT 2008
Author: jpalley
Date: Wed Aug 6 12:17:30 2008
New Revision: 9229
Modified:
freeswitch/trunk/scripts/contrib/jpalley/telegraph/trunk/README
freeswitch/trunk/scripts/contrib/jpalley/telegraph/trunk/generators/voice_events_controller/templates/routes.rb
freeswitch/trunk/scripts/contrib/jpalley/telegraph/trunk/install.rb
freeswitch/trunk/scripts/contrib/jpalley/telegraph/trunk/lib/core/telegraph.rb
freeswitch/trunk/scripts/contrib/jpalley/telegraph/trunk/lib/core/voice_events/router.rb
freeswitch/trunk/scripts/contrib/jpalley/telegraph/trunk/lib/core/voice_view/action_controller_extensions.rb
freeswitch/trunk/scripts/contrib/jpalley/telegraph/trunk/lib/core/voice_view/dispatcher.rb
freeswitch/trunk/scripts/contrib/jpalley/telegraph/trunk/lib/core/voice_view/interface.rb
freeswitch/trunk/scripts/contrib/jpalley/telegraph/trunk/lib/core/voice_view/request.rb
freeswitch/trunk/scripts/contrib/jpalley/telegraph/trunk/lib/core/voice_view/template.rb
freeswitch/trunk/scripts/contrib/jpalley/telegraph/trunk/lib/freeswitch/voice_events_server.rb
freeswitch/trunk/scripts/contrib/jpalley/telegraph/trunk/lib/freeswitch/voice_model/voice_channel_model.rb
freeswitch/trunk/scripts/contrib/jpalley/telegraph/trunk/lib/freeswitch/voice_model/voice_conference_model.rb
freeswitch/trunk/scripts/contrib/jpalley/telegraph/trunk/lib/freeswitch/voice_model/voice_connector.rb
freeswitch/trunk/scripts/contrib/jpalley/telegraph/trunk/lib/freeswitch/voice_model/voice_sip_model.rb
freeswitch/trunk/scripts/contrib/jpalley/telegraph/trunk/lib/freeswitch/voice_view_interface.rb
freeswitch/trunk/scripts/contrib/jpalley/telegraph/trunk/lib/freeswitch/voice_view_server.rb
Log:
updates to telegraph. Rails 2.1, bug fixes, imprveoments
Modified: freeswitch/trunk/scripts/contrib/jpalley/telegraph/trunk/README
==============================================================================
--- freeswitch/trunk/scripts/contrib/jpalley/telegraph/trunk/README (original)
+++ freeswitch/trunk/scripts/contrib/jpalley/telegraph/trunk/README Wed Aug 6 12:17:30 2008
@@ -1,7 +1,7 @@
Telegraph for FreeSWITCH
-Please see http://code.google.com/p/telegraph for more information
+Please see http://developer.idapted.com/plugins/telegraph for more information
-Telegraph allows you to write MVC voice application in Ruby on Rails that tightly integrate with the web. In our second release we go FreeSWITCH (the new OSS carrier grade switch) and Rails 2. Here's the details:
+Telegraph allows you to write MVC voice application in Ruby on Rails that tightly integrate with the web. In our second release we go FreeSWITCH (the new OSS carrier grade switch) and Rails 2.1. Here's the details:
For the FreeSWITCH fan:
- Complete implementation of Outbound Socket, Event (Inbound) Socket and XML-RPC
Modified: freeswitch/trunk/scripts/contrib/jpalley/telegraph/trunk/generators/voice_events_controller/templates/routes.rb
==============================================================================
--- freeswitch/trunk/scripts/contrib/jpalley/telegraph/trunk/generators/voice_events_controller/templates/routes.rb (original)
+++ freeswitch/trunk/scripts/contrib/jpalley/telegraph/trunk/generators/voice_events_controller/templates/routes.rb Wed Aug 6 12:17:30 2008
@@ -11,4 +11,9 @@
map.default :<%= file_name %>
end
+
+ def self.filter(params)
+ return true
+ end
+
end
Modified: freeswitch/trunk/scripts/contrib/jpalley/telegraph/trunk/install.rb
==============================================================================
--- freeswitch/trunk/scripts/contrib/jpalley/telegraph/trunk/install.rb (original)
+++ freeswitch/trunk/scripts/contrib/jpalley/telegraph/trunk/install.rb Wed Aug 6 12:17:30 2008
@@ -5,7 +5,9 @@
#Copy script files
%w{voice_view voice_events}.each do |f|
- File.copy "#{dir}/lib/#{f}", "#{dir}/../../../script/#{f}"
+ dest = "#{dir}/../../../script/#{f}"
+ File.copy "#{dir}/lib/#{f}", dest
+ File.chmod 0755, dest
end
#Copy configuration
Modified: freeswitch/trunk/scripts/contrib/jpalley/telegraph/trunk/lib/core/telegraph.rb
==============================================================================
--- freeswitch/trunk/scripts/contrib/jpalley/telegraph/trunk/lib/core/telegraph.rb (original)
+++ freeswitch/trunk/scripts/contrib/jpalley/telegraph/trunk/lib/core/telegraph.rb Wed Aug 6 12:17:30 2008
@@ -1,9 +1,9 @@
Mime::Type.register "telegraph/voice", :voice
module Telegraph
def self.config
- rails_config = File.join(RAILS_ROOT, 'config/telegraph')
+ rails_config = File.join(RAILS_ROOT, 'config/telegraph.yml')
if File.exist?(rails_config)
- yml = YAML.load(File.open(File.join(RAILS_ROOT, 'config/telegraph.yml')))
+ yml = YAML.load(File.open(rails_config))
else
yml = YAML.load(File.open(File.join(RAILS_ROOT, 'vendor/plugins/telegraph/lib/telegraph.yml')))
end
Modified: freeswitch/trunk/scripts/contrib/jpalley/telegraph/trunk/lib/core/voice_events/router.rb
==============================================================================
--- freeswitch/trunk/scripts/contrib/jpalley/telegraph/trunk/lib/core/voice_events/router.rb (original)
+++ freeswitch/trunk/scripts/contrib/jpalley/telegraph/trunk/lib/core/voice_events/router.rb Wed Aug 6 12:17:30 2008
@@ -13,9 +13,12 @@
@routes << {:controller=>name, :block=>nil}
end
+
def dispatch!(event_name, params)
controller_name = @routes.detect{|r|
- r[:block].nil? || r[:block].call(params)}[:controller]
+ r[:block].nil? || r[:block].call(params)}
+ raise("No Route For Event: #{event_name}\n\nPARAMS:\n#{params.inspect}") if controller_name.nil?
+ controller_name=controller_name[:controller]
controller = controller_from_name(controller_name)
controller.params = params
controller.send(event_name.to_sym)
Modified: freeswitch/trunk/scripts/contrib/jpalley/telegraph/trunk/lib/core/voice_view/action_controller_extensions.rb
==============================================================================
--- freeswitch/trunk/scripts/contrib/jpalley/telegraph/trunk/lib/core/voice_view/action_controller_extensions.rb (original)
+++ freeswitch/trunk/scripts/contrib/jpalley/telegraph/trunk/lib/core/voice_view/action_controller_extensions.rb Wed Aug 6 12:17:30 2008
@@ -1,6 +1,7 @@
module ActionController
class Base
def render_voice(&block)
+ response.interface.controller = self
begin
yield response.interface
end
Modified: freeswitch/trunk/scripts/contrib/jpalley/telegraph/trunk/lib/core/voice_view/dispatcher.rb
==============================================================================
--- freeswitch/trunk/scripts/contrib/jpalley/telegraph/trunk/lib/core/voice_view/dispatcher.rb (original)
+++ freeswitch/trunk/scripts/contrib/jpalley/telegraph/trunk/lib/core/voice_view/dispatcher.rb Wed Aug 6 12:17:30 2008
@@ -36,6 +36,7 @@
@request.next_action=nil
ActionController::Dispatcher.new(StdOutEmulator.new, @request, @response).dispatch
#Check for errors
+
if @response.headers['Status'] == "500 Internal Server Error" or @response.headers['Status'] == "406 Not Acceptable"
@request.interface.hangup
break
Modified: freeswitch/trunk/scripts/contrib/jpalley/telegraph/trunk/lib/core/voice_view/interface.rb
==============================================================================
--- freeswitch/trunk/scripts/contrib/jpalley/telegraph/trunk/lib/core/voice_view/interface.rb (original)
+++ freeswitch/trunk/scripts/contrib/jpalley/telegraph/trunk/lib/core/voice_view/interface.rb Wed Aug 6 12:17:30 2008
@@ -1,9 +1,30 @@
module Telegraph
module VoiceView
+ class Form
+ attr_accessor :elements
+ def initialize
+ @elements = Array.new
+ end
+
+ def numeric_input(param, pars={})
+ @elements << {:type=>:get_dtmf, :sound=>pars[:sound], :param=>param, :timeout=>pars[:timeout] || 5000, :max_digits=>pars[:max_digits] || 7, :terminators=>pars[:terminators]}
+ end
+
+ def submit(args)
+ @elements << {:type=>'submit', :args=>args}
+ end
+
+ def record_input(label, filename, param, max_time=10, beep=true, silence_detect=10)
+ @elements << {:type=>'record_input',:label=>label, :filename=>filename,:param=>param, :max_time=>max_time, :beep=>beep, :silence_detect=>silence_detect}
+ end
+ end
class Interface
- def redirect(args)
- @request.create_redirect args
+ attr_accessor :controller
+
+ def redirect_to(args)
+ create_redirect @controller.url_for(args.merge(:only_path=>true))
end
+
# The following has not been updated/tested with FreeSWITCH.
# It should work with minor modifications for someone who needs the features
@@ -13,18 +34,20 @@
# str.split(' ').each {|e| say_element(e)}
# end
#
- # def form (opts={})
- # form = Telegraph::CallForm.new
- # @params = {}
- # yield form
- #
- # for element in form.elements
- # build_form_element(element)
- # end
- #
- # @params.update(opts[:url])
- # @request.create_redirect @params
- # end
+ def form (opts={})
+ form = Telegraph::VoiceView::Form.new
+ @params = {}
+ yield form
+
+ for element in form.elements
+ build_form_element(element)
+ end
+
+ url = opts[:url] || opts
+ url = @controller.url_for(args.merge(:only_path=>true)) unless url.is_a?(String)
+ method = opts[:method].to_s.upcase || "POST"
+ create_redirect url, method
+ end
#
# def extract_hash(key, value)
# split_key=key.split('[')
Modified: freeswitch/trunk/scripts/contrib/jpalley/telegraph/trunk/lib/core/voice_view/request.rb
==============================================================================
--- freeswitch/trunk/scripts/contrib/jpalley/telegraph/trunk/lib/core/voice_view/request.rb (original)
+++ freeswitch/trunk/scripts/contrib/jpalley/telegraph/trunk/lib/core/voice_view/request.rb Wed Aug 6 12:17:30 2008
@@ -10,7 +10,7 @@
#
def initialize(interface, cgi, query_parameters ={}, request_parameters = {}, session_opts = ActionController::CgiRequest::DEFAULT_SESSION_OPTIONS)
@interface = interface
- @query_parameters = query_parameters
+ @query_parameters = query_parameters
@session_options = session_opts
@redirect = false
@env = {}
@@ -24,7 +24,7 @@
@cgi = cgi
@host = "voice_view"
@request_uri = "/"
- @env['REQUEST_METHOD'] = "POST"
+ @env['REQUEST_METHOD'] = @interface.params['http_method'] || "GET"
@path= @interface.url
@session_options['session_id'] = @interface.params['session_id']
Modified: freeswitch/trunk/scripts/contrib/jpalley/telegraph/trunk/lib/core/voice_view/template.rb
==============================================================================
--- freeswitch/trunk/scripts/contrib/jpalley/telegraph/trunk/lib/core/voice_view/template.rb (original)
+++ freeswitch/trunk/scripts/contrib/jpalley/telegraph/trunk/lib/core/voice_view/template.rb Wed Aug 6 12:17:30 2008
@@ -28,8 +28,8 @@
#options = Haml::Template.options.dup
puts "COMPILE"
puts template
-
- "controller.render_voice do |voice|\n #{template}\n end"
+
+ "controller.render_voice do |voice|\n #{template.source}\n end"
# Haml::Engine.new(template, options).send(:precompiled_with_ambles, [])
end
@@ -40,4 +40,4 @@
end
end
-ActionView::Base.register_template_handler(:freeswitch, Telegraph::VoiceView::Template)
+ActionView::Template.register_template_handler(:freeswitch, Telegraph::VoiceView::Template)
Modified: freeswitch/trunk/scripts/contrib/jpalley/telegraph/trunk/lib/freeswitch/voice_events_server.rb
==============================================================================
--- freeswitch/trunk/scripts/contrib/jpalley/telegraph/trunk/lib/freeswitch/voice_events_server.rb (original)
+++ freeswitch/trunk/scripts/contrib/jpalley/telegraph/trunk/lib/freeswitch/voice_events_server.rb Wed Aug 6 12:17:30 2008
@@ -85,8 +85,9 @@
headers[:content] = data[2] if data[2]
event_name = headers[:event_name].downcase
- event_name = "custom_" + headers[:event_subclass].gsub('::', '_') if headers[:event_name] == "CUSTOM"
+ event_name = "custom_" + headers[:event_subclass].gsub('::', '_') if headers[:event_name] == "CUSTOM"
begin
+ return unless VoiceEventsRouter.filter(headers)
Telegraph.log "CALLING: #{event_name}"
@routes.dispatch!(event_name.to_sym, headers)
# @voice_events.params = headers
@@ -104,6 +105,7 @@
rescue Exception => e
Telegraph.log "Error in sending event: #{headers[:event_name]}"
Telegraph.log e.inspect
+ Telegraph.log e.backtrace
else
@ar_reconnected_retried = false
Modified: freeswitch/trunk/scripts/contrib/jpalley/telegraph/trunk/lib/freeswitch/voice_model/voice_channel_model.rb
==============================================================================
--- freeswitch/trunk/scripts/contrib/jpalley/telegraph/trunk/lib/freeswitch/voice_model/voice_channel_model.rb (original)
+++ freeswitch/trunk/scripts/contrib/jpalley/telegraph/trunk/lib/freeswitch/voice_model/voice_channel_model.rb Wed Aug 6 12:17:30 2008
@@ -12,10 +12,10 @@
@exists = nil
@last_error = nil
def initialize(params={})
- @params = params
+ @params = params.with_indifferent_access
@uuid = params[:uuid]
@job_uuid = params[:job_uuid]
- @@connector = params[:connector] || VoiceConnector.new
+ @@connector ||= params[:connector] || VoiceConnector.new
@valid=true
end
@@ -68,8 +68,12 @@
end
def method_missing(method, *args)
- properties = self.dump
- properties[method] ? properties[method] : properties["channel_#{method}"]
+ if @params[method]
+ return @params[method]
+ else
+ properties = self.dump
+ properties[method] ? properties[method] : properties["channel_#{method}"]
+ end
end
@@ -93,7 +97,8 @@
if meth == :all
channels_csv = voice_connector.show(:channels)
if args.empty?
- return channels_csv.map{|c| VoiceChannelModel.new(c, voice_connector)}
+
+ return channels_csv.map{|c| VoiceChannelModel.new(c)}
end
else
klass = self.new(:uuid=>meth)
@@ -115,14 +120,17 @@
variables[:origination_caller_id_name] = cid_name
variables[:origination_caller_id_number] = cid_number
variables[:ignore_early_media] = "true"
-
+# variables[:system_domain] = SiteConfig['global']['domain']
variables = variables.map{|k,v| "#{k}=#{v}"}.join(',')
if callback = opts[:callback]
- port = opts[:port] || '8084'
+ #port = opts[:port] || '8084'
#Remove http://blah/ if it exists
callback.gsub!(/http:\/\/[\d\w\.:]+\//, '')
- params = "&socket(${rails_server}:#{port}/#{callback} async full)"
+ callback.gsub!(/^\//, '')
+# name_prefix = SiteConfig ? "#{SiteConfig['global']['domain']}_" : ''
+ name_prefix = ''
+ params = "&socket(${rails_#{name_prefix}server}/#{callback} async full)"
else
params = opts[:params]
end
Modified: freeswitch/trunk/scripts/contrib/jpalley/telegraph/trunk/lib/freeswitch/voice_model/voice_conference_model.rb
==============================================================================
--- freeswitch/trunk/scripts/contrib/jpalley/telegraph/trunk/lib/freeswitch/voice_model/voice_conference_model.rb (original)
+++ freeswitch/trunk/scripts/contrib/jpalley/telegraph/trunk/lib/freeswitch/voice_model/voice_conference_model.rb Wed Aug 6 12:17:30 2008
@@ -17,11 +17,11 @@
end
def start_recording(filename)
- @connector.send_command('conference', "#{@name} record #{filename}")
+ @@connector.send_command('conference', "#{@name} record #{filename}")
end
def stop_recording(filename)
- @connector.send_command('conference', "#{@name} norecord #{filename}")
+ @@connector.send_command('conference', "#{@name} norecord #{filename}")
end
def self.find(id)
@@ -78,11 +78,8 @@
end
def update_attributes(params)
- puts "UPDATE"
- pp params
+
params.each do |k,v|
- puts "param"
- puts k.to_sym
if [:mute, :deaf].include?(k.to_sym)
tru = (v and not v == "0")
prefix = tru ? '' : 'un'
@@ -92,7 +89,6 @@
end
end
elsif [:volume_in, :volume_out, :energy].include?(k.to_sym)
- puts "in valume"
if @connector.send_command('conference', "#{conf_name} #{k.to_s} #{id} #{v}")
self.send("#{k}=", v)
end
Modified: freeswitch/trunk/scripts/contrib/jpalley/telegraph/trunk/lib/freeswitch/voice_model/voice_connector.rb
==============================================================================
--- freeswitch/trunk/scripts/contrib/jpalley/telegraph/trunk/lib/freeswitch/voice_model/voice_connector.rb (original)
+++ freeswitch/trunk/scripts/contrib/jpalley/telegraph/trunk/lib/freeswitch/voice_model/voice_connector.rb Wed Aug 6 12:17:30 2008
@@ -22,7 +22,6 @@
def self.load_configuration_and_connect!
config = Telegraph.config
-
Telegraph::FreeSWITCH::VoiceConnector.new.connect!(:server=>config['server'], :port=>config['model']['port'], :username=>config['model']['username'], :password=>config['model']['password'], :timeout=>10)
end
@@ -57,10 +56,10 @@
name_array = []
return_array = []
result.split("\n").each do |line|
- if name_array.empty?
+ if line =~ /Content-Type/ or line.empty? or line =~ /\d+ total\./
+ #Do nothing
+ elsif name_array.empty?
name_array = line.split(',')
- elsif line.empty?
- break
else
item = Hash.new
line.split(',').each_with_index{|v,i| item[name_array[i].to_sym]=v}
Modified: freeswitch/trunk/scripts/contrib/jpalley/telegraph/trunk/lib/freeswitch/voice_model/voice_sip_model.rb
==============================================================================
--- freeswitch/trunk/scripts/contrib/jpalley/telegraph/trunk/lib/freeswitch/voice_model/voice_sip_model.rb (original)
+++ freeswitch/trunk/scripts/contrib/jpalley/telegraph/trunk/lib/freeswitch/voice_model/voice_sip_model.rb Wed Aug 6 12:17:30 2008
@@ -32,7 +32,7 @@
@@connector ||=VoiceConnector.new
@@data_cache ||= Hash.new
if @@data_cache[:set_at].nil? or @@data_cache[:set_at] < 3.second.ago.utc
- data = @@connector.send_command("sofia", "status profile default")
+ data = @@connector.send_command("sofia", "status profile #{profile}")
@@data_cache[:data] = data
@@data_cache[:set_at] = Time.now.utc
else
Modified: freeswitch/trunk/scripts/contrib/jpalley/telegraph/trunk/lib/freeswitch/voice_view_interface.rb
==============================================================================
--- freeswitch/trunk/scripts/contrib/jpalley/telegraph/trunk/lib/freeswitch/voice_view_interface.rb (original)
+++ freeswitch/trunk/scripts/contrib/jpalley/telegraph/trunk/lib/freeswitch/voice_view_interface.rb Wed Aug 6 12:17:30 2008
@@ -93,6 +93,31 @@
msg "export", val
end
+ def speak(txt, engine="flite", voice="kal")
+ msg "set", "tts_engine=#{engine}"
+ msg "set", "tts_voice=#{voice}"
+ msg "speak", txt
+ end
+
+ def transfer(extension, dialplan='', context='')
+ msg "transfer", "#{extension} #{dialplan} #{context}"
+ end
+ def dtmf_read(max = 10, sound = nil, fs_var_name = "dtmf_inputs", timeout = 10000, terminators = '#,*')
+ sound ||= 'misc/8000/silence.wav'
+ msg "read", "1 #{max} #{sound} #{fs_var_name} #{timeout} #{terminators}"
+ end
+
+ ##############
+ # For FORMS
+ ##################
+ def build_form_element(element)
+ dtmf_read(element[:max_digits], element[:sound], element[:param], element[:timeout], element[:terminators]) if element[:type]==:get_dtmf
+ end
+
+ def create_redirect(url, method="GET")
+ set("http_method=#{method}")
+ transfer "'socket:${rails_server}#{url} async full'", "inline"
+ end
private
def msg(app, params='')
@commands << {:type=>:msg, :app=>app, :params=>params}
Modified: freeswitch/trunk/scripts/contrib/jpalley/telegraph/trunk/lib/freeswitch/voice_view_server.rb
==============================================================================
--- freeswitch/trunk/scripts/contrib/jpalley/telegraph/trunk/lib/freeswitch/voice_view_server.rb (original)
+++ freeswitch/trunk/scripts/contrib/jpalley/telegraph/trunk/lib/freeswitch/voice_view_server.rb Wed Aug 6 12:17:30 2008
@@ -61,14 +61,22 @@
def hashify data
hsh = Hash.new
data.split("\n").each do |line|
- hsh[line.split(': ')[0].gsub('-', '_').downcase] = line.split(': ')[1] unless line.empty?
+ unless line.empty?
+ key,value = line.split(': ')
+ key = key.gsub('-', '_').downcase
+
+ hsh[key] = value
+ non_variable_key = key.gsub(/^variable\_/, '') #remove variable_ from keys
+ hsh[non_variable_key] = value
+ end
end
- return hsh
+ return hsh.with_indifferent_access
end
def send_application app, params=nil
msg = "SendMsg #{@connection_params['unique-id']}\ncall-command: execute\nexecute-app-name: #{app}"
msg << "\nexecute-app-arg: #{params}" #if params
+ msg << "\nevent-lock: true"
send msg
end
More information about the Freeswitch-svn
mailing list