70 lines
1.5 KiB
TypeScript
70 lines
1.5 KiB
TypeScript
import fetch from "node-fetch"
|
|
import { getFetchResponse } from "./utils"
|
|
import {
|
|
AutomationActionStepId,
|
|
AutomationStep,
|
|
AutomationStepInput,
|
|
} from "@budibase/types"
|
|
|
|
export const definition: AutomationStep = {
|
|
name: "Slack Message",
|
|
tagline: "Send a message to Slack",
|
|
description: "Send a message to Slack",
|
|
icon: "ri-slack-line",
|
|
stepId: AutomationActionStepId.slack,
|
|
type: "ACTION",
|
|
internal: false,
|
|
inputs: {},
|
|
schema: {
|
|
inputs: {
|
|
properties: {
|
|
url: {
|
|
type: "string",
|
|
title: "Incoming Webhook URL",
|
|
},
|
|
text: {
|
|
type: "string",
|
|
title: "Message",
|
|
},
|
|
},
|
|
required: ["url", "text"],
|
|
},
|
|
outputs: {
|
|
properties: {
|
|
httpStatus: {
|
|
type: "number",
|
|
description: "The HTTP status code of the request",
|
|
},
|
|
success: {
|
|
type: "boolean",
|
|
description: "Whether the message sent successfully",
|
|
},
|
|
response: {
|
|
type: "string",
|
|
description: "The response from the Slack Webhook",
|
|
},
|
|
},
|
|
},
|
|
},
|
|
}
|
|
|
|
export async function run({ inputs }: AutomationStepInput) {
|
|
let { url, text } = inputs
|
|
const response = await fetch(url, {
|
|
method: "post",
|
|
body: JSON.stringify({
|
|
text,
|
|
}),
|
|
headers: {
|
|
"Content-Type": "application/json",
|
|
},
|
|
})
|
|
|
|
const { status, message } = await getFetchResponse(response)
|
|
return {
|
|
httpStatus: status,
|
|
response: message,
|
|
success: status === 200,
|
|
}
|
|
}
|