Class: CallRecord::TwilioRecordingImporter
- Inherits:
-
Object
- Object
- CallRecord::TwilioRecordingImporter
- Defined in:
- app/services/call_record/twilio_recording_importer.rb
Overview
Imports call recordings from Twilio SIP Trunk
Runs parallel to Switchvox importer for testing/verification
Key features:
- Downloads dual-channel (stereo) MP3 recordings
- Stores separately from Switchvox records via
recording_sourcefield - Tracks
twilio_recording_sidto avoid duplicate imports - Filters to specific trunk ID if configured
Usage:
CallRecord::TwilioRecordingImporter.new.import_new_recordings
Configuration (via Setting):
- call_recording_twilio_trunk_id: Filter to specific trunk (optional)
- call_recording_twilio_enabled: Enable/disable Twilio import
Constant Summary collapse
- TRUNK_ID =
Target trunk ID for SIP recordings
Set via Setting.call_recording_twilio_trunk_id or override in options 'TKc7c6b6bb675a29978a90a617c207a3e1'
Instance Attribute Summary collapse
-
#logger ⇒ Object
readonly
Returns the value of attribute logger.
-
#options ⇒ Object
readonly
Returns the value of attribute options.
-
#twilio ⇒ Object
readonly
Returns the value of attribute twilio.
Instance Method Summary collapse
-
#import_new_recordings(limit: 50, since: nil) ⇒ Hash
Import new recordings from Twilio.
-
#initialize(options = {}) ⇒ TwilioRecordingImporter
constructor
A new instance of TwilioRecordingImporter.
Constructor Details
#initialize(options = {}) ⇒ TwilioRecordingImporter
Returns a new instance of TwilioRecordingImporter.
26 27 28 29 30 31 |
# File 'app/services/call_record/twilio_recording_importer.rb', line 26 def initialize( = {}) @options = @logger = [:logger] || Rails.logger @twilio = TwilioClient.instance @dry_run = [:dry_run] || false end |
Instance Attribute Details
#logger ⇒ Object (readonly)
Returns the value of attribute logger.
20 21 22 |
# File 'app/services/call_record/twilio_recording_importer.rb', line 20 def logger @logger end |
#options ⇒ Object (readonly)
Returns the value of attribute options.
20 21 22 |
# File 'app/services/call_record/twilio_recording_importer.rb', line 20 def @options end |
#twilio ⇒ Object (readonly)
Returns the value of attribute twilio.
20 21 22 |
# File 'app/services/call_record/twilio_recording_importer.rb', line 20 def twilio @twilio end |
Instance Method Details
#import_new_recordings(limit: 50, since: nil) ⇒ Hash
Import new recordings from Twilio
37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 |
# File 'app/services/call_record/twilio_recording_importer.rb', line 37 def import_new_recordings(limit: 50, since: nil) since ||= last_import_time || 24.hours.ago logger.info "[TwilioRecordingImporter] Starting import (since: #{since}, limit: #{limit})" recordings = fetch_recordings(since: since, limit: limit) logger.info "[TwilioRecordingImporter] Found #{recordings.count} recordings to process" results = { processed: 0, imported: 0, skipped: 0, errors: 0 } recordings.each do |recording| result = process_recording(recording) results[:processed] += 1 case result when :imported results[:imported] += 1 when :skipped, :already_imported, :wrong_trunk results[:skipped] += 1 when :error results[:errors] += 1 end end logger.info "[TwilioRecordingImporter] Complete: #{results.inspect}" results end |