Skip to content
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

Emails sent and received by email aliases are not associated with the workspaceMember #5748

Open
bosiraphael opened this issue Jun 5, 2024 · 4 comments · May be fixed by #5855
Open

Emails sent and received by email aliases are not associated with the workspaceMember #5748

bosiraphael opened this issue Jun 5, 2024 · 4 comments · May be fixed by #5855
Assignees
Labels
type: bug Something isn't working

Comments

@bosiraphael
Copy link
Contributor

Bug Description

Emails sent and received by email aliases are not associated with the workspaceMember and contacts are not created.

Expected behavior

Associate messages with the workspaceMember and create contacts for emails sent or received by email aliases.

Technical inputs

Use the users.settings.sendAs.list method to retrieve the sendAs aliases.

@bosiraphael bosiraphael added the type: bug Something isn't working label Jun 5, 2024
@bosiraphael bosiraphael changed the title Emails sent and received by an email aliases are not associated with the workspaceMember Emails sent and received by email aliases are not associated with the workspaceMember Jun 5, 2024
Copy link

greptile-apps bot commented Jun 5, 2024

Disclaimer: This comment was automatically generated with AI. It can give some useful hints as to where to look for, but sometimes it can also give very inaccurate answers so takes this with a pinch of salt :).

To resolve the issue, follow these steps:

  1. Retrieve Email Aliases: Modify the EmailService to include a method that uses users.settings.sendAs.list to retrieve email aliases.
async function getEmailAliases(userId) {
  const res = await gmail.users.settings.sendAs.list({ userId });
  return res.data.sendAs.map(alias => alias.sendAsEmail);
}
  1. Associate Messages with WorkspaceMember: Update the message processing logic to check if the sender or recipient email matches any of the retrieved aliases and associate the message with the corresponding workspaceMember.
async function processMessage(message) {
  const aliases = await getEmailAliases(message.userId);
  const isAlias = email => aliases.includes(email);

  if (isAlias(message.sender) || message.recipients.some(isAlias)) {
    // Associate with workspaceMember
    associateWithWorkspaceMember(message);
  }
}
  1. Create Contacts: Ensure that contacts are created for emails sent or received by these aliases within the ContactService.
function createContactIfNotExists(email) {
  if (!contactExists(email)) {
    createContact(email);
  }
}

function processMessage(message) {
  const aliases = await getEmailAliases(message.userId);
  const isAlias = email => aliases.includes(email);

  if (isAlias(message.sender) || message.recipients.some(isAlias)) {
    // Associate with workspaceMember
    associateWithWorkspaceMember(message);
    // Create contacts
    message.recipients.forEach(createContactIfNotExists);
  }
}

Update the relevant files in the services directory to include these changes.

References

@FelixMalfait
Copy link
Member

We should store all aliases within our DB. If we try to hack this we will probably have more issues down the line

Not sure how we will keep this data fresh, is there a webhook update for alias creation/deletion?

@charlesBochet
Copy link
Member

@FelixMalfait We can try to implement alias webhook update once we have implemented it for messaging.

In the meantime, we could just fetch user aliases before at the start of the message import job (doing it at the same time as we refresh connectedAccount access token for example).

I would create an handleAliases ARRAY field to the messageChannel

@FelixMalfait
Copy link
Member

@charlesBochet Great! As long as we store all alias and not just the first one perfect

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type: bug Something isn't working
Projects
Status: 🆕 New
Development

Successfully merging a pull request may close this issue.

3 participants