2022-11-25 20:57:07 +01:00
|
|
|
import fetch from "node-fetch"
|
|
|
|
import { getFetchResponse } from "./utils"
|
|
|
|
import {
|
|
|
|
AutomationActionStepId,
|
2022-11-26 16:10:41 +01:00
|
|
|
AutomationStepSchema,
|
2023-04-06 19:11:44 +02:00
|
|
|
AutomationStepType,
|
|
|
|
AutomationIOType,
|
2023-05-22 16:46:42 +02:00
|
|
|
AutomationFeature,
|
2024-07-31 23:18:00 +02:00
|
|
|
ExternalAppStepOutputs,
|
|
|
|
MakeIntegrationInputs,
|
2022-11-25 20:57:07 +01:00
|
|
|
} from "@budibase/types"
|
2021-09-03 18:36:00 +02:00
|
|
|
|
2022-11-26 16:10:41 +01:00
|
|
|
export const definition: AutomationStepSchema = {
|
2023-05-05 13:41:24 +02:00
|
|
|
name: "Make Integration",
|
|
|
|
stepTitle: "Make",
|
|
|
|
tagline: "Trigger a Make scenario",
|
2021-09-03 18:36:00 +02:00
|
|
|
description:
|
2023-05-05 13:41:24 +02:00
|
|
|
"Performs a webhook call to Make and gets the response (if configured)",
|
2021-09-03 18:36:00 +02:00
|
|
|
icon: "ri-shut-down-line",
|
2022-11-25 20:57:07 +01:00
|
|
|
stepId: AutomationActionStepId.integromat,
|
2023-04-06 19:11:44 +02:00
|
|
|
type: AutomationStepType.ACTION,
|
2021-09-14 13:40:19 +02:00
|
|
|
internal: false,
|
2023-05-26 12:02:47 +02:00
|
|
|
features: {
|
|
|
|
[AutomationFeature.LOOPING]: true,
|
|
|
|
},
|
2021-09-03 18:36:00 +02:00
|
|
|
inputs: {},
|
|
|
|
schema: {
|
|
|
|
inputs: {
|
|
|
|
properties: {
|
|
|
|
url: {
|
2023-04-06 19:11:44 +02:00
|
|
|
type: AutomationIOType.STRING,
|
2021-09-03 18:36:00 +02:00
|
|
|
title: "Webhook URL",
|
|
|
|
},
|
2023-05-11 18:49:33 +02:00
|
|
|
body: {
|
|
|
|
type: AutomationIOType.JSON,
|
|
|
|
title: "Payload",
|
|
|
|
},
|
2021-09-03 18:36:00 +02:00
|
|
|
},
|
2024-02-15 14:05:03 +01:00
|
|
|
required: ["url", "body"],
|
2021-09-03 18:36:00 +02:00
|
|
|
},
|
|
|
|
outputs: {
|
|
|
|
properties: {
|
|
|
|
success: {
|
2023-04-06 19:11:44 +02:00
|
|
|
type: AutomationIOType.BOOLEAN,
|
2021-09-03 18:36:00 +02:00
|
|
|
description: "Whether call was successful",
|
|
|
|
},
|
2021-09-07 18:31:54 +02:00
|
|
|
httpStatus: {
|
2023-04-06 19:11:44 +02:00
|
|
|
type: AutomationIOType.NUMBER,
|
2021-09-07 18:31:54 +02:00
|
|
|
description: "The HTTP status code returned",
|
|
|
|
},
|
2021-09-03 18:36:00 +02:00
|
|
|
response: {
|
2023-04-06 19:11:44 +02:00
|
|
|
type: AutomationIOType.OBJECT,
|
2021-09-03 18:36:00 +02:00
|
|
|
description: "The webhook response - this can have properties",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
required: ["success", "response"],
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
2024-07-31 23:18:00 +02:00
|
|
|
export async function run({
|
|
|
|
inputs,
|
|
|
|
}: {
|
|
|
|
inputs: MakeIntegrationInputs
|
|
|
|
}): Promise<ExternalAppStepOutputs> {
|
2023-09-29 11:15:36 +02:00
|
|
|
const { url, body } = inputs
|
2023-05-11 18:49:33 +02:00
|
|
|
|
|
|
|
let payload = {}
|
|
|
|
try {
|
|
|
|
payload = body?.value ? JSON.parse(body?.value) : {}
|
|
|
|
} catch (err) {
|
|
|
|
return {
|
|
|
|
httpStatus: 400,
|
|
|
|
response: "Invalid payload JSON",
|
|
|
|
success: false,
|
|
|
|
}
|
|
|
|
}
|
2021-09-03 18:36:00 +02:00
|
|
|
|
2023-02-16 17:23:44 +01:00
|
|
|
if (!url?.trim()?.length) {
|
|
|
|
return {
|
|
|
|
httpStatus: 400,
|
|
|
|
response: "Missing Webhook URL",
|
|
|
|
success: false,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
let response
|
|
|
|
try {
|
|
|
|
response = await fetch(url, {
|
|
|
|
method: "post",
|
|
|
|
body: JSON.stringify({
|
2023-05-11 18:49:33 +02:00
|
|
|
...payload,
|
2023-02-16 17:23:44 +01:00
|
|
|
}),
|
|
|
|
headers: {
|
|
|
|
"Content-Type": "application/json",
|
|
|
|
},
|
|
|
|
})
|
|
|
|
} catch (err: any) {
|
|
|
|
return {
|
|
|
|
httpStatus: 400,
|
|
|
|
response: err.message,
|
|
|
|
success: false,
|
|
|
|
}
|
|
|
|
}
|
2021-09-03 18:36:00 +02:00
|
|
|
|
2021-09-07 18:31:54 +02:00
|
|
|
const { status, message } = await getFetchResponse(response)
|
2021-09-03 18:36:00 +02:00
|
|
|
return {
|
2021-09-07 18:31:54 +02:00
|
|
|
httpStatus: status,
|
|
|
|
success: status === 200,
|
|
|
|
response: message,
|
2021-09-03 18:36:00 +02:00
|
|
|
}
|
|
|
|
}
|