If your team relies on a shared Google Sheet to track incoming bug reports, new sales leads, or inventory requests, checking that spreadsheet manually every hour is highly inefficient. In a modern remote workflow, data should come to you.
You can build a seamless, automated bridge between Google Sheets and Slack using a custom Webhook and Google Apps Script. This allows you to configure your spreadsheet so that whenever a specific action occurs (like a new row being added, or a project status being changed to “Complete”), a beautifully formatted alert is instantly pushed directly to a dedicated Slack channel.
Step 1: Create an Incoming Webhook in Slack
First, we need to generate a secure URL that gives Google Sheets permission to post messages into your Slack workspace.
- Go to your Slack workspace in a web browser and navigate to the App Directory (slack.com/apps).
- Search for Incoming WebHooks and click “Add to Slack”.
- Choose the specific Slack channel where you want the spreadsheet alerts to appear (e.g.,
#sales-alerts) and click Add Incoming WebHooks integration. - Scroll down the settings page until you see the Webhook URL (it will look like
https://hooks.slack.com/services/T0000/B0000/XXXX). Copy this URL to your clipboard.
Step 2: Write the Apps Script in Google Sheets
Now we need to write a simple script that packages your spreadsheet data into a JSON payload and fires it at the Slack Webhook URL you just created.
- Open your Google Sheet.
- In the top menu, click Extensions > Apps Script.
- Delete any existing code in the editor and paste the following JavaScript:
function sendAlertToSlack(messageText) {
// 1. Paste your Slack Webhook URL here
var slackWebhookUrl = "https://hooks.slack.com/services/YOUR/WEBHOOK/URL_HERE";
// 2. Format the payload as a JSON object
var payload = {
"text": messageText,
"icon_emoji": ":mega:", // Optional: Adds a megaphone emoji to the bot
"username": "Sheets Bot" // Optional: Names the bot
};
// 3. Configure the HTTP POST request options
var options = {
"method": "post",
"contentType": "application/json",
"payload": JSON.stringify(payload)
};
// 4. Send the request to Slack
UrlFetchApp.fetch(slackWebhookUrl, options);
}
// A test function to trigger the alert manually
function testSlackMessage() {
sendAlertToSlack("🚨 *New Alert:* A high-priority item was added to the tracker!");
}
Crucial Step: Replace the dummy URL in line 3 with the actual Webhook URL you copied from Slack in Step 1. Click the Save (floppy disk) icon.
Step 3: Test the Connection
Before automating the script, let’s ensure it can successfully talk to Slack.
- In the Apps Script editor, ensure
testSlackMessageis selected in the dropdown menu at the top. - Click the Run button.
- Google will prompt you to review permissions. Follow the prompts to authorize the script to connect to an external service.
- Check your Slack channel. You should instantly see a message from “Sheets Bot” with a megaphone emoji, declaring the test successful.
Step 4: Automate the Alert (Optional)
You can now trigger this sendAlertToSlack() function however you want. You could add an “onEdit” trigger to send a message every time a specific cell is changed, or use a Time-Driven trigger to scan the sheet every night at 5:00 PM and send a summary of all rows marked “Incomplete” directly to your team’s Slack channel.