Hero Bg Gradient
February 15th, 2025

How to Send Slack Notifications from Google Sheets Using Google Apps Script

Learn how to automate Slack notifications directly from Google Sheets using Google Apps Script and Slack’s Incoming Webhooks. Keep your team instantly updated whenever spreadsheet data changes.

Client Image

Patrick Flanagan

February 15th, 2025

Blog Details Image

Are you tired of manually sending Slack messages to update your team every time a certain cell or row changes in Google Sheets? By combining Google Apps Script with Slack Incoming Webhooks, you can automatically notify a Slack channel (or direct message) whenever your spreadsheet data is added or updated. In this tutorial, you’ll learn the step-by-step process, complete with code snippets, to set up this integration.

What You’ll Need

  1. A Slack Workspace: Make sure you have permission to create an incoming webhook or coordinate with an administrator who does.
  2. Slack App or Webhook URL: You’ll need an active Incoming Webhook URL in Slack.
  3. Google Sheets: A spreadsheet to monitor.
  4. Basic Apps Script Knowledge: Familiarity with JavaScript syntax will make this easier, but it’s not required.

Step 1: Create a Slack Incoming Webhook

  1. Go to your Slack workspace and open the Slack API: Incoming Webhooks page.
  2. Choose or create an app, then select Incoming Webhooks under the “Features” section on the left.
  3. Toggle Activate Incoming Webhooks to ON.
  4. Click Add New Webhook to Workspace.
  5. Select a channel (or direct message) where you want the notifications to appear.
  6. Copy the Webhook URL; you’ll need it in your script.

Step 2: Set Up Your Google Sheet

  1. Identify which sheet and which range you want to monitor. For example, you might watch for changes in a “Status” column or keep track of new rows being added.
  2. (Optional) Label your columns clearly (e.g., Name, Task, Status, etc.) so you can reference them easily in your notifications.

Step 3: Open the Apps Script Editor

  1. In Google Sheets, navigate to Extensions > Apps Script to open the editor.
  2. A new tab will open where you can write and manage your script.

Step 4: Add Your Script

Below is a simple example that watches for edits in the “Status” column and sends a Slack notification if a status changes.

/**
 * Trigger: onEdit(e)
 * This simple trigger will run automatically whenever a cell is edited.
 */
function onEdit(e) {
  // Replace with your Slack Incoming Webhook URL
  const SLACK_WEBHOOK_URL = 'https://hooks.slack.com/services/YOUR/UNIQUE/WEBHOOK';

  // (Optional) The name of your sheet to monitor
  const SHEET_NAME = 'Sheet1';

  // Adjust the column index if you only want to watch a specific column 
  // (e.g., 'Status' is in column 3 -> 3rd column)
  const STATUS_COLUMN_INDEX = 3;

  // e.range gives the edited cell's Range object
  const range = e.range;
  const sheet = range.getSheet();
  
  // Check if we're on the correct sheet
  if (sheet.getName() !== SHEET_NAME) return;

  // Check if the edited cell is in the status column
  if (range.getColumn() === STATUS_COLUMN_INDEX) {
    // Get the updated value (i.e., the new status)
    const newValue = range.getValue();

    // Get additional info (optional): row data, user email, etc.
    const rowNumber = range.getRow();
    const name = sheet.getRange(rowNumber, 1).getValue(); // e.g., "Name" column in column 1
    const task = sheet.getRange(rowNumber, 2).getValue(); // e.g., "Task" column in column 2
    
    // Construct your Slack message
    const slackMessage = {
      text: `*Status Update*\n• *Name:* ${name}\n• *Task:* ${task}\n• *New Status:* ${newValue}`
    };

    // Send the POST request to Slack
    UrlFetchApp.fetch(SLACK_WEBHOOK_URL, {
      method: 'post',
      contentType: 'application/json',
      payload: JSON.stringify(slackMessage)
    });
  }
}

Code Explanation

  • onEdit(e): A simple trigger that fires whenever a cell is edited in the spreadsheet.
  • STATUS_COLUMN_INDEX: Adjust this based on the column you want to monitor.
  • SLACK_WEBHOOK_URL: Insert the URL you got from Slack.
  • Constructing the Slack Message: Slack expects a JSON payload with a “text” property. You can also use Block Kit formatting for more complex messages.
  • UrlFetchApp.fetch: Sends an HTTP POST request to the Slack webhook URL with the message payload.

Step 5: Set Up Permissions

When you first save and run this script (although onEdit(e) doesn’t require a manual run), Google will ask you to authorize specific services:

  • UrlFetchApp: Needed to call external webhooks (Slack in this case).

Step 6: Test Your Automation

  1. Return to your Google Sheet.
  2. Update or change a cell in the monitored column (in this example, column C / 3rd column).
  3. Check your Slack channel; you should see a new message with the updated details.

Tips for Testing:

  • Use dummy data in your spreadsheet.
  • Open Slack in a separate browser tab for quick viewing.
  • If nothing appears, check the Apps Script Execution Log or Slack’s webhook logs (if available).

Step 7: Customize & Expand

  • Multiple Channels: You can create multiple webhook URLs for different Slack channels.
  • Batch Updates: For larger datasets, you might prefer an onChange trigger or a manual function that loops through rows and posts updates.
  • Advanced Formatting: Explore Slack’s Block Kit Builder to design richer, more interactive messages.
  • Error Handling: Consider wrapping your UrlFetchApp.fetch call in a try-catch block to manage potential network failures.

Conclusion

By linking Google Apps Script with Slack’s Incoming Webhooks, you can fully automate the flow of critical information right from your spreadsheets. This integration saves you time, ensures updates are never missed, and keeps your team in the loop—even when you’re away from your desk.

If you found this useful, feel free to explore more ways to automate your workflow. You can do everything from sending scheduled Slack reminders to integrating with other third-party APIs. With a bit of creativity and code, Google Apps Script can become your ultimate automation powerhouse.

Happy automating!

About the Author
This post was written by Patrick Flanagan, a Google Apps Script and Expert Automation developer specializing in custom integrations across Google Workspace and more. If you have questions or need assistance with your own Slack-Apps Script projects, contact us to learn more!

Ready to Transform Your Business?