From c66541ad99f24035f380c4075ea8ce42a6330fea Mon Sep 17 00:00:00 2001 From: mike12345567 Date: Mon, 26 Oct 2020 16:04:02 +0000 Subject: [PATCH] Joe-ifying some of the work on webhooks to make it a bit easier to understand and finished up some testing around it. --- .../BlockList/AutomationBlock.svelte | 2 +- .../SetupPanel/AutomationBlockSetup.svelte | 9 +++- .../automation/SetupPanel/SetupPanel.svelte | 9 +++- .../CreateWebhookModal.svelte | 50 +++++++++---------- .../WebhookDisplay.svelte | 14 ++++-- .../server/src/api/controllers/webhook.js | 8 ++- packages/server/src/automations/triggers.js | 9 +++- 7 files changed, 63 insertions(+), 38 deletions(-) rename packages/builder/src/components/automation/{AutomationPanel/BlockList => Shared}/CreateWebhookModal.svelte (67%) rename packages/builder/src/components/automation/{AutomationPanel/BlockList => Shared}/WebhookDisplay.svelte (87%) diff --git a/packages/builder/src/components/automation/AutomationPanel/BlockList/AutomationBlock.svelte b/packages/builder/src/components/automation/AutomationPanel/BlockList/AutomationBlock.svelte index f2a52088ad..54e6b2dbbf 100644 --- a/packages/builder/src/components/automation/AutomationPanel/BlockList/AutomationBlock.svelte +++ b/packages/builder/src/components/automation/AutomationPanel/BlockList/AutomationBlock.svelte @@ -1,6 +1,6 @@ -
+
- copyToClipboard()}> + copyToClipboard()}>
diff --git a/packages/server/src/api/controllers/webhook.js b/packages/server/src/api/controllers/webhook.js index a593133a47..c759105fed 100644 --- a/packages/server/src/api/controllers/webhook.js +++ b/packages/server/src/api/controllers/webhook.js @@ -87,7 +87,13 @@ exports.trigger = async ctx => { validate(ctx.request.body, webhook.bodySchema) const target = await db.get(webhook.action.target) if (webhook.action.type === exports.WebhookType.AUTOMATION) { - await triggers.externalTrigger(target, ctx.request.body) + // trigger with both the pure request and then expand it + // incase the user has produced a schema to bind to + await triggers.externalTrigger(target, { + body: ctx.request.body, + ...ctx.request.body, + instanceId: ctx.params.instance, + }) } ctx.status = 200 ctx.body = "Webhook trigger fired successfully" diff --git a/packages/server/src/automations/triggers.js b/packages/server/src/automations/triggers.js index 4870cfd051..6dd163ea8e 100644 --- a/packages/server/src/automations/triggers.js +++ b/packages/server/src/automations/triggers.js @@ -108,8 +108,13 @@ const BUILTIN_DEFINITIONS = { required: ["schemaUrl", "triggerUrl"], }, outputs: { - properties: {}, - required: [], + properties: { + body: { + type: "object", + description: "Body of the request which hit the webhook", + }, + }, + required: ["body"], }, }, type: "TRIGGER",