Class: CustomersMailbox
- Inherits:
-
ApplicationMailbox
- Object
- ActionMailbox::Base
- ApplicationMailbox
- CustomersMailbox
- Defined in:
- app/mailboxes/customers_mailbox.rb
Overview
ActionMailbox: customers.
Routes inbound email addressed to a customer (cus+id@…) into a
Communication and follow-up Activity on that Customer.
Constant Summary collapse
- RECIPIENT_FORMAT =
Recipient format.
/cus(?:_case)?\+id(.+)@/i
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
-
#get_customer ⇒ void
Resolves the Customer referenced by the recipient address, if any.
-
#process ⇒ void
Processes the inbound email: resolves the customer, creates the communication and attachments, and creates the follow-up activity.
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
#get_customer ⇒ void
This method returns an undefined value.
Resolves the Customer referenced by the recipient address, if any.
52 53 54 55 56 57 58 59 |
# File 'app/mailboxes/customers_mailbox.rb', line 52 def get_customer @customer = begin Customer.find(get_resource_id) rescue StandardError nil end Rails.logger.info "Customer Mailbox, customer retrieved. ID: #{@customer&.id}" end |
#process ⇒ void
This method returns an undefined value.
Processes the inbound email: resolves the customer, creates the
communication and attachments, and creates the follow-up activity.
15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 |
# File 'app/mailboxes/customers_mailbox.rb', line 15 def process get_customer return if @customer.blank? Rails.logger.info "Processing Customer Mail for Customer ID #{@customer.id}" if mail.from.any? { |a| a.include?('@warmlyyours.com') } comm_state = 'sent' comm_direction = 'outbound' act_type = 'EMAILOUT' complete_act = true else comm_state = 'received' comm_direction = 'inbound' act_type = 'EMAILIN' complete_act = false end note = process_content(mail) comm = create_communication(@customer, mail, note, comm_state, comm_direction) (comm, mail) follow_up_activity_type = ActivityType.find_by(task_type: act_type) sender_party = find_sender_party(mail) assigned_resource = if sender_party.present? && sender_party.is_employee? sender_party else follow_up_activity_type.determine_assigned_resource(@customer) || @customer.sales_manager end create_activity(@customer, act_type, assigned_resource, comm, complete_act) end |