diff --git a/connectors/src/api_server.ts b/connectors/src/api_server.ts index 59202b51fd4c..565ad5f100bd 100644 --- a/connectors/src/api_server.ts +++ b/connectors/src/api_server.ts @@ -93,7 +93,7 @@ export function startServer(port: number) { app.post("/webhooks/:webhook_secret/slack", webhookSlackAPIHandler); app.post( - "/webhooks/:webhook_secret/google_drive", + "/webhooks/:webhook_secret/google_drive/:connector_id?", webhookGoogleDriveAPIHandler ); app.post( diff --git a/connectors/src/connectors/google_drive/index.ts b/connectors/src/connectors/google_drive/index.ts index aee0404aff48..a6f5b361d303 100644 --- a/connectors/src/connectors/google_drive/index.ts +++ b/connectors/src/connectors/google_drive/index.ts @@ -79,7 +79,7 @@ export async function createGoogleDriveConnector( { transaction: t } ); - const webhookInfo = await registerWebhook(connector.connectionId); + const webhookInfo = await registerWebhook(connector); if (webhookInfo.isErr()) { throw webhookInfo.error; } else { diff --git a/connectors/src/connectors/google_drive/lib.ts b/connectors/src/connectors/google_drive/lib.ts index fa7be5c406cb..40c927ab1566 100644 --- a/connectors/src/connectors/google_drive/lib.ts +++ b/connectors/src/connectors/google_drive/lib.ts @@ -2,14 +2,14 @@ import memoize from "lodash.memoize"; import { v4 as uuidv4 } from "uuid"; import { HTTPError } from "@connectors/lib/error"; -import { GoogleDriveFiles, ModelId } from "@connectors/lib/models"; +import { Connector, GoogleDriveFiles, ModelId } from "@connectors/lib/models"; import { Err, Ok, type Result } from "@connectors/lib/result.js"; import { getAuthObject } from "./temporal/activities"; const { CONNECTORS_PUBLIC_URL, DUST_CONNECTORS_WEBHOOKS_SECRET } = process.env; export async function registerWebhook( - nangoConnectionId: string + connector: Connector ): Promise< Result<{ id: string; expirationTsMs: number; url: string }, HTTPError | Error> > { @@ -19,11 +19,11 @@ export async function registerWebhook( if (!CONNECTORS_PUBLIC_URL) { return new Err(new Error("CONNECTORS_PUBLIC_URL is not defined")); } - const auth = await getAuthObject(nangoConnectionId); + const auth = await getAuthObject(connector.connectionId); const uuid = uuidv4().toString(); const accessToken = (await auth.getAccessToken()).token; - const webhookURL = `${CONNECTORS_PUBLIC_URL}/webhooks/${DUST_CONNECTORS_WEBHOOKS_SECRET}/google_drive`; + const webhookURL = `${CONNECTORS_PUBLIC_URL}/webhooks/${DUST_CONNECTORS_WEBHOOKS_SECRET}/google_drive/${connector.id}`; const res = await fetch( "https://www.googleapis.com/drive/v3/changes/watch?pageToken=&includeItemsFromAllDrives=true", { diff --git a/connectors/src/connectors/google_drive/temporal/activities.ts b/connectors/src/connectors/google_drive/temporal/activities.ts index 5df628255512..7b4a6d22df47 100644 --- a/connectors/src/connectors/google_drive/temporal/activities.ts +++ b/connectors/src/connectors/google_drive/temporal/activities.ts @@ -896,7 +896,7 @@ export async function renewOneWebhook(webhookId: ModelId) { if (connector) { try { - const webhookInfo = await registerWebhook(connector.connectionId); + const webhookInfo = await registerWebhook(connector); if (webhookInfo.isErr()) { throw webhookInfo.error; } else {