feat: add zapier support

This commit is contained in:
Catalin Pit
2024-02-24 11:18:58 +02:00
parent c6dbaaea21
commit fab4992e13
18 changed files with 258 additions and 13 deletions

View File

@@ -9,9 +9,11 @@ import { DOCUMENT_AUDIT_LOG_TYPE } from '@documenso/lib/types/document-audit-log
import { createDocumentAuditLogData } from '@documenso/lib/utils/document-audit-logs';
import { prisma } from '@documenso/prisma';
import { DocumentStatus, RecipientRole, SigningStatus } from '@documenso/prisma/client';
import { WebhookTriggerEvents } from '@documenso/prisma/client';
import { signPdf } from '@documenso/signing';
import type { RequestMetadata } from '../../universal/extract-request-metadata';
import { triggerWebhook } from '../../universal/trigger-webhook';
import { getFile } from '../../universal/upload/get-file';
import { putFile } from '../../universal/upload/put-file';
import { insertFieldInPDF } from '../pdf/insert-field-in-pdf';
@@ -134,4 +136,9 @@ export const sealDocument = async ({
if (sendEmail) {
await sendCompletedEmail({ documentId, requestMetadata });
}
await triggerWebhook({
eventTrigger: WebhookTriggerEvents.DOCUMENT_COMPLETED,
documentData: document,
});
};

View File

@@ -10,12 +10,14 @@ import { createDocumentAuditLogData } from '@documenso/lib/utils/document-audit-
import { renderCustomEmailTemplate } from '@documenso/lib/utils/render-custom-email-template';
import { prisma } from '@documenso/prisma';
import { DocumentStatus, RecipientRole, SendStatus } from '@documenso/prisma/client';
import { WebhookTriggerEvents } from '@documenso/prisma/client';
import { NEXT_PUBLIC_WEBAPP_URL } from '../../constants/app';
import {
RECIPIENT_ROLES_DESCRIPTION,
RECIPIENT_ROLE_TO_EMAIL_TYPE,
} from '../../constants/recipient-roles';
import { triggerWebhook } from '../../universal/trigger-webhook';
export type SendDocumentOptions = {
documentId: number;
@@ -163,5 +165,10 @@ export const sendDocument = async ({
},
});
await triggerWebhook({
eventTrigger: WebhookTriggerEvents.DOCUMENT_SENT,
documentData: updatedDocument,
});
return updatedDocument;
};

View File

@@ -3,6 +3,10 @@ import type { RequestMetadata } from '@documenso/lib/universal/extract-request-m
import { createDocumentAuditLogData } from '@documenso/lib/utils/document-audit-logs';
import { prisma } from '@documenso/prisma';
import { ReadStatus } from '@documenso/prisma/client';
import { WebhookTriggerEvents } from '@documenso/prisma/client';
import { triggerWebhook } from '../../universal/trigger-webhook';
import { getDocumentAndSenderByToken } from './get-document-by-token';
export type ViewedDocumentOptions = {
token: string;
@@ -51,4 +55,22 @@ export const viewedDocument = async ({ token, requestMetadata }: ViewedDocumentO
}),
});
});
const document = await getDocumentAndSenderByToken({ token });
await triggerWebhook({
eventTrigger: WebhookTriggerEvents.DOCUMENT_OPENED,
documentData: {
id: document.id,
userId: document.userId,
title: document.title,
status: document.status,
documentDataId: document.documentDataId,
createdAt: document.createdAt,
updatedAt: document.updatedAt,
completedAt: document.completedAt,
deletedAt: document.deletedAt,
teamId: document.teamId,
},
});
};