Class: TwilioClient
- Inherits:
-
Object
- Object
- TwilioClient
- Includes:
- Singleton
- Defined in:
- app/services/twilio_client.rb
Delegated Instance Attributes collapse
-
#client ⇒ Object
readonly
Alias for Instance#client.
Instance Attribute Summary collapse
-
#default_sender ⇒ Object
readonly
Returns the value of attribute default_sender.
-
#logger ⇒ Object
readonly
Returns the value of attribute logger.
Delegated Instance Attributes collapse
-
#download_recording(recording_sid, dual_channel: true) ⇒ String
Download a recording as WAV (required when call recording encryption is enabled) SIP trunk recordings are natively stereo (2 channels) - preserved in WAV format.
-
#list_numbers ⇒ Object
Alias for Instance#list_numbers.
-
#list_recordings(date_created_after: nil, limit: 100) ⇒ Array<Hash>
List recordings from Twilio.
-
#send_message(from: nil, to:, body:, media_urls: nil) ⇒ Object
============================================================================ SMS Methods ============================================================================.
Instance Method Summary collapse
-
#delete_recording(recording_sid) ⇒ Object
Delete a recording from Twilio (after successful import).
-
#get_call(call_sid) ⇒ Hash
Get call details for a recording (to extract phone numbers).
-
#initialize(options = {}) ⇒ TwilioClient
constructor
A new instance of TwilioClient.
Constructor Details
#initialize(options = {}) ⇒ TwilioClient
Returns a new instance of TwilioClient.
15 16 17 18 19 20 21 22 23 24 25 |
# File 'app/services/twilio_client.rb', line 15 def initialize( = {}) @logger = [:logger] || Rails.logger account_sid = [:account_sid] || Heatwave::Configuration.fetch(:twilio, :account_sid) auth_token = [:auth_token] || Heatwave::Configuration.fetch(:twilio, :auth_token) @account_sid = account_sid @auth_token = auth_token @sms_status_callback_url = [:sms_status_callback_url] @sms_status_callback_url ||= "#{Heatwave::Configuration.fetch(:twilio, :sms_base_wehook_url)}/update_status" @default_sender = [:default_sender] || '+18008755285' @client = Twilio::REST::Client.new account_sid, auth_token end |
Instance Attribute Details
#client ⇒ Object (readonly)
Alias for Instance#client
9 10 11 |
# File 'app/services/twilio_client.rb', line 9 def client @client end |
#default_sender ⇒ Object (readonly)
Returns the value of attribute default_sender.
9 10 11 |
# File 'app/services/twilio_client.rb', line 9 def default_sender @default_sender end |
#logger ⇒ Object (readonly)
Returns the value of attribute logger.
9 10 11 |
# File 'app/services/twilio_client.rb', line 9 def logger @logger end |
Instance Method Details
#delete_recording(recording_sid) ⇒ Object
Delete a recording from Twilio (after successful import)
145 146 147 148 149 150 151 152 |
# File 'app/services/twilio_client.rb', line 145 def delete_recording(recording_sid) client.recordings(recording_sid).delete logger.info "[TwilioClient] Deleted recording #{recording_sid}" true rescue Twilio::REST::RestError => e logger.error "[TwilioClient] Failed to delete recording #{recording_sid}: #{e.}" false end |
#download_recording(recording_sid, dual_channel: true) ⇒ String
Download a recording as WAV (required when call recording encryption is enabled)
SIP trunk recordings are natively stereo (2 channels) - preserved in WAV format
Note: Twilio error 16109 - When call recording encryption is enabled,
recordings can ONLY be downloaded in WAV format, not MP3.
See: https://www.twilio.com/docs/errors/16109
113 |
# File 'app/services/twilio_client.rb', line 113 delegate :client, :send_message, :list_numbers, :list_recordings, :download_recording, to: :instance |
#get_call(call_sid) ⇒ Hash
Get call details for a recording (to extract phone numbers)
84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 |
# File 'app/services/twilio_client.rb', line 84 def get_call(call_sid) call = client.calls(call_sid).fetch { sid: call.sid, from: call.from, to: call.to, direction: call.direction, duration: call.duration.to_i, start_time: call.start_time, end_time: call.end_time, status: call.status, # SIP trunk info if available trunk_sid: call.trunk_sid } rescue Twilio::REST::RestError => e logger.error "[TwilioClient] Failed to fetch call #{call_sid}: #{e.}" nil end |
#list_numbers ⇒ Object
Alias for Instance#list_numbers
12 |
# File 'app/services/twilio_client.rb', line 12 delegate :client, :send_message, :list_numbers, :list_recordings, :download_recording, to: :instance |
#list_recordings(date_created_after: nil, limit: 100) ⇒ Array<Hash>
List recordings from Twilio
59 |
# File 'app/services/twilio_client.rb', line 59 delegate :client, :send_message, :list_numbers, :list_recordings, :download_recording, to: :instance |
#send_message(from: nil, to:, body:, media_urls: nil) ⇒ Object
============================================================================
SMS Methods
31 |
# File 'app/services/twilio_client.rb', line 31 delegate :client, :send_message, :list_numbers, :list_recordings, :download_recording, to: :instance |