Skip to content
deathsyn edited this page Mar 10, 2011 · 1 revision

An Outbound Event Listener Example that reads and returns DTMF input:

Simply just create a subclass of FSR::Listner::Outbound and all new calls/sessions will invoke the "session_initiated" callback method.

NOTE: FSR uses blocks within the ‘session_inititated’ method to ensure that the next "freeswich command" is not executed until the previous "Freeswitch command" has finished. (Basically a continuation) This is kicked off by "answer do".

#!/usr/bin/ruby
require 'fsr'
require 'fsr/listener/outbound'

class OutboundDemo < FSR::Listener::Outbound

  def session_initiated
    exten = @session.headers[:caller_caller_id_number]
    FSR::Log.info "*** Answering incoming call from #{exten}"

    answer do
      FSR::Log.info "***Reading DTMF from #{exten}"
      read("/home/freeswitch/freeswitch/sounds/music/8000/sweet.wav", 4, 10, "input", 7000) do |read_var|
        FSR::Log.info "***Success, grabbed #{read_var.to_s.strip} from #{exten}"
        # Tell the caller what they entered
        speak("Got the DTMF of: #{read_var.to_s.strip}") do
          #Hangup the call
          hangup
        end
      end
    end
  end

end

FSR.start_oes! OutboundDemo, :port => 8084, :host => "127.0.0.1"
Clone this wiki locally