M lib/trivial_backend_sgx_repo.rb => lib/trivial_backend_sgx_repo.rb +4 -2
@@ 7,11 7,13 @@ class TrivialBackendSgxRepo
def initialize(
jid: CONFIG[:sgx],
creds: CONFIG[:creds],
- component_jid: CONFIG[:component][:jid]
+ component_jid: CONFIG[:component][:jid],
+ **with
)
@jid = Blather::JID.new(jid)
@creds = creds
@component_jid = component_jid
+ @with = with
end
def get(customer_id)
@@ 22,6 24,6 @@ class TrivialBackendSgxRepo
fwd: NotLoaded.new(:fwd_timeout),
transcription_enabled: NotLoaded.new(:transcription_enabled),
registered?: NotLoaded.new(:registered?)
- )
+ ).with(@with)
end
end
M web.rb => web.rb +23 -13
@@ 106,6 106,17 @@ class Web < Roda
opts[:customer_repo] || CustomerRepo.new(**kwargs)
end
+ def find_by_tel_with_fallback(sgx_repo:, **kwargs)
+ customer_repo(sgx_repo: sgx_repo).find_by_tel(params["to"]).catch { |e|
+ next EMPromise.reject(e) if e.is_a?(CustomerRepo::NotFound)
+
+ log_error(e)
+ customer_repo(
+ sgx_repo: TrivialBackendSgxRepo.new(**kwargs)
+ ).find_by_tel(params["to"])
+ }
+ end
+
def call_attempt_repo
opts[:call_attempt_repo] || CallAttemptRepo.new
end
@@ 223,9 234,10 @@ class Web < Roda
"https://jmp.chat"
)
- customer_repo(
- sgx_repo: Bwmsgsv2Repo.new
- ).find_by_tel(params["to"]).then do |customer|
+ find_by_tel_with_fallback(
+ sgx_repo: Bwmsgsv2Repo.new,
+ transcription_enabled: false
+ ).then do |customer|
start_transcription(customer, call_id, jmp_media_url)
m = Blather::Stanza::Message.new
@@ 280,16 292,14 @@ class Web < Roda
end
r.post do
- customer_repo(sgx_repo: Bwmsgsv2Repo.new)
- .find_by_tel(params["to"])
- .then { |c|
- EMPromise.all([c, c.ogm(params["from"])])
- }.then do |(customer, ogm)|
- render :voicemail, locals: {
- ogm: ogm,
- transcription_enabled: customer.transcription_enabled
- }
- end
+ find_by_tel_with_fallback(
+ sgx_repo: Bwmsgsv2Repo.new,
+ ogm_url: nil
+ ).then { |c|
+ c.ogm(params["from"])
+ }.then { |ogm|
+ render :voicemail, locals: { ogm: ogm }
+ }
end
end