Created
June 23, 2010 05:40
-
-
Save cloudvoxcode/449550 to your computer and use it in GitHub Desktop.
place & receive a phone call with Ruby (Adhearsion)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require File.expand_path(File.dirname(__FILE__) + "/../../config/environment") | |
require 'adhearsion' | |
require 'adhearsion/initializer/asterisk' | |
require 'drb' | |
# http://help.cloudvox.com/faqs/getting-started/setup-for-ruby-adhearsion | |
desc "Make an outgoing phone call to number provided as 'call' (via Cloudvox)" | |
task :make_outgoing_call do | |
if ENV['call'] | |
# Outgoing context from Cloudvox Switchboard, under "Outgoing settings (AMI)." | |
# If you don't have one, create a free account at cloudvox.com and add an app. | |
# For example: | |
# outgoing_context = "outgoing-42" | |
outgoing_context = "OUTGOING_CONTEXT" | |
Adhearsion = DRbObject.new_with_uri 'druby://localhost:9050' | |
# channel example: Local/12063335555@outgoing-42 | |
Adhearsion.originate :channel => "Local/#{ENV['call']}@#{outgoing_context}", | |
#:variables => {:foo_id => 123, :bar_id => bar.id}, | |
:caller_id => "2063576220", | |
:context => outgoing_context, | |
:application => 'AGI', | |
# change this to your client 's hostname or IP | |
:data => 'agi://this.computer.com/' | |
else | |
print """ | |
Cloudvox Adhearsion outgoing example | |
http://help.cloudvox.com/ | |
Syntax: rake make_outgoing_call call=12065554444 | |
""" | |
return | |
end | |
end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
default { | |
say_digits 12345 | |
execute "swift", "\"I'm calling from Cloudvox to wish you a very happy birthday. This message could say anything, interact with the caller, play sounds | |
# .. more call processing .. | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
unless defined? Adhearsion | |
if File.exists? File.dirname(__FILE__) + "/../adhearsion/lib/adhearsion.rb" | |
# If you wish to freeze a copy of Adhearsion to this app, simply place a copy of Adhearsion | |
# into a folder named "adhearsion" within this app's main directory. | |
require File.dirname(__FILE__) + "/../adhearsion/lib/adhearsion.rb" | |
else | |
require 'rubygems' | |
gem 'adhearsion', '>= 0.8.2' | |
require 'adhearsion' | |
end | |
end | |
Adhearsion::Configuration.configure do |config| | |
# Supported levels (in increasing severity) -- :debug < :info < :warn < :error < :fatal | |
config.logging :level => :info | |
# Whether incoming calls be automatically answered. Defaults to true. | |
# config.automatically_answer_incoming_calls = false | |
# Whether the other end hanging up should end the call immediately. Defaults to true. | |
# config.end_call_on_hangup = false | |
# Whether to end the call immediately if an unrescued exception is caught. Defaults to true. | |
# config.end_call_on_error = false | |
# NOTE: Pay special attention to the argument_delimiter field below: | |
# For Asterisk <= 1.4, use "|" (default) | |
# For Asterisk >= 1.6, use "," | |
# The delimiter can also be specified in Asterisk's asterisk.conf. | |
# This setting applies only to AGI. The AMI delimiter is auto-detected. | |
config.enable_asterisk :argument_delimiter => '|' | |
# config.asterisk.enable_ami :host => "127.0.0.1", :username => "admin", :password => "password", :events => true | |
config.asterisk.enable_ami :host => "ami.cloudvox.com", :port => 5038, | |
:username => "MANAGER_USERNAME", :password => "MANAGER_PASSWORD", :events => true | |
config.enable_drb | |
# Streamlined Rails integration! The first argument should be a relative or absolute path to | |
# the Rails app folder with which you're integrating. The second argument must be one of the | |
# the following: :development, :production, or :test. | |
# config.enable_rails :path => 'gui', :env => :development | |
config.enable_rails :path => '../', :env => :development | |
# Note: You CANNOT do enable_rails and enable_database at the same time. When you enable Rails, | |
# it will automatically connect to same database Rails does and load the Rails app's models. | |
# Configure a database to use ActiveRecord-backed models. See ActiveRecord::Base.establish_connection | |
# for the appropriate settings here. | |
# You can also override the default log destination by supplying an alternate | |
# logging object with :logger. The default is ahn_log.db. | |
# config.enable_database :adapter => 'mysql', | |
# :username => 'joe', | |
# :password => 'secret', | |
# :host => 'db.example.org' | |
# Configure an LDAP connection using ActiveLdap. See ActiveLdap::Base.establish_connect | |
# for the appropriate settings here. | |
# config.enable_ldap :host => 'ldap.dataspill.org', | |
# :port => 389, | |
# :base => 'dc=dataspill,dc=org', | |
# :logger => ahn_log.ldap, | |
# :bind_dn => "uid=drewry,ou=People,dc=dataspill,dc=org", | |
# :password => 'password12345', | |
# :allow_anonymous => false, | |
# :try_sasl => false | |
# Configure XMPP call controller | |
# config.enable_xmpp :jid => 'active-calls.xmpp.example.com', | |
# :password => 'passwd', | |
# :server => 'xmpp.example.com', | |
# :port => 5347 | |
end | |
Adhearsion::Initializer.start_from_init_file(__FILE__, File.dirname(__FILE__) + "/..") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment