-
Notifications
You must be signed in to change notification settings - Fork 8
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: add helper for email recipients #41
Merged
Merged
Conversation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
size-limit report 📦
|
muhsin-k
approved these changes
Feb 6, 2025
scmmishra
added a commit
to chatwoot/chatwoot
that referenced
this pull request
Feb 11, 2025
This PR target two issues ### CC & BCC not updated correctly When moving from one conversation to another, the store may not have the list of all the messages. A fetch is subsequently made to get the messages. However, this update does not trigger the `currentChat` watcher. This PR fixes it by adding a new watcher on `currentChat.messages`. We also update the `setCCAndToEmailsFromLastChat` method to reset the `cc`, `bcc` and `to` fields if the last email is not found. This ensures that the data is not carried forward from a previous email Fixes: #10477 ### To address are not added correctly to the `CC` If the `to` address of a previous email has multiple recipient, there was no case to add them to the CC. Fixes: #8925 --- Depends on: chatwoot/utils#41
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This PR adds a
getRecipients
which takes an email message and returns what will be theto
,cc
andbcc
email to reply to. The following are the docs for thisgetRecipients
The
getRecipients
function determines the recipients for an email reply based on the last email message's details, the conversation contact, and system-specific email addresses. This utility is designed to simplify the process of building recipient lists for outgoing emails.Overview
Given a last email (either incoming or outgoing), a conversation contact, and system emails (inbox and forward-to),
getRecipients
constructs and returns three lists:To: The primary recipient.
from
field).to
field).CC: The carbon copy list containing:
to
(in addition to the primary recipient for proper context).BCC: The blind carbon copy list is typically used for internal purposes. Any instance of the conversation contact is removed from this list because they are already added in the CC.
Additionally, all recipient lists are deduplicated to ensure that each email address appears only once.
Parameters
lastEmail
(EmailMessage
):The last email message of the conversation. It should contain:
message_type
property (indicating whether the message was incoming or outgoing).content_attributes.email
object containing:from
: An array of sender email addresses.to
: An array of recipient email addresses.cc
: An optional array of carbon copy email addresses.bcc
: An optional array of blind carbon copy email addresses.conversationContact
(string
):The email address of the contact with whom the conversation is taking place. This is used to determine which email addresses to add (or remove) from the recipient lists.
inboxEmail
(string
):The email address of the system's inbox. This is removed from the CC list to avoid email loops.
forwardToEmail
(string
):The system's forwarding email address. This is also removed from the CC list to prevent email loops.
Return Value
Returns an object with the following properties:
to
(string[]
):An array of email addresses for the primary recipient.
cc
(string[]
):An array of email addresses for the CC recipients, excluding system emails and duplicate values.
bcc
(string[]
):An array of email addresses for the BCC recipients, with the conversation contact removed if present.
Usage Example