Skip to content

Instantly share code, notes, and snippets.

@nathansamson
Created December 13, 2013 23:24
Show Gist options
  • Save nathansamson/7953339 to your computer and use it in GitHub Desktop.
Save nathansamson/7953339 to your computer and use it in GitHub Desktop.
class OfficeIVR < Adhearsion::CallController
before_call do
call.on_end do
@cdr.dialed_out_at = DateTime.now
end
end
def run
volunteer = metadata[:volunteer]
@cdr = metadata[:cdr]
if office_hours?
logger.info "DIALING ALICE"
#play "file://#{Rails.root}/lib/assets/audio/brotheriswatchingyou.wav"
#play "file://#{Rails.root}/lib/assets/audio/redirecting.wav"
call.on_joined do
logger.info "START recording"
@cdr.status = :connected
record async: true, start_beep: false do |event|
Rails.logger.info "Async recording saved to #{event.recording.uri}"
Rails.logger.info "Async recording saved to #{event.recording.inspect}"
file_name = event.recording.uri.gsub(/file:\/\//, '')
@cdr.recording = File.open(file_name)
logger.info "CDR UPDATED"
end
end
dial_status = dial 'user/userb'
success = dial_status.result == :answer
logger.info "CALL ENDED"
logger.info dial_status.result
if success
@cdr.status = :connected
elsif call.active?
@cdr.status = :unreachable
play "file://#{Rails.root}/lib/assets/audio/noonefound.wav"
end
logger.info "#{@cdr.status}"
else
@cdr.status = :closed
play "file://#{Rails.root}/lib/assets/audio/closed.wav"
end
hangup if call.active?
logger.info "CDR SAVE 2"
@cdr.save!
end
def office_hours?
return true
return DateTime.now.hour >= 9 && DateTime.now.hour < 20
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment