Follow-Up Logic
Our Follow-Up logic is very similar to that of our Drip Logic.
Sending is based on the configuration of the associated FollowUp record. Here's a high-level overview of the logic:
- Retrieve the
FollowUprecord by ID and validate its status. - Validate the
FollowUp(and associatedBlastContact) data, including:- Property details (checking against blocked properties, cities, and states, as well as properties we own)
- Contact details (ensure email and first name are present)
- Outlook login credentials (confirm the sending
OutlookLoginis signed in with valid credentials) - Script details (check that the script is properly filled in)
- Do Not Contact (DNC) list
- Build the email subject and body from the associated script and script variants.
- Generate the email signature.
- Find the email to respond to
- This process is particularly critical to ensuring accurate emails
- The current algorithm initially looks for the email sent from the
Associateinitiating the follow-up - Once this message is found, we retrieve the entire conversation, and then remove any emails to teddy@pak-records.info
- With this finalized conversation, we take the most recently sent message and use this to respond
- Send a follow-up email using the Outlook login credentials.
- Update the
FollowUprecord:- Set the
LastContactedtimestamp. - If the next
FollowUpScriptis not present, and the status is not "failed", mark the record as completed. - Otherwise, find the next script based on the
NextFollowUpScriptfield and associate ID. - Update the
FollowUprecord with the new script details and status.
- Set the
- Handle any errors that occur during the process:
- Update the
FollowUpstatus and failure reason based on the error type. - If the error is related to an invalid sender or expired follow-up, handle it accordingly.
- If the error is related to a failed token refresh, update the Outlook login credentials.
- Update the
The process relies on several helper functions to validate data, fill email templates, and handle errors. The sendNewEmail and sendReply functions are responsible for constructing and sending the actual emails using the Microsoft Graph API.
By following this logic, our system ensures that follow-up emails are sent according to the configured scripts and contact details, while handling various error scenarios and updating the relevant records in our database.