How to Automatically Send a Slack Message from Google Sheets Using a Webhook and Apps Script

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.

  1. Go to your Slack workspace in a web browser and navigate to the App Directory (slack.com/apps).
  2. Search for Incoming WebHooks and click “Add to Slack”.
  3. Choose the specific Slack channel where you want the spreadsheet alerts to appear (e.g., #sales-alerts) and click Add Incoming WebHooks integration.
  4. 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.

  1. Open your Google Sheet.
  2. In the top menu, click Extensions > Apps Script.
  3. 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.

  1. In the Apps Script editor, ensure testSlackMessage is selected in the dropdown menu at the top.
  2. Click the Run button.
  3. Google will prompt you to review permissions. Follow the prompts to authorize the script to connect to an external service.
  4. 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.

RELATED POSTS

  • How to Completely Remove All Hyperlinks in a Google Docs Document Simultaneously
  • How to Automatically Send an Email from Google Sheets When a Cell Value Changes Using Apps Script
  • How to Force Google Sheets to Automatically Recalculate Formulas Every Minute
  • How to Use the Google Sheets SORTN Function to Find Top Performers
  • How to Protect Cells and Ranges in Google Sheets from Accidental Edits
  • Get the best tech tips delivered straight to your inbox.

    Join thousands of readers mastering Apple, Google, Microsoft, and Linux.