Class: VoicemailsMailbox
- Inherits:
-
ApplicationMailbox
- Object
- ActionMailbox::Base
- ApplicationMailbox
- VoicemailsMailbox
- Defined in:
- app/mailboxes/voicemails_mailbox.rb
Overview
Processes voicemail emails from phone systems (Switchvox PBX or hosted PBX).
Phone systems are configured to email voicemail recordings as WAV attachments.
Email routing:
voicemail@warmlyyours.com → This mailbox (Switchvox, no extension)
voicemail+XXX@warmlyyours.com → This mailbox (XXX = extension number)
Workflow:
- Extract caller info from email headers/body
- Extract WAV attachment
- Create CallRecord with call_outcome: :voicemail
- Match employee by extension (from email recipient or body)
- Match caller to an existing Customer/Contact (no Customer is created
for unknown callers — that happens on demand from the call record) - Create an open follow-up Activity only when the caller is matched and
the destination employee has not opted out (process_voicemails) - Queue for transcription (which also emails the destination employee)
Supported email formats:
Switchvox:
From: "Switchvox" switchvox@warmlyyours.com
Subject: Voicemail from [Caller Name] <[Caller Number]>
Body: Contains VM details (duration, date, mailbox)
Attachment: msg*.wav
Hosted PBX:
Body: "You received a message from (+17043707833). The message is in mailbox 401, ..."
Attachment: .wav file
Constant Summary collapse
- RECIPIENT_FORMAT =
Recipient format.
/voicemail(?:\+(\d+))?@/i- MIN_DURATION_SECONDS =
Minimum duration seconds.
5
Constants inherited from ApplicationMailbox
ApplicationMailbox::DIRECT_FILE_EXTENSIONS, ApplicationMailbox::FETCHABLE_MIME_TYPES, ApplicationMailbox::FETCH_MAX_SIZE, ApplicationMailbox::GDRIVE_FILE_RE, ApplicationMailbox::GDRIVE_OPEN_RE, ApplicationMailbox::MAX_FILENAME_LENGTH
Instance Method Summary collapse
-
#process ⇒ void
Processes the voicemail email: extracts caller metadata, saves the WAV attachment, creates the CallRecord, and queues transcription.
Methods inherited from ApplicationMailbox
#attempt_url_download, #collect_fetchable_urls, #create_activity, #create_communication, #fetch_linked_files, #find_sender_party, #get_resource_id, #inline_or_attachment_part?, #process_attachments, #process_content, #replace_cid_references, #sanitize_attachment_filename
Instance Method Details
#process ⇒ void
This method returns an undefined value.
Processes the voicemail email: extracts caller metadata, saves the WAV
attachment, creates the CallRecord, and queues transcription.
43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 |
# File 'app/mailboxes/voicemails_mailbox.rb', line 43 def process Rails.logger.info "[VoicemailsMailbox] Processing voicemail email: #{mail.subject}" = = unless Rails.logger.warn "[VoicemailsMailbox] No WAV attachment found in email #{inbound_email.id}" return end if [:duration_secs] && [:duration_secs] < MIN_DURATION_SECONDS Rails.logger.info "[VoicemailsMailbox] Skipping short voicemail (#{[:duration_secs]}s) from #{[:caller_number]}" return end call_record = create_voicemail_record() attach_wav_to_record(call_record, ) # Only matched callers whose destination employee still has voicemail # processing enabled get an automatic follow-up Activity. Unmatched callers # (and opted-out employees) are surfaced via email + the "Create Customer" # button on the call record (see CallRecordProcessing::VoicemailFollowup). CallRecordProcessing::VoicemailFollowup.new(call_record).create_activity if call_record.voicemail_processing_enabled? queue_transcription(call_record) Rails.logger.info "[VoicemailsMailbox] Created CallRecord #{call_record.id} for voicemail from #{[:caller_number]}" end |