class Bell::Ami::Caller
Attributes
ami_stream[RW]
call_id[RW]
call_uniqueid[RW]
number[RW]
options[RW]
status[RW]
Public Class Methods
new(number, ami_stream,options={})
click to toggle source
# File lib/bell/ami/caller.rb, line 7 def initialize(number, ami_stream,options={}) @number=number @ami_stream=ami_stream @ami_stream.register_handler(self) if @ami_stream.ami_stream.started? @status='connected' else @status='initialized' end @call_id=SecureRandom.uuid @call_uniqueid=nil @options={'Priority'=> '1', 'Timeout'=> '30000', 'MaxRetries'=>'0', 'RetryTime'=>'15', 'WaitTime'=> '45', } @options.merge!(options) end
Public Instance Methods
dial(context, extention)
click to toggle source
# File lib/bell/ami/caller.rb, line 75 def dial(context, extention) @status='dialing' begin caller_id=%Q["#{@call_id}" <1000>] result=@ami_stream.ami_stream.send_action('Originate',@options.merge({"Channel"=>@number, 'Context'=> context, 'Exten'=> extention, 'Callerid': caller_id })) rescue RubyAMI::Error => e if @status=='dialing' @status='failed' end end end
dialed?()
click to toggle source
# File lib/bell/ami/caller.rb, line 91 def dialed? return @status=='dialing' end
finished?()
click to toggle source
# File lib/bell/ami/caller.rb, line 95 def finished? return @status=='errored' || @status=='failed' || @status=='succeeded' || @status=='not_answered' || @status=='busy' || @status=='not_available' end
handle_connected()
click to toggle source
# File lib/bell/ami/caller.rb, line 71 def handle_connected @status='connected' end
handle_disconnected()
click to toggle source
# File lib/bell/ami/caller.rb, line 63 def handle_disconnected if @status='dialing' @status='errored' else @status='errored' end end
handle_event(event)
click to toggle source
# File lib/bell/ami/caller.rb, line 23 def handle_event(event) case event.name when 'FullyBooted' @status='ready' when 'Hangup' if event['Uniqueid']==@call_uniqueid if @status=='in_call' @status='succeeded' else case event['Cause'] when '19'#User alerting, no answer @status='not_answered' when '17'#User busy @status='busy' when '16'#Normal Clearing @status='succeeded' else @status='not_available' end end end when 'NewCallerid' if event['CallerIDName']==@call_id @call_uniqueid=event['Uniqueid'] end when 'Newexten' if event['Uniqueid']==@call_uniqueid if event['Application']=='Answer' @status='in_call' end end when 'DTMF' if event['Uniqueid']==@call_uniqueid if event['End']=='Yes' STDOUT.puts event['Digit'] end end end end
ready?()
click to toggle source
# File lib/bell/ami/caller.rb, line 99 def ready? return @status=='ready' end
terminate()
click to toggle source
# File lib/bell/ami/caller.rb, line 87 def terminate end