MGL Group Updater using Slack
@MakeGiveLive
code:
data:privatelast updated:1 year ago
today
Build integrations remarkably fast!
You're viewing a public workflow template.
Sign up to customize, add steps, modify code and more.
Join 250,000+ developers using the Pipedream platform
steps.
trigger
Slack - New Message In Conversation(s)
last updated:2 years ago
steps.
getBaseID
auth
to use OAuth tokens and API keys in code via theauths object
(auths.airtable)
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 invocations with$checkpoint.
async (event, steps, auths) => {
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
// Get Group Name from Slack Message
var msg = steps.trigger.event.text;
var n = msg.indexOf("* in ");
var group = msg.substr(n+5, msg.length - n+5);
//console.log('https://api.airtable.com/v0/appsEhmLOfUP2Svk5/MGL%20Groups?filterByFormula=SEARCH("'+group+'",{Group})');


const config = {
  url: `https://api.airtable.com/v0/appsEhmLOfUP2Svk5/MGL%20Groups?filterByFormula=SEARCH("${group}",{Group})`,
  
  headers: {
    Authorization: `Bearer ${auths.airtable.api_key}`,
  },
}

//steps.getGroup.$return_value.records[0].fields.baseid
var x = await require("@pipedreamhq/platform").axios(this, config);
var baseID = x.records[0].fields.baseid;
return baseID;
//return await require("@pipedreamhq/platform").axios(this, config);
//var results =  await require("@pipedreamhq/platform").axios(this, config)
//console.log(results);
//var baseID = results.records[0].fields.baseID;
//return baseID
//return steps.getGroup.$return_value.records[0].fields.baseid
// Get Group Name from Slack Message
var msg = steps.trigger.event.text;
var n = msg.indexOf("* in ");
var group = msg.substr(n+5, msg.length - n+5);
//console.log('https://api.airtable.com/v0/appsEhmLOfUP2Svk5/MGL%20Groups?filterByFormula=SEARCH("'+group+'",{Group})');


const config = {
  url: `https://api.airtable.com/v0/appsEhmLOfUP2Svk5/MGL%20Groups?filterByFormula=SEARCH("${group}",{Group})`,
  
  headers: {
    Authorization: `Bearer ${auths.airtable.api_key}`,
  },
}

//steps.getGroup.$return_value.records[0].fields.baseid
var x = await require("@pipedreamhq/platform").axios(this, config);
var baseID = x.records[0].fields.baseid;
return baseID;
//return await require("@pipedreamhq/platform").axios(this, config);
//var results =  await require("@pipedreamhq/platform").axios(this, config)
//console.log(results);
//var baseID = results.records[0].fields.baseID;
//return baseID
//return steps.getGroup.$return_value.records[0].fields.baseid
steps.
getUpdateData
auth
to use OAuth tokens and API keys in code via theauths object
(auths.airtable)
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 invocations with$checkpoint.
async (event, steps, auths) => {
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
29
30
31
32
33
34
35
36
37
}
38
// You'll need to add your Airtable API key and baseId to the 

const Airtable = require('airtable')
const base = new Airtable({apiKey: auths.airtable.api_key}).base(steps.getBaseID.$return_value)

// 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.
event.updates = [];
for (let attachment of steps.trigger.event.attachments) {
  let { tableId, recordId } = attachment.title_link.match(titleRegex).groups
  //console.log(`tableId: ${tableId}, recordId: ${recordId}`)
  let record = await base(tableId).find(recordId)
  let createdTime = record._rawJson.createdTime
  let baseId = steps.getBaseID.$return_value
  let updates = attachment.fields.map(slackMessageField => {
    return { 
      field: slackMessageField.title, 
      newValue: slackMessageField.value,
    }
  })


  event.updates.push({
    record, baseId, tableId //, recordId, createdTime, updates
  })
}


return event.updates;

//return record;
// You'll need to add your Airtable API key and baseId to the 

const Airtable = require('airtable')
const base = new Airtable({apiKey: auths.airtable.api_key}).base(steps.getBaseID.$return_value)

// 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.
event.updates = [];
for (let attachment of steps.trigger.event.attachments) {
  let { tableId, recordId } = attachment.title_link.match(titleRegex).groups
  //console.log(`tableId: ${tableId}, recordId: ${recordId}`)
  let record = await base(tableId).find(recordId)
  let createdTime = record._rawJson.createdTime
  let baseId = steps.getBaseID.$return_value
  let updates = attachment.fields.map(slackMessageField => {
    return { 
      field: slackMessageField.title, 
      newValue: slackMessageField.value,
    }
  })


  event.updates.push({
    record, baseId, tableId //, recordId, createdTime, updates
  })
}


return event.updates;

//return record;
steps.
updateArray
auth
to use OAuth tokens and API keys in code via theauths object
(auths.airtable)
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 invocations with$checkpoint.
async (event, steps, auths) => {
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
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52