Airtable Slack Messages -> Webhook
@dylburger
code:
data:privatelast updated:4 years ago
today
Build integrations remarkably fast!
You're viewing a public workflow template.
Sign up to customize, add steps, modify code and more.
Join 800,000+ developers using the Pipedream platform
steps.
trigger
HTTP API
Deploy to generate unique URL
This workflow runs on Pipedream's servers and is triggered by HTTP / Webhook requests.
steps.
skip_non_airtable_slack_messages
auth
to use OAuth tokens and API keys in code via theauths object
code
Write any Node.jscodeand use anynpm package. You can alsoexport datafor use in later steps via return or this.key = 'value', pass input data to your code viaparams, and maintain state across executions with$checkpoint.
async (event, steps) => {
1
2
3
4
5
6
7
8
9
10
11
}
12
// 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.")
}
steps.
format_webhook_body
auth
to use OAuth tokens and API keys in code via theauths object
code
Write any Node.jscodeand use anynpm package. You can alsoexport datafor use in later steps via return or this.key = 'value', pass input data to your code viaparams, and maintain state across executions with$checkpoint.
async (event, steps) => {
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
}
22
// 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
  }
})
steps.
send_http_request
Send data to an HTTP destination.
params
Url
 
string ·params.url
Payload
{{steps.format_webhook_body.updates}}
string ·params.payload
Optional
code
async params => {
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
}
28
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
}