HttpEndpoin that isn’t a trigger
This commit is contained in:
@@ -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}`);
|
||||
|
||||
Reference in New Issue
Block a user