Calling Voice Views
Voice Views are standard actions in your controllers. They use rails route and can be called by the voice application in one of two ways
- Using the socket application in the freeswitch dialplan (see freeswitch docs).
2. From the VoiceChannelModel.create. For example:
MyVoiceChannel.create(:destination=>'sofia/default/1000', :callback=>url_for(:action=>:show))
Creating Voice Views
Telegraph tricks rails into thinking that a call from FreeSWITCH is really a web application call with a special mime type. First, you need to make sure your action responds to the voice mime type:
In your controller:
def show
# Business Logic Here
respond_to do |wants|
wants.html
wants.voice
end
endYes - you can share business logic between your voice and web application!
Next you need to create the view file. In this case, you would make: show.voice.freeswitch. This file works like an rjs file does. It might look like:
voice.answer
voice.set "hangup_after_bridge=true"
voice.ring_ready
voice.set "ringback=%(2000, 4000, 440.0, 480.0)"
voice.bridge params[:call_me]
Running
You have to run a separate rails server to listen for socket connections. Simply do the following
script/voice_view
Make sure voice_view has permission to execute.
You can also daemonize with the following
script/voice_view -a start -d
and
script/voice_view -a stop
See -h for more options.
Voice View Functions
Not all of the freeswitch socket functions have been implemented. They are easy to add. Please contribute..here are some that have been implemented:
- spell
- spell_phonetic
- say_time
- say_timespec
- answer
- play_sound
- record
- phrase
- bridge
- set
- conference
- hangup
- hold
- ring_ready
- socket
- fifo_in
- fifo_out
- export
Please see voice_view_interface.rb for complete implementation.
When using this from the socket, how do I see information about the call? Is there a standard session with all the variables and headers of this specific call?
Found it out. params
chan = voice.bridge should populate chan with variables about the call. Useful so you can get hangup cause/originate disposition etc.
consider
5.times do |i| chan = voice.bridge 'sofia/default/#{i}' puts chan.originate_disposition endIs this possible?
Sorry, the originate disposition is set on the originating channel. I think we should be able to do this.
channel = Telegraph.channels.find_by_uuid(params[:uuid]) puts channel.uuid channel2 = voice.bridge 'somewhere' # bridge returns a Channel object puts channel2.uuid # Prints the channel we are bridged to (actually channel2 if they are bridged) puts channel.bridged_to # This should also be possible 5.times do |i| chan = voice.bridge 'somewhere{i}' # bridge returns a Channel object # Returns the originate disposition of this bridge attempt puts "Originate dispos for call to {i}: " + channel.originate_disposition.to_s endI can't even start the server.
$ script/voice_view ** Starting Server ** ** Logging at /Users/alxx/Sites/rails/telegraph/log/voice_view_development.log ** ** Signals ready. TERM => stop. INT => stop (no restart). ** ** Exiting ** ** Exiting... ** /Users/alxx/Sites/rails/telegraph/vendor/plugins/telegraph/lib/core/voice_view/template.rb:43: undefined method `register_template_handler' for ActionView::Base:Class (NoMethodError) from /usr/local/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:27:in `gem_original_require' from /usr/local/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:27:in `require' from /usr/local/lib/ruby/gems/1.8/gems/activesupport-2.1.0/lib/active_support/dependencies.rb:509:in `require' from /usr/local/lib/ruby/gems/1.8/gems/activesupport-2.1.0/lib/active_support/dependencies.rb:354:in `new_constants_in' from /usr/local/lib/ruby/gems/1.8/gems/activesupport-2.1.0/lib/active_support/dependencies.rb:509:in `require' from script/voice_view:12 from script/voice_view:11:in `each' from script/voice_view:11 from ./script/../vendor/plugins/telegraph/lib/core/script_base.rb:101:in `start' from ./script/../vendor/plugins/telegraph/lib/core/script_base.rb:56:in `initialize' from script/voice_view:5:in `new' from script/voice_view:5Using Rails 2.1.
That was because in Rails 2.1, the method register_template_handler has been moved to ActionView?::Template.
In voice_view_server.rb the following command is returning the expected result:
While the following command is sending an error: