From 49676f2cae769098e83976c0e047a5118ca7e8b9 Mon Sep 17 00:00:00 2001 From: Peter Clement Date: Sat, 30 Dec 2023 18:51:08 +0000 Subject: [PATCH] recomitting trigger another automation work --- .../FlowChart/ActionModal.svelte | 1 - packages/server/src/automations/actions.ts | 4 + .../server/src/automations/steps/trigger.ts | 75 +++++++++++++++++++ .../types/src/documents/app/automation.ts | 1 + 4 files changed, 80 insertions(+), 1 deletion(-) create mode 100644 packages/server/src/automations/steps/trigger.ts diff --git a/packages/builder/src/components/automation/AutomationBuilder/FlowChart/ActionModal.svelte b/packages/builder/src/components/automation/AutomationBuilder/FlowChart/ActionModal.svelte index 15dd864168..a0da8e455a 100644 --- a/packages/builder/src/components/automation/AutomationBuilder/FlowChart/ActionModal.svelte +++ b/packages/builder/src/components/automation/AutomationBuilder/FlowChart/ActionModal.svelte @@ -23,7 +23,6 @@ let selectedAction let actionVal let actions = Object.entries($automationStore.blockDefinitions.ACTION) - $: collectBlockExists = checkForCollectStep($selectedAutomation) const disabled = () => { diff --git a/packages/server/src/automations/actions.ts b/packages/server/src/automations/actions.ts index 81cf4d8176..7025a2f64c 100644 --- a/packages/server/src/automations/actions.ts +++ b/packages/server/src/automations/actions.ts @@ -15,6 +15,7 @@ import * as delay from "./steps/delay" import * as queryRow from "./steps/queryRows" import * as loop from "./steps/loop" import * as collect from "./steps/collect" +import * as trigger from "./steps/trigger" import env from "../environment" import { AutomationStepSchema, @@ -41,6 +42,7 @@ const ACTION_IMPLS: Record< FILTER: filter.run, QUERY_ROWS: queryRow.run, COLLECT: collect.run, + TRIGGER_AUTOMATION: trigger.run, // these used to be lowercase step IDs, maintain for backwards compat discord: discord.run, slack: slack.run, @@ -62,6 +64,7 @@ export const BUILTIN_ACTION_DEFINITIONS: Record = QUERY_ROWS: queryRow.definition, LOOP: loop.definition, COLLECT: collect.definition, + TRIGGER: trigger.definition, // these used to be lowercase step IDs, maintain for backwards compat discord: discord.definition, slack: slack.definition, @@ -102,6 +105,7 @@ export async function getActionDefinitions() { /* istanbul ignore next */ export async function getAction(stepId: string) { + console.log(stepId) if (ACTION_IMPLS[stepId] != null) { return ACTION_IMPLS[stepId] } diff --git a/packages/server/src/automations/steps/trigger.ts b/packages/server/src/automations/steps/trigger.ts new file mode 100644 index 0000000000..7624bef817 --- /dev/null +++ b/packages/server/src/automations/steps/trigger.ts @@ -0,0 +1,75 @@ +import { + AutomationActionStepId, + AutomationStepSchema, + AutomationStepInput, + AutomationStepType, + AutomationIOType, + AutomationFeature, + AutomationResults, + Automation, +} from "@budibase/types" +import * as triggers from "../triggers" +import { db as dbCore, context } from "@budibase/backend-core" + +export const definition: AutomationStepSchema = { + name: "Trigger Automation", + tagline: "Triggers an automation synchronously", + icon: "Sync", + description: "Triggers an automation synchronously", + type: AutomationStepType.ACTION, + internal: true, + features: {}, + stepId: AutomationActionStepId.TRIGGER, + inputs: {}, + schema: { + inputs: { + properties: { + automationId: { + type: AutomationIOType.STRING, + title: "Automation ID to trigger", + }, + }, + required: ["automationId"], + }, + outputs: { + properties: { + success: { + type: AutomationIOType.BOOLEAN, + description: "Whether the automation was successful", + }, + value: { + type: AutomationIOType.OBJECT, + description: "Automation Result", + }, + }, + required: ["success", "value"], + }, + }, +} + +export async function run({ inputs }: AutomationStepInput) { + console.log("??: " + inputs.automationId) + console.log("???DSAASDFAFSDFDSFDS") + if (!inputs.automationId) { + return { + success: false, + } + } else { + const db = context.getAppDB() + let automation = await db.get(inputs.automationId) + + const response: AutomationResults = await triggers.externalTrigger( + automation, + { + fields: {}, + timeout: 120000, + }, + { getResponses: true } + ) + + return { + success: true, + value: response, + } + } +} diff --git a/packages/types/src/documents/app/automation.ts b/packages/types/src/documents/app/automation.ts index 88ce5e9b9a..bbaa74bb14 100644 --- a/packages/types/src/documents/app/automation.ts +++ b/packages/types/src/documents/app/automation.ts @@ -61,6 +61,7 @@ export enum AutomationActionStepId { LOOP = "LOOP", COLLECT = "COLLECT", OPENAI = "OPENAI", + TRIGGER = "TRIGGER", // these used to be lowercase step IDs, maintain for backwards compat discord = "discord", slack = "slack",