auths
objectreturn
or this.key = 'value'
, pass input data to your code viaparams
, and maintain state across executions with$checkpoint.async
(event, steps) => {
}
// Exit early if this message doesn't have any attachments
if (!("event" in event.body) || !('attachments' in event.body.event)) {
$end("No attachments in this Slack message — not an Airtable update.")
}
// ... or if the attachments don't actually contain Airtable data.
// This filters out any other messages from getting processed through
// the rest of the workflow
if (!(event.body.event.attachments[0].title_link.match(/https:\/\/airtable\.com.*/))) {
$end("No Airtable title_link in this Slack message — not an Airtable update.")
}
auths
objectreturn
or this.key = 'value'
, pass input data to your code viaparams
, and maintain state across executions with$checkpoint.async
(event, steps) => {
}
// Used for extracting the baseId and recordId from the Airtable URL
// included in each record update sent to Slack
const titleRegex = /https:\/\/airtable\.com\/(?<tableId>.*)\/(?<recordId>.*)/
// Airtable sends a batch of updates in a single message, but includes
// updates to individual records in Slack message attachments.
// For each of those attachments (record updates), we construct a JavaScript
// object that looks closer to what you'd expect to receive from a webhook directly.
this.updates = event.body.event.attachments.map(attachment => {
let { tableId, recordId } = attachment.title_link.match(titleRegex).groups
let updates = attachment.fields.map(slackMessageField => {
return {
field: slackMessageField.title,
newValue: slackMessageField.value,
}
})
return {
tableId, recordId, updates
}
})
async
params => {
}
const axios = require("axios")
const config = {
method: params.method || "post",
url: params.url,
}
for (const { key, value } of params.query || []) {
if (!config.params) config.params = {}
config.params[key] = value
}
for (const { key, value } of params.headers || []) {
if (!config.headers) config.headers = {}
config.headers[key] = value
}
if (params.auth) {
config.auth = {
username: params.auth.username,
password: params.auth.password,
}
}
if (params.payload) config.data = params.payload
try {
return await axios(config)
} catch (err) {
this.err = err
throw err
}