From 54d38434480aa12682b1699ef2e33ba860c8ed74 Mon Sep 17 00:00:00 2001 From: Matt Aitken Date: Mon, 23 Oct 2023 12:17:18 +0100 Subject: [PATCH] =?UTF-8?q?HttpEndpoin=20that=20isn=E2=80=99t=20a=20trigge?= =?UTF-8?q?r?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- references/job-catalog/src/httpTrigger.ts | 13 ++----------- 1 file changed, 2 insertions(+), 11 deletions(-) diff --git a/references/job-catalog/src/httpTrigger.ts b/references/job-catalog/src/httpTrigger.ts index c74cdc141..4bfec8d57 100644 --- a/references/job-catalog/src/httpTrigger.ts +++ b/references/job-catalog/src/httpTrigger.ts @@ -10,7 +10,7 @@ export const client = new TriggerClient({ ioLogLocalEnabled: true, }); -const whatsApp = client.defineHttpTrigger({ +const whatsApp = client.defineHttpEndpoint({ id: "whatsapp", hostname: "whatsapp.com", //only needed for strange APIs like WhatsApp which don't setup the webhook until you pass the test @@ -34,26 +34,17 @@ const whatsApp = client.defineHttpTrigger({ headerName: "X-Signature-SHA256", }); }, - transform: async (request, context) => { - const payload = await request.json(); - - return { - payload, - }; - }, - //todo would it be better to just have a "preprocess" function that returns the event? }); //todo it would be nice if a filter could be added to an HttpTrigger //then a webhook that subscribes to many events could be created and reused -const whatsappMessage = whatsApp.filtered({}); client.defineJob({ id: "event-example-1", name: "Event Example 1", version: "1.0.0", enabled: true, - trigger: whatsApp.onRequest({ filter: { method: ["POST"] } }), + trigger: whatsApp.onRequest({ filter: { body: { event: ["message"] } } }), run: async (payload, io, ctx) => { const { message } = payload.body; await io.logger.info(`Received message from ${message.from}`);