Skip to content

Conversation

@leog
Copy link
Contributor

@leog leog commented Aug 11, 2022

What does this PR do?

Introduces the concept of Sync Services, used to sync external tools with key information of Cal.com users when they interact with the app, such as HelpScout, Close.com and SendGrid. See #3633 for more details on what's needed.

Note that the work for this was implemented above #3709, which means it needs to be merged before this PR gets merged.

Implements #3633.

Please be sure to also review closely related PRs in other apps. Once this PR is merged, they also need to be merged.

Type of change

  • Chore

How should this be tested?

  • Create a new web user via website signup and see user being created in Cal.com's Sendgrid, not Close.com
  • Create a new console user via console wizard and see user being created in Cal.com's Sendgrid, not Close.com
  • Have a user create a new booking and see user's information be updated in Cal.com's Sendgrid, not Close.com (Last booking)
  • Have a user update their profile name and/or username and see user's information be updated in Cal.com's Sendgrid and Close.com (Name and Username)
  • Have a user create/update a team, a new lead with team owner as contact will be created in Close.com (contact as Point of Contact)
  • Have a user delete a team, will trigger Close.com lead deletion
  • Have a user accept/leave a team, it will be added/removed into Close.com corresponding lead
  • Have a user update a team name, it will be updated into Close.com corresponding lead
  • Have a user update their plan and see user's information be updated in Cal.com's Sendgrid, not Close.com (Plan)
  • Help Scout dedicated API to access last booking, username and plan for the ticket customer in case they exist in the system

@leog leog marked this pull request as ready for review August 26, 2022 14:17
try {
this.service = new service();
} catch (e) {
this.log.warn("Couldn't instantiate sync service:", (e as Error).message);
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not having the requirements to instance a service part of a sync service will just result in a warning. So for example, if Close.com or Sendgrid API Keys are missing, a warning will come up to the console and no other method will be called resulting in no errors whatsoever

return this.service !== undefined;
}

async getUserLastBooking(user: { email: string }): Promise<{ booking: { createdAt: Date } | null } | null> {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is to provide common logic to all Sync Services. As they all need to get the last booking for a user, this is available from the class they extend from

import SendgridService from "./SendgridService";

const services: ISyncServices[] = [
//CloseComService, This service gets a special treatment after deciding it shouldn't get the same treatment as Sendgrid
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Close.com does not behave the same as Sendgrid, as the definitions changed to only register contacts within teams, so it was excluded from here and implemented specific Close.com functions in SyncServiceManager.

Copy link
Contributor

@zomars zomars left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looking good @leog nice work

Comment on lines 16 to 18
export default async function handler(req: NextApiRequest, res: NextApiResponse) {
if (req.method === "POST") {
if (!req.headers["x-helpscout-signature"]) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry @zomars, couldn't make it a default handler as I couldn't find a way to disable the automatic bodyParser from it.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@leog the defaultHandler doesn't add bodyParser at all. You can still configure it at config level

Copy link
Contributor

@zomars zomars left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Computer Reaction GIF by GitHub

@zomars zomars merged commit 1d927a8 into main Aug 26, 2022
@zomars zomars deleted the chore/sync-services branch August 26, 2022 21:10
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

No open projects
Status: Done

Development

Successfully merging this pull request may close these issues.

sync user data with helpscout, close and sendgrid

4 participants