Class: Adhearsion::DialPlan::Manager

Inherits:
Object
  • Object
show all
Defined in:
lib/adhearsion/voip/dial_plan.rb

Defined Under Namespace

Classes: NoContextError

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeManager

Returns a new instance of Manager.



109
110
111
# File 'lib/adhearsion/voip/dial_plan.rb', line 109

def initialize
  @dial_plan = DialPlan.new
end

Instance Attribute Details

#contextObject

Returns the value of attribute context.



108
109
110
# File 'lib/adhearsion/voip/dial_plan.rb', line 108

def context
  @context
end

#dial_planObject

Returns the value of attribute dial_plan.



108
109
110
# File 'lib/adhearsion/voip/dial_plan.rb', line 108

def dial_plan
  @dial_plan
end

Class Method Details

.handle(call) ⇒ Object



103
104
105
# File 'lib/adhearsion/voip/dial_plan.rb', line 103

def handle(call)
  new.handle(call)
end

Instance Method Details

#entry_point_for(call) ⇒ Object

Find the dialplan by the context name from the call or from the first path entry in the AGI URL



133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
# File 'lib/adhearsion/voip/dial_plan.rb', line 133

def entry_point_for(call)

  # Try the request URI for an entry point first
  if call.respond_to?(:request) && m = call.request.path.match(%r{/([^/]+)})
    if entry_point = dial_plan.lookup(m[1].to_sym)
      return entry_point
    else
      ahn_log.warn "AGI URI requested context \"#{m[1]}\" but matching Adhearsion context not found!  Falling back to Asterisk context."
    end
  end

  # Fall back to the matching Asterisk context name
  if entry_point = dial_plan.lookup(call.context.to_sym)
    return entry_point
  end
end

#handle(call) ⇒ Object

Raises:



113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
# File 'lib/adhearsion/voip/dial_plan.rb', line 113

def handle(call)
  if call.failed_call?
    environment = ExecutionEnvironment.create(call, nil)
    call.extract_failed_reason_from environment
    raise FailedExtensionCallException.new(environment)
  end

  if call.hungup_call?
    raise HungupExtensionCallException.new(ExecutionEnvironment.new(call, nil))
  end

  starting_entry_point = entry_point_for call
  raise NoContextError, "No dialplan entry point for call context '#{call.context}' -- Ignoring call!" unless starting_entry_point
  @context = ExecutionEnvironment.create(call, starting_entry_point)
  inject_context_names_into_environment @context
  @context.run
end