From 837a900723cc2cd0eba5fe962601867cb23277c3 Mon Sep 17 00:00:00 2001 From: Dom Webber Date: Thu, 5 Dec 2024 13:03:39 +0000 Subject: [PATCH 1/2] Add linking to https://developers.facebook.com/docs/messenger-platform/webhooks#validate-payloads --- src/Webhook/index.ts | 1 + 1 file changed, 1 insertion(+) diff --git a/src/Webhook/index.ts b/src/Webhook/index.ts index 313509d..0e27bc3 100644 --- a/src/Webhook/index.ts +++ b/src/Webhook/index.ts @@ -204,6 +204,7 @@ export default class Webhook { ) as WebhookEventNotification; // See: https://github.com/WhatsApp/WhatsApp-Nodejs-SDK/blob/58ca3d5fceea604e18393734578d9a7944a37b15/src/utils.ts#L77-L82 + // See: https://developers.facebook.com/docs/messenger-platform/webhooks#validate-payloads const getCalculatedSignature = (alg: string) => (appSecret: string) => createHmac(alg, appSecret) .update(bodyString, "utf-8") From da9832ffef1d58dff2e4d2305f966fb64b2a168a Mon Sep 17 00:00:00 2001 From: Dom Webber Date: Thu, 5 Dec 2024 13:22:50 +0000 Subject: [PATCH 2/2] Updated fastify event notification JSDoc example --- .changeset/rich-planes-do.md | 5 +++++ src/Webhook/index.ts | 10 +++++++++- 2 files changed, 14 insertions(+), 1 deletion(-) create mode 100644 .changeset/rich-planes-do.md diff --git a/.changeset/rich-planes-do.md b/.changeset/rich-planes-do.md new file mode 100644 index 0000000..8d08893 --- /dev/null +++ b/.changeset/rich-planes-do.md @@ -0,0 +1,5 @@ +--- +"@great-detail/whatsapp": patch +--- + +Update Documentation for Fastify Raw Body Parsing diff --git a/src/Webhook/index.ts b/src/Webhook/index.ts index 0e27bc3..ce42278 100644 --- a/src/Webhook/index.ts +++ b/src/Webhook/index.ts @@ -64,14 +64,22 @@ export default class Webhook { * **Fastify**: * * ```ts + * // See: https://github.com/fastify/fastify/issues/707#issuecomment-817224931 + * fastify.addContentTypeParser("application/json", { parseAs: "buffer" }, (_req, body, done) => { + * done(null, body); + * }); + * * fastify.route({ * method: "GET", * url: "/path/to/webhook", * handler: (request, reply) => { + * assert(Buffer.isBuffer(request.body) || typeof request.body === "string"); + * const body = request.body.toString(); + * * const reg = await sdk.webhook.register({ * method: request.method, * query: request.query, - * body: JSON.stringify(request.body), + * body, * headers: request.headers, * }); * // DIY: Check the reg.verifyToken value