Class: VoicemailsMailbox

Inherits:
ApplicationMailbox show all
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:

  1. Extract caller info from email headers/body
  2. Extract WAV attachment
  3. Create CallRecord with call_outcome: :voicemail
  4. Match employee by extension (from email recipient or body)
  5. Match caller to existing Customer/Contact, or create lead_qualify Customer
  6. Create open Activity assigned to the employee for follow-up
  7. Queue for transcription

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 =
/voicemail(?:\+(\d+))?@/i
MIN_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

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

#processObject



36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
# File 'app/mailboxes/voicemails_mailbox.rb', line 36

def process
  Rails.logger.info "[VoicemailsMailbox] Processing voicemail email: #{mail.subject}"

   = 

  wav_attachment = find_wav_attachment
  unless wav_attachment
    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, wav_attachment)
  create_voicemail_activity(call_record, )
  queue_transcription(call_record)

  Rails.logger.info "[VoicemailsMailbox] Created CallRecord #{call_record.id} for voicemail from #{[:caller_number]}"
end