Class: OpportunitiesMailbox
- Inherits:
-
ApplicationMailbox
- Object
- ActionMailbox::Base
- ApplicationMailbox
- OpportunitiesMailbox
- Defined in:
- app/mailboxes/opportunities_mailbox.rb
Overview
ActionMailbox: opportunities.
Routes inbound email addressed to an opportunity (opp+id@…) into a
Communication and follow-up Activity on that Opportunity.
Constant Summary collapse
- RECIPIENT_FORMAT =
Recipient format.
/opp(?:_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_opportunity ⇒ void
Resolves the Opportunity referenced by the recipient address, if any.
-
#process ⇒ void
Processes the inbound email: resolves the opportunity, 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_opportunity ⇒ void
This method returns an undefined value.
Resolves the Opportunity referenced by the recipient address, if any.
52 53 54 55 56 57 58 59 |
# File 'app/mailboxes/opportunities_mailbox.rb', line 52 def get_opportunity @opportunity = begin Opportunity.find(get_resource_id) rescue StandardError nil end Rails.logger.info "Opportunity Mailbox, opportunity retrieved. ID: #{@opportunity&.id}" end |
#process ⇒ void
This method returns an undefined value.
Processes the inbound email: resolves the opportunity, 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/opportunities_mailbox.rb', line 15 def process get_opportunity return if @opportunity.blank? Rails.logger.info "Processing Opportunity Mail for Opportunity ID #{@opportunity.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(@opportunity, 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(@opportunity.customer) || @opportunity.customer.sales_manager end create_activity(@opportunity, act_type, assigned_resource, comm, complete_act) end |