1
0
Fork 0
mirror of synced 2024-06-28 02:50:50 +12:00
budibase/packages/server/src/automations/steps/integromat.js
2021-09-14 12:40:19 +01:00

88 lines
2 KiB
JavaScript

const fetch = require("node-fetch")
const { getFetchResponse } = require("./utils")
exports.definition = {
name: "Integromat Integration",
tagline: "Trigger an Integromat scenario",
description:
"Performs a webhook call to Integromat and gets the response (if configured)",
icon: "ri-shut-down-line",
stepId: "integromat",
type: "ACTION",
internal: false,
inputs: {},
schema: {
inputs: {
properties: {
url: {
type: "string",
title: "Webhook URL",
},
value1: {
type: "string",
title: "Input Value 1",
},
value2: {
type: "string",
title: "Input Value 2",
},
value3: {
type: "string",
title: "Input Value 3",
},
value4: {
type: "string",
title: "Input Value 4",
},
value5: {
type: "string",
title: "Input Value 5",
},
},
required: ["url", "value1", "value2", "value3", "value4", "value5"],
},
outputs: {
properties: {
success: {
type: "boolean",
description: "Whether call was successful",
},
httpStatus: {
type: "number",
description: "The HTTP status code returned",
},
response: {
type: "object",
description: "The webhook response - this can have properties",
},
},
required: ["success", "response"],
},
},
}
exports.run = async function ({ inputs }) {
const { url, value1, value2, value3, value4, value5 } = inputs
const response = await fetch(url, {
method: "post",
body: JSON.stringify({
value1,
value2,
value3,
value4,
value5,
}),
headers: {
"Content-Type": "application/json",
},
})
const { status, message } = await getFetchResponse(response)
return {
httpStatus: status,
success: status === 200,
response: message,
}
}