1
0
Fork 0
mirror of synced 2024-09-21 03:43:21 +12:00
budibase/packages/server/src/automations/steps/zapier.ts
melohagan b4e0d98973 Add bindings support to meeting start / end dates (#11759)
* Deprecate zapier+make values1..5

* Allow dates in meeting invite to be bindable

* Add DrawerBindableSlot component

* Show calendar icon

* refactor

* Use cancel icon

* Disable cancel for JS bindings

* WIP

* WIP

* WIP

* Fix linkedIds svelte binding

* Label and icon update

* Handle arrays

* Support text area

* Add reactivity to text area icon

* Support boolean

* JSON support

* Remove rowControl

* Allow boolean field to have three states

* lint

* Refactor

---------

Co-authored-by: Michael Drury <me@michaeldrury.co.uk>
2023-09-29 09:15:36 +00:00

123 lines
2.7 KiB
TypeScript

import fetch from "node-fetch"
import { getFetchResponse } from "./utils"
import {
AutomationActionStepId,
AutomationStepSchema,
AutomationStepInput,
AutomationStepType,
AutomationIOType,
AutomationFeature,
} from "@budibase/types"
export const definition: AutomationStepSchema = {
name: "Zapier Webhook",
stepId: AutomationActionStepId.zapier,
type: AutomationStepType.ACTION,
internal: false,
features: {
[AutomationFeature.LOOPING]: true,
},
description: "Trigger a Zapier Zap via webhooks",
tagline: "Trigger a Zapier Zap",
icon: "ri-flashlight-line",
inputs: {},
schema: {
inputs: {
properties: {
url: {
type: AutomationIOType.STRING,
title: "Webhook URL",
},
body: {
type: AutomationIOType.JSON,
title: "Payload",
},
value1: {
type: AutomationIOType.STRING,
title: "Payload Value 1",
},
value2: {
type: AutomationIOType.STRING,
title: "Payload Value 2",
},
value3: {
type: AutomationIOType.STRING,
title: "Payload Value 3",
},
value4: {
type: AutomationIOType.STRING,
title: "Payload Value 4",
},
value5: {
type: AutomationIOType.STRING,
title: "Payload Value 5",
},
},
required: ["url"],
},
outputs: {
properties: {
httpStatus: {
type: AutomationIOType.NUMBER,
description: "The HTTP status code of the request",
},
response: {
type: AutomationIOType.STRING,
description: "The response from Zapier",
},
},
},
},
}
export async function run({ inputs }: AutomationStepInput) {
const { url, body } = inputs
let payload = {}
try {
payload = body?.value ? JSON.parse(body?.value) : {}
} catch (err) {
return {
httpStatus: 400,
response: "Invalid payload JSON",
success: false,
}
}
if (!url?.trim()?.length) {
return {
httpStatus: 400,
response: "Missing Webhook URL",
success: false,
}
}
// send the platform to make sure zaps always work, even
// if no values supplied
let response
try {
response = await fetch(url, {
method: "post",
body: JSON.stringify({
platform: "budibase",
...payload,
}),
headers: {
"Content-Type": "application/json",
},
})
} catch (err: any) {
return {
httpStatus: 400,
response: err.message,
success: false,
}
}
const { status, message } = await getFetchResponse(response)
return {
success: status === 200,
httpStatus: status,
response: message,
}
}