Skip to content

Instantly share code, notes, and snippets.

@wwalker
Created May 25, 2009 21:32
Show Gist options
  • Save wwalker/117763 to your computer and use it in GitHub Desktop.
Save wwalker/117763 to your computer and use it in GitHub Desktop.
require 'pp'
def handle_originate_response
ahn_log "Looking for a matching OriginateResponses key: #{event.headers['ActionID']}"
attempt_id = OriginateResponses[event.headers['ActionID']]
ahn_log "attempt_id is #{attempt_id}"
if attempt_id
if event.headers['Response'] == 'Success'
ahn_log "Doing Nothing, the call was answered, it will be handled in the context"
else
ahn_log "Retrieving attempt"
attempt = Attempt.find_by_id(attempt_id)
if attempt
ahn_log "Retrieved attempt!!"
attempt.delivered_at = Time.now()
attempt.current_state = STATE_RETRY
attempt.save
Attempt.increment_counter(:retries, attempt.id)
else
ahn_log "Originate Response pointed to an Originate Request with an invalid attempt_id!!!!!!!"
end
end
else
ahn_log "Originate Response had an untracked or empty ActionID"
end
end
events.asterisk.manager_interface.each do |event|
if event.name == 'OriginateResponse'
ahn_log "Received an Originate Response: #{event.inspect}"
handle_originate_response(event)
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment