Class: Phone::BpoCallRecordingLinker
- Inherits:
-
Object
- Object
- Phone::BpoCallRecordingLinker
- Defined in:
- app/services/phone/bpo_call_recording_linker.rb
Overview
Attaches imported Twilio BPO recordings (CallRecords) to the CallLogEvents of
the BPO call they belong to.
Each BPO call produces up to two trunk recordings (see
CallRecordTwilioRecordingImporter):
- the terminating leg (customer <-> BPO cascade number) -> attached to the
TALKING event with ext 602 ("BPO 24x7"), - the originating leg (full inbound call incl. IVR) -> attached to the first
INCOMING event.
Matching rides on the customer number + call time window, which is already a
strong signal for the ~1 BPO call/day volume; the talk-duration sanity check
only decides BETWEEN candidates, it never blocks a sole candidate.
This bypasses Phone::CallLogEventToRecordMatcher deliberately — its
two-sided duration gate rejects full-call trunk recordings. The unique index
on call_log_events.call_record_id is the backstop, and unmatched records stay
unlinked so the next hourly run can reconsider them (the window absorbs
call-log import lag).
Usage:
Phone::BpoCallRecordingLinker.new.link(since: 4.hours.ago)
Constant Summary collapse
- TIME_TOLERANCE =
How far outside the CallLog's [start_time, start_time + total_duration]
window a recording's timestamp may fall and still count as this call. 3.minutes
- DURATION_TOLERANCE_SECS =
Warn (never block) when the terminating leg's recording duration differs
from the CallLog's talk_duration by more than this. 15
Instance Attribute Summary collapse
-
#logger ⇒ Object
readonly
Returns the value of attribute logger.
Instance Method Summary collapse
-
#initialize(logger: Rails.logger) ⇒ BpoCallRecordingLinker
constructor
A new instance of BpoCallRecordingLinker.
-
#link(since: 4.hours.ago) ⇒ Hash
Summary { call_logs:, linked:, skipped: }.
Constructor Details
#initialize(logger: Rails.logger) ⇒ BpoCallRecordingLinker
Returns a new instance of BpoCallRecordingLinker.
37 38 39 |
# File 'app/services/phone/bpo_call_recording_linker.rb', line 37 def initialize(logger: Rails.logger) @logger = logger end |
Instance Attribute Details
#logger ⇒ Object (readonly)
Returns the value of attribute logger.
35 36 37 |
# File 'app/services/phone/bpo_call_recording_linker.rb', line 35 def logger @logger end |
Instance Method Details
#link(since: 4.hours.ago) ⇒ Hash
Returns Summary { call_logs:, linked:, skipped: }.
43 44 45 46 47 48 49 50 51 52 53 |
# File 'app/services/phone/bpo_call_recording_linker.rb', line 43 def link(since: 4.hours.ago) stats = { call_logs: 0, linked: 0, skipped: 0 } Phone::Bpo.bpo_call_logs.where(start_time: since..).find_each do |call_log| stats[:call_logs] += 1 link_call_log(call_log, stats) end logger.info "[BpoCallRecordingLinker] Complete: #{stats.inspect}" stats end |