Save Slack Channel Links to Google Sheets
This app checks Slack messages posted to your Slack workspace that contain links
and saves those links, along with the person who posted them, the channel they
were posted in, and when they were posted, in Google Sheets.
User's Guide

Step 1. Press the Open in Autocode button above to fork your own copy of
the source.
Step 2. Next, you'll be in the Autocode editor. You can open
functions/events/slack/message/channels.js
to see the logic for
the project. This endpoint will trigger whenever a message is posted to your
channel. It checks to see whether the message text contains one or more links
using this code adapted to Slack's message link formatting:
let matches = [...(event.event.text || '').matchAll(/<((https?)?:\/\/[^\s$.?#].[^\s\|>]*)/gi)];
Then, if the message contains one or more links, the endpoint will insert the
matches one by one into the linked Google Sheet using the
googlesheets.query API:
for (let i = 0; i < matches.length; i++) {
result.googlesheets.insertQueryResult = await lib.googlesheets.query['@0.3.0'].insert({
range: `A:Z`,
fieldsets: [
{
'Poster': `${result.slack.user.name}`,
'Channel': `#${result.slack.channel.name}`,
'Link': `${matches[i][1]}`,
'Date': `${format.asString('MM/dd/yy', new Date())}`
}
]
});
}
There is some commented out code that will send you an ephemeral
message in Slack letting you know which links have been stored in the
Google Sheet as well. If you would like to receive this confirmation message,
open the functions/events/slack/message/channels.js
file
and comment this code back in (remove the //
characters from everything
except the first line below):
// Comment in to send an ephemeral message confirming the links added to spreadsheet
// result.slack.messageResponse = await lib.slack.messages['@0.6.1'].ephemeral.create({
// channelId: `${event.event.channel}`,
// userId: `${event.event.user}`,
// text: `I've added the following links to the Google spreadsheet:`,
// attachments: matches.map((match) => {
// return {
// text: `*${match[1]}*`
// }
// })
// });
The message, if enabled, will look like this:
Step 3. I'll assume you already have a Slack workspace, so next we need to
set up a Google Sheet you'd like to use. Your spreadsheet must have these
four case-sensitive values in the A
row, with no whitespace after them:
Your spreadsheet should look like this:
Step 4. Once you've done that, return to the Autocode editor. You should see
a bouncing button indicator in the bottom right like this:
Click the button and link the Google Sheet you created and the Slack workspace
you'd like to use. For Slack, it's much faster to get started with the Autocode
app, so I'd recommend going with that option.
Step 5. Once you've linked the proper accounts, press the blue Deploy
button in the bottom left and you're done!
Thanks for reading! If you have any questions, the best place to ask them is
in our Slack workspace. You can get an invite from the Community tab in the
topbar of this page. Happy hacking!