~singpolyma/sgx-jmp

08049e9908b4b2a11784296e22a1f8e6ea402d94 — Stephen Paul Weber a month ago df6b3ed
Use disposition=VOICEMAIL for calls that went to voicemail
2 files changed, 15 insertions(+), 13 deletions(-)

M lib/cdr.rb
M views/voicemail.slim
M lib/cdr.rb => lib/cdr.rb +14 -13
@@ 5,20 5,21 @@ require "value_semantics/monkey_patched"
class CDR
	module Disposition
		def self.===(other)
			["NO ANSWER", "ANSWERED", "BUSY", "FAILED"].include?(other)
			["NO ANSWER", "ANSWERED", "BUSY", "FAILED", "VOICEMAIL"].include?(other)
		end

		def self.for(cause)
			case cause
			when "timeout", "rejected", "cancel"
				"NO ANSWER"
			when "hangup"
				"ANSWERED"
			when "busy"
				"BUSY"
			else
				"FAILED"
			end
		CAUSES = {
			timeout: "NO ANSWER",
			rejected: "NO ANSWER",
			cancel: "NO ANSWER",
			hangup: "ANSWERED",
			busy: "BUSY"
		}.freeze

		def self.for(cause, tag)
			return tag if tag == "VOICEMAIL"

			CAUSES.fetch(cause.to_sym, "FAILED")
		end
	end



@@ 39,7 40,7 @@ class CDR
			cdr_id: "sgx-jmp/#{event['callId']}",
			start: start,
			billsec: (Time.parse(event["endTime"]) - start).ceil,
			disposition: Disposition.for(event["cause"])
			disposition: Disposition.for(event["cause"], event["tag"])
		}.merge(kwargs))
	end


M views/voicemail.slim => views/voicemail.slim +1 -0
@@ 1,5 1,6 @@
doctype xml
Response
	Tag= "VOICEMAIL"
	Pause duration=2 /
	== render(*ogm.to_render)
	PlayAudio= "/beep.mp3"