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

Account Sync Engine #2602

Closed
11 tasks done
FelixMalfait opened this issue Nov 20, 2023 · 0 comments
Closed
11 tasks done

Account Sync Engine #2602

FelixMalfait opened this issue Nov 20, 2023 · 0 comments
Assignees

Comments

@FelixMalfait
Copy link
Member

FelixMalfait commented Nov 20, 2023

[WIP issue / do not pay attention to it]

Need to be able to connect accounts (gmail, outlook, imap, etc.) and sync them with internal APIs (messaging for now but later probably calendar, contacts).
I'm separating the logic to store message threads (in #2210) from the logic to sync accounts here.

Implementation

Allow users to add an e-mail account in settings

  • Add a new tab "accounts" under profile settings
  • Add a button "Add Google account" that redirects to Google with the right scopes
  • Create a page to receive the connection tokens and store them in ExternalApiConnections / MessagingChannel
  • Display the list of connected channels in the accounts tab we created

Note: we already implement a nodejs Passport + GoogleStrategy for login so we should be able to reuse the existing code and pass additional scopes. We don't want to ask for those scopes during login because it would hurt conversion (currently we ask for [profile, email] which is a 1-step process, asking for emails would add one more permission screen)

Scope: Full-stack
Time: 2.5 days

Setup queue and background job system

By the time we start working on this, this sub-task might have been completed already.
(Look for "pg-boss" or "bullmq")

Scope: backend
Time: 2 days

Upon connecting the account, dispatch a job to fetch emails

  • Create a job ImportEmails(MessagingChannelId)
  • Implement "googleapis" node package and authenticate user with stored token
  • Call the api to retrieve all threads
  • Iterate over all pages, iterate over every thread, iterate over every message, iterate over every recipient, save to db

Note: we will also import emails through webhook, so make sure we split the mass-import/pagination logic from the logic to import an email and map it into db which will be re-used.
Note2: use batch-requests to fetch the threads to avoid hitting api rate limits -> https://developers.google.com/gmail/api/reference/quota ; maybe need to add a slight delay too (it says "allow short bursts" but not sure how long is the moving average computation window)

Scope: backend
Time: 3 days

Polling sync

Take most recent historyId and fetch events that happened since then https://developers.google.com/gmail/api/reference/rest/v1/users.history/list

Create person and a company from email

When we create a MessageRecipient, we should already check if there's a corresponding person in the people table.
Now, if that person doesn't exist, we want to create it manually

Scope: backend
Time: 1 day

Discussion

Data model

ConnectedAccount

  • id, createdAt, updatedAt
  • ownerId - fk to users
  • type - string enum: google, outlook, smtp, intercom, twilio
  • accessToken - string
  • refreshToken - string
  • externalScopes - array
  • hasEmailScope - boolean

Contact creation

Should we create a contact for every email recipient?
How do we differentiate newsletter, internal emails and spam from real interactions?
Sent mailbox only as v1?

Tasks

Preview Give feedback
  1. type: feature
    bosiraphael
  2. type: feature
    bosiraphael
  3. scope: backend type: feature
    bosiraphael
  4. 4 of 4
    scope: front type: feature
    thaisguigon
  5. 4 of 4
    scope: front type: feature
    thaisguigon
  6. 2 of 2
    scope: front type: feature
    thaisguigon
  7. 4 of 4
    type: chore
    bosiraphael
  8. 4 of 4
    scope: front type: feature
    thaisguigon
  9. 7 of 7
    scope: front type: feature
    thaisguigon
  10. 6 of 6
    scope: front type: feature
    CoreTeamTwenty
  11. 7 of 7
    scope: front type: feature
    CoreTeamTwenty
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Archived in project
Development

No branches or pull requests

2 participants