Adding slack integration.
This commit is contained in:
parent
879f1a2368
commit
d05c60d470
|
@ -35,10 +35,6 @@ exports.APP_PREFIX = DocumentTypes.APP + SEPARATOR
|
||||||
exports.APP_DEV = exports.APP_DEV_PREFIX = DocumentTypes.APP_DEV + SEPARATOR
|
exports.APP_DEV = exports.APP_DEV_PREFIX = DocumentTypes.APP_DEV + SEPARATOR
|
||||||
exports.SEPARATOR = SEPARATOR
|
exports.SEPARATOR = SEPARATOR
|
||||||
|
|
||||||
function isDevApp(app) {
|
|
||||||
return app.appId.startsWith(exports.APP_DEV_PREFIX)
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* If creating DB allDocs/query params with only a single top level ID this can be used, this
|
* If creating DB allDocs/query params with only a single top level ID this can be used, this
|
||||||
* is usually the case as most of our docs are top level e.g. tables, automations, users and so on.
|
* is usually the case as most of our docs are top level e.g. tables, automations, users and so on.
|
||||||
|
@ -62,6 +58,18 @@ function getDocParams(docType, docId = null, otherProps = {}) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
exports.isDevAppID = appId => {
|
||||||
|
return appId.startsWith(exports.APP_DEV_PREFIX)
|
||||||
|
}
|
||||||
|
|
||||||
|
exports.isProdAppID = appId => {
|
||||||
|
return appId.startsWith(exports.APP_PREFIX) && !exports.isDevAppID(appId)
|
||||||
|
}
|
||||||
|
|
||||||
|
function isDevApp(app) {
|
||||||
|
return exports.isDevAppID(app.appId)
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Generates a new workspace ID.
|
* Generates a new workspace ID.
|
||||||
* @returns {string} The new workspace ID which the workspace doc can be stored under.
|
* @returns {string} The new workspace ID which the workspace doc can be stored under.
|
||||||
|
|
|
@ -280,3 +280,5 @@ exports.trigger = async function (ctx) {
|
||||||
automation,
|
automation,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
exports.test = async function (ctx) {}
|
||||||
|
|
|
@ -9,7 +9,7 @@ const executeQuery = require("./steps/executeQuery")
|
||||||
const outgoingWebhook = require("./steps/outgoingWebhook")
|
const outgoingWebhook = require("./steps/outgoingWebhook")
|
||||||
const serverLog = require("./steps/serverLog")
|
const serverLog = require("./steps/serverLog")
|
||||||
const discord = require("./steps/discord")
|
const discord = require("./steps/discord")
|
||||||
// TODO: remove zapier/integromat some time in the future/deprecate them
|
const slack = require("./steps/slack")
|
||||||
const zapier = require("./steps/zapier")
|
const zapier = require("./steps/zapier")
|
||||||
const integromat = require("./steps/integromat")
|
const integromat = require("./steps/integromat")
|
||||||
|
|
||||||
|
@ -26,6 +26,7 @@ const ACTION_IMPLS = {
|
||||||
SERVER_LOG: serverLog.run,
|
SERVER_LOG: serverLog.run,
|
||||||
// these used to be lowercase step IDs, maintain for backwards compat
|
// these used to be lowercase step IDs, maintain for backwards compat
|
||||||
discord: discord.run,
|
discord: discord.run,
|
||||||
|
slack: slack.run,
|
||||||
zapier: zapier.run,
|
zapier: zapier.run,
|
||||||
integromat: integromat.run,
|
integromat: integromat.run,
|
||||||
}
|
}
|
||||||
|
@ -42,6 +43,7 @@ const ACTION_DEFINITIONS = {
|
||||||
SERVER_LOG: serverLog.definition,
|
SERVER_LOG: serverLog.definition,
|
||||||
// these used to be lowercase step IDs, maintain for backwards compat
|
// these used to be lowercase step IDs, maintain for backwards compat
|
||||||
discord: discord.definition,
|
discord: discord.definition,
|
||||||
|
slack: slack.definition,
|
||||||
zapier: zapier.definition,
|
zapier: zapier.definition,
|
||||||
integromat: integromat.definition,
|
integromat: integromat.definition,
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,5 +1,8 @@
|
||||||
const fetch = require("node-fetch")
|
const fetch = require("node-fetch")
|
||||||
|
|
||||||
|
const DEFAULT_USERNAME = "Budibase Automate"
|
||||||
|
const DEFAULT_AVATAR_URL = "https://i.imgur.com/a1cmTKM.png"
|
||||||
|
|
||||||
exports.definition = {
|
exports.definition = {
|
||||||
name: "Discord Message",
|
name: "Discord Message",
|
||||||
tagline: "Send a message to a Discord server",
|
tagline: "Send a message to a Discord server",
|
||||||
|
@ -7,10 +10,7 @@ exports.definition = {
|
||||||
icon: "ri-discord-line",
|
icon: "ri-discord-line",
|
||||||
stepId: "discord",
|
stepId: "discord",
|
||||||
type: "ACTION",
|
type: "ACTION",
|
||||||
inputs: {
|
inputs: {},
|
||||||
username: "Budibase Automate",
|
|
||||||
avatar_url: "https://i.imgur.com/a1cmTKM.png",
|
|
||||||
},
|
|
||||||
schema: {
|
schema: {
|
||||||
inputs: {
|
inputs: {
|
||||||
properties: {
|
properties: {
|
||||||
|
@ -39,14 +39,23 @@ exports.definition = {
|
||||||
type: "number",
|
type: "number",
|
||||||
description: "The HTTP status code of the request",
|
description: "The HTTP status code of the request",
|
||||||
},
|
},
|
||||||
|
success: {
|
||||||
|
type: "boolean",
|
||||||
|
description: "Whether the message sent successfully",
|
||||||
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
exports.run = async function ({ inputs }) {
|
exports.run = async function ({ inputs }) {
|
||||||
const { url, username, avatar_url, content } = inputs
|
let { url, username, avatar_url, content } = inputs
|
||||||
|
if (!username) {
|
||||||
|
username = DEFAULT_USERNAME
|
||||||
|
}
|
||||||
|
if (!avatar_url) {
|
||||||
|
avatar_url = DEFAULT_AVATAR_URL
|
||||||
|
}
|
||||||
const response = await fetch(url, {
|
const response = await fetch(url, {
|
||||||
method: "post",
|
method: "post",
|
||||||
body: JSON.stringify({
|
body: JSON.stringify({
|
||||||
|
@ -61,5 +70,6 @@ exports.run = async function ({ inputs }) {
|
||||||
|
|
||||||
return {
|
return {
|
||||||
httpStatus: response.status,
|
httpStatus: response.status,
|
||||||
|
success: response.status === 200,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -0,0 +1,59 @@
|
||||||
|
const fetch = require("node-fetch")
|
||||||
|
|
||||||
|
const DEFAULT_USERNAME = "Budibase Automate"
|
||||||
|
const DEFAULT_ICON_URL = "https://i.imgur.com/a1cmTKM.png"
|
||||||
|
|
||||||
|
exports.definition = {
|
||||||
|
name: "Slack Message",
|
||||||
|
tagline: "Send a message to Slack",
|
||||||
|
description: "Send a message to Slack",
|
||||||
|
icon: "ri-slack-line",
|
||||||
|
stepId: "slack",
|
||||||
|
type: "ACTION",
|
||||||
|
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",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
exports.run = async function ({ inputs }) {
|
||||||
|
let { url, text } = inputs
|
||||||
|
const response = await fetch(url, {
|
||||||
|
method: "post",
|
||||||
|
body: JSON.stringify({
|
||||||
|
text,
|
||||||
|
}),
|
||||||
|
headers: {
|
||||||
|
"Content-Type": "application/json",
|
||||||
|
},
|
||||||
|
})
|
||||||
|
|
||||||
|
return {
|
||||||
|
httpStatus: response.status,
|
||||||
|
success: response.status === 200,
|
||||||
|
}
|
||||||
|
}
|
|
@ -9,6 +9,7 @@ const { coerce } = require("../utilities/rowProcessor")
|
||||||
const { utils } = require("@budibase/auth/redis")
|
const { utils } = require("@budibase/auth/redis")
|
||||||
const { JobQueues } = require("../constants")
|
const { JobQueues } = require("../constants")
|
||||||
const { definitions } = require("./triggerInfo")
|
const { definitions } = require("./triggerInfo")
|
||||||
|
const { isDevAppID } = require("../db/utils")
|
||||||
|
|
||||||
const { opts } = utils.getRedisOptions()
|
const { opts } = utils.getRedisOptions()
|
||||||
let automationQueue = new Queue(JobQueues.AUTOMATIONS, { redis: opts })
|
let automationQueue = new Queue(JobQueues.AUTOMATIONS, { redis: opts })
|
||||||
|
@ -19,6 +20,11 @@ async function queueRelevantRowAutomations(event, eventType) {
|
||||||
if (event.appId == null) {
|
if (event.appId == null) {
|
||||||
throw `No appId specified for ${eventType} - check event emitters.`
|
throw `No appId specified for ${eventType} - check event emitters.`
|
||||||
}
|
}
|
||||||
|
// don't queue events which are for dev apps, only way to test automations is
|
||||||
|
// running tests on them
|
||||||
|
if (isDevAppID(event.appId)) {
|
||||||
|
return
|
||||||
|
}
|
||||||
const db = new CouchDB(event.appId)
|
const db = new CouchDB(event.appId)
|
||||||
let automations = await db.allDocs(
|
let automations = await db.allDocs(
|
||||||
getAutomationParams(null, { include_docs: true })
|
getAutomationParams(null, { include_docs: true })
|
||||||
|
|
|
@ -7,6 +7,8 @@ const {
|
||||||
APP_PREFIX,
|
APP_PREFIX,
|
||||||
SEPARATOR,
|
SEPARATOR,
|
||||||
StaticDatabases,
|
StaticDatabases,
|
||||||
|
isDevAppID,
|
||||||
|
isProdAppID,
|
||||||
} = require("@budibase/auth/db")
|
} = require("@budibase/auth/db")
|
||||||
|
|
||||||
const UNICODE_MAX = "\ufff0"
|
const UNICODE_MAX = "\ufff0"
|
||||||
|
@ -62,6 +64,8 @@ const BudibaseInternalDB = {
|
||||||
|
|
||||||
exports.APP_PREFIX = APP_PREFIX
|
exports.APP_PREFIX = APP_PREFIX
|
||||||
exports.APP_DEV_PREFIX = APP_DEV_PREFIX
|
exports.APP_DEV_PREFIX = APP_DEV_PREFIX
|
||||||
|
exports.isDevAppID = isDevAppID
|
||||||
|
exports.isProdAppID = isProdAppID
|
||||||
exports.USER_METDATA_PREFIX = `${DocumentTypes.ROW}${SEPARATOR}${InternalTables.USER_METADATA}${SEPARATOR}`
|
exports.USER_METDATA_PREFIX = `${DocumentTypes.ROW}${SEPARATOR}${InternalTables.USER_METADATA}${SEPARATOR}`
|
||||||
exports.LINK_USER_METADATA_PREFIX = `${DocumentTypes.LINK}${SEPARATOR}${InternalTables.USER_METADATA}${SEPARATOR}`
|
exports.LINK_USER_METADATA_PREFIX = `${DocumentTypes.LINK}${SEPARATOR}${InternalTables.USER_METADATA}${SEPARATOR}`
|
||||||
exports.ViewNames = ViewNames
|
exports.ViewNames = ViewNames
|
||||||
|
|
Loading…
Reference in New Issue