Skip to content

Instantly share code, notes, and snippets.

@vangberg
Created November 18, 2009 22:21
Show Gist options
  • Save vangberg/238324 to your computer and use it in GitHub Desktop.
Save vangberg/238324 to your computer and use it in GitHub Desktop.
freeswitcher: inbound/outbound event listener
require 'fsr'
require 'fsr/listener/inbound'
class MyInbound < FSR::Listener::Inbound
# `on_event` is called every time an event is received.
def on_event
# Be sure to check out the content of `event`. It has all the good stuff.
FSR::Log.info "Got event: #{event.content[:event_name]}"
end
# You can add a hook for a certain event:
add_event_hook :CHANNEL_HANGUP do
FSR::Log.info "Channel hangup!"
# It is instance_eval'ed, so you can use your instance methods etc:
do_something
end
def do_something
...
end
end
FSR.start_ies! MyInbound, :auth => "somepwd"
require 'fsr'
require 'fsr/listener/outbound'
class MyApp < FSR::Listener::Outbound
def session_initiated
answer
playback "/path/to/file.wav"
# Whenever we expect a meaningful answer from a command (basically, that means
# `play_and_get_digits` and `read` we have to pass it a block. The return value
# will be passed to the block argument.
play_and_get_digits "/sounds/enter-digit.wav", "/sounds/wrong-digit.wav" do |digit|
# Set channel variables
set "playback_terminators", "#"
# For apps not added to FSR yet (see lib/fsr/app) you can use
# `execute_app "app_name", "app arguments"` to execute generic Freeswitch commands
# as seen on http://wiki.freeswitch.org/wiki/Category:Dialplan
execute_app "record", "/sound-recordings/user-recording-#{digit}.wav"
bridge "sofia/foo/bar", "sofia/foo/baz"
end
end
end
FSR.start_oes! MyApp, :port => 8084, :host => "127.0.0.1"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment