Support transcription disablement option

Stephen Paul Weber created

Change summary

lib/backend_sgx.rb   |  9 +++++++++
lib/customer.rb      |  2 +-
views/voicemail.slim |  2 +-
web.rb               | 15 ++++++++++++---
4 files changed, 23 insertions(+), 5 deletions(-)

Detailed changes

lib/backend_sgx.rb 🔗

@@ -1,6 +1,8 @@
 # frozen_string_literal: true
 
 class BackendSgx
+	VOICEMAIL_TRANSCRIPTION_DISABLED = 0
+
 	def initialize(customer_id, jid=CONFIG[:sgx], creds=CONFIG[:creds])
 		@customer_id = customer_id
 		@jid = jid
@@ -37,6 +39,13 @@ class BackendSgx
 		REDIS.get("catapult_ogm_url-#{from_jid}")
 	end
 
+	def catapult_flag(flagbit)
+		REDIS.getbit(
+			"catapult_setting_flags-#{from_jid}",
+			flagbit
+		).then { |x| x != 1 }
+	end
+
 	def fwd_timeout
 		REDIS.get("catapult_fwd_timeout-#{from_jid}")
 	end

lib/customer.rb 🔗

@@ -22,7 +22,7 @@ class Customer
 	def_delegators :@plan, :active?, :activate_plan_starting_now, :bill_plan,
 	               :currency, :merchant_account, :plan_name, :auto_top_up_amount
 	def_delegators :@sgx, :register!, :registered?,
-	               :fwd_timeout, :set_fwd_timeout
+	               :fwd_timeout, :set_fwd_timeout, :catapult_flag
 	def_delegators :@usage, :usage_report, :message_usage, :incr_message_usage
 
 	def initialize(

views/voicemail.slim 🔗

@@ -4,7 +4,7 @@ Response
 	== render(*ogm.to_render)
 	PlayAudio= "/beep.mp3"
 	Record{
-		transcribe="true"
+		transcribe=transcription_enabled.to_s
 		recordingAvailableUrl="/inbound/calls/#{pseudo_call_id}/voicemail/audio"
 		transcriptionAvailableUrl="/inbound/calls/#{pseudo_call_id}/voicemail/transcription"
 		fileFormat="mp3"} /

web.rb 🔗

@@ -288,9 +288,18 @@ class Web < Roda
 						r.post do
 							customer_repo
 								.find_by_tel(params["to"])
-								.then { |customer| customer.ogm(params["from"]) }
-								.then do |ogm|
-									render :voicemail, locals: { ogm: ogm }
+								.then { |customer|
+									EMPromise.all([
+										customer.ogm(params["from"]),
+										customer.catapult_flag(
+											BackendSgx::VOICEMAIL_TRANSCRIPTION_DISABLED
+										)
+									])
+								}.then do |(ogm, transcription_disabled)|
+									render :voicemail, locals: {
+										ogm: ogm,
+										transcription_enabled: !transcription_disabled
+									}
 								end
 						end
 					end