
To automate Slack notifications from Google Sheets, you'll need to use Google Apps Script. This script can be triggered by certain criteria, such as when a value in a cell changes.
The script can be set up to send a message to a specific Slack channel, and the message can include data from the Google Sheet. This is done by using the Slack Webhook URL and the Google Apps Script's HTTP service.
You can also use Google Sheets' built-in functions to filter and sort data before sending it to Slack. For example, you can use the "IF" function to check if a cell meets a certain condition, and then send a notification if it does.
You might like: Export Looker Studio to Google Sheets
Setting Up the Script
To set up the script, start by opening up your Google Sheet menu and navigating to Extensions > Apps Script.
Clear out all the existing default code in the code editor window so you have a blank window.
You'll need to paste in the three parts of code, which include a function that gets the data from your spreadsheet and checks which students and channels are selected, and then calls the functions that send out emails and send messages to Slack.
First, go to the URL https://my.slack.com/services/new/incoming-webhook/ to grab a unique webhook for your Slack team.
For your interest: Slack Integration Google Drive
Getting Student Data
To get student data, you'll want to use a function that grabs relevant information from a Google Sheet. This function is responsible for selecting the students' data, seeing which students have been selected, and then requesting the program to send emails or Slack messages as required.
The function works by grabbing all the relevant student data from the Summary sheet and putting it into a variable called "range" (lines 3 to 7). It then loops through this entire range, student by student (lines 13 to 37).
Here's a breakdown of the steps the function takes:
- It checks if the row of data is marked with a "Yes" in the Submit column (line 14).
- If it is "Yes", the function proceeds to the switch statement, which looks at whether to send feedback to the student via a Slack message, an email, or both (lines 17 to 32).
- If the loop finds a "No" at the If check, the function simply moves on to the next student, and no communications are sent.
Get Student Data and Determine Action

The main function, also known as the engine, is responsible for selecting students' data, determining which students to select, choosing the communication channel, and then requesting the program to send emails or Slack messages as required.
This function grabs all relevant student data from the Summary sheet and puts it into a variable called "range" (lines 3 to 7).
It then loops through this entire range, student by student, from lines 13 to 37.
At each iteration of the loop, it checks if that row of data is marked with a "Yes" in the Submit column (line 14).
If it is "Yes", then the function proceeds to the switch statement, which looks at whether to send feedback to the student via a Slack message, an email, or both (lines 17 to 32).
The function either calls the sendToSlack function, the sendEmail function, or calls both, depending on the choice in the Google Sheet.

A date is added to the Google Sheet in the final column of the Summary sheet, against any rows for which we have sent Slack messages and/or emails.
If the loop finds a "No" at the If check, then it simply moves on to the next student, and no communications are sent.
The entire process can be seen in action on the provided Github link.
Fetch Data from Your Spreadsheet
To get started with sending student data to Slack or email, you need to fetch the data from your Google spreadsheet. This can be done using Google Apps Script, which allows you to access and manipulate your spreadsheet data programmatically.
You can access the script editor by clicking Tools > Script editor in your Google spreadsheet. If you copied a template spreadsheet, the required code will already be in place, but if you're starting from scratch, you'll need to set things up.
Give your script a meaningful name, and replace the empty function at the top with the following code, which gets the data from cells A1:B6. If you're using your own spreadsheet, update the range to reflect your own data.
To get the data from your spreadsheet, you need to specify the range of cells that contain the data you want to fetch. In this case, the range is A1:B6, but you can change it to suit your needs.
Here's a summary of the steps to fetch data from your spreadsheet:
- Click Tools > Script editor in your Google spreadsheet.
- Give your script a meaningful name and replace the empty function at the top with the code to get the data from your spreadsheet.
- Update the range to reflect your own data if you're using a different spreadsheet.
By following these steps, you'll be able to fetch the data from your spreadsheet and use it to send student data to Slack or email.
Configuring the Alert
You can create custom alerts by setting up rule conditions, such as price drops or availability changes.
To receive an alert when the price drops, open the Price drops rule and add Slack, just like you added Google Sheets in Step 4. Choose a channel, and compose your message in a similar way to this:
You can also receive availability changes by repeating the same instructions using the Availability changed rule.
To send the alert to Slack, you'll need to paste in your webhook URL that you created in Step 1. You can get that from your app's 'incoming webhooks' page.
Your Slack App is now ready to start receiving data from an external service.
Here are the steps to follow:
- Create a custom app in Slack
- Fetch data from your spreadsheet using Google Apps Script
- Transform the data into a format understandable by Slack
- Send the alert to Slack
- Bonus step: Set up scheduled alerts
Note: You'll need some basic experience of Google Apps Script and/or JavaScript to understand everything in this article.
Automating the Process
The main function of the code is the engine that selects the students' data and determines what action to take.
It grabs all the relevant student data from the Summary sheet and puts it into a variable called "range" (lines 3 to 7).
The code then loops through this entire range, student by student, from lines 13 to 37.
At each iteration of the loop, it checks if that row of data is marked with a "Yes" in the Submit column (line 14).
If it is "Yes", then the code proceeds to the switch statement, which looks at whether to send feedback to the student via a Slack message, an email, or both (lines 17 to 32).
The switch statement is based on the choice made in the Google Sheet, which determines whether to call the sendToSlack function, the sendEmail function, or both.
A date is added to the Google Sheet in the final column of the Summary sheet, against any rows for which a Slack message and/or email have been sent.
The code simply moves on to the next student if it finds a "No" at the If check, and no communications are sent.
A different take: Christian Horner Whatsapp Message Google Drive
Transform Data for Another Platform
Transforming data for another platform can be a bit tricky, but it's a crucial step in sending a Slack message from a Google Sheet when certain criteria are met.
First, you need to understand that the data you fetched from your Google Sheet is in JavaScript array format, which Slack won't understand.
You need to convert this data into specially-structured JSON that Slack will understand, known as 'Blocks'.
The structure of an alert in Slack is fairly simple, with 5 sections: the alert title, a horizontal divider, a sentence, another sentence, and a breakdown of revenue.
Each of these elements is represented by an object within the "blocks" array of your 'payload' variable.
If you want to add another section, just insert another element into the array!
Here's a breakdown of the structure of an alert in Slack:
Slack's Block Kit Builder is a great place to experiment with the JSON format before setting up your 'payload' variable in Apps Script.
The subsequent code block takes the remaining data in the array and turns it from an array into a text string, formatted the way we want.
Receive Alerts
To receive alerts in Slack, you can set up custom rules in Google Sheets. You can create alerts for specific events like price drops or availability changes.
The process involves setting up a rule condition and adding Slack as the notification channel. You can compose a custom message to be sent to Slack when the condition is met.
For example, you can set up a rule to send a message to Slack when the price drops. To do this, open the Price drops rule and add Slack as a notification channel. Choose a channel and compose your message.
You can also set up a rule to send a message to Slack when the availability status changes. Repeat the same instructions using the Availability changed rule.
Here are the basic steps to send Slack alerts from Google Sheets:
1. Create a custom app in Slack
2. Fetch data from your spreadsheet using Google Apps Script
3. Transform the data into a format understandable by Slack
4. Send the alert to Slack
5. Bonus step: Set up scheduled alerts
Note that you'll need some basic experience with Google Apps Script and/or JavaScript to understand the process.
Broaden your view: How to Send Files in Google Drive Using Phone
Apps Script Code
To get started with the Apps Script code, open up your Google Sheet menu and navigate to Extensions > Apps Script. You'll need to clear out the existing default code and paste in the three parts of code provided.
The code consists of three parts: a function that gets data from your spreadsheet and checks which students and channels are selected, a function that sends out emails, and a function that sends messages to Slack.
First, you'll need to grab a unique webhook for your Slack team by going to https://my.slack.com/services/new/incoming-webhook/. You'll be prompted to login with your Slack team name and then your login details.
You'll then be presented with a screen where you choose the channel, but don't worry, it's the same webhook for your team, no matter which channel you choose. Our program will choose each channel on the fly based on the student selected.
To send a message to Slack, you'll need to specify the options for your request, including the channel, icon, and JSON data. This is done on lines 28 to 32 of the code.
Finally, the last line of the code sends the message to Slack by making a POST request to the Slack webhook using the UrlFetchApp service.
For another approach, see: How to Make Message Important in Teams
Connecting to Google Sheets
Connecting to Google Sheets is a crucial step in sending Slack messages from your Google Sheets when certain criteria are met. To do this, you'll need to create a custom app in Slack and then connect it to your Google Sheets. On the Conditions pane, specify if you want your workflow to run only if the Google Sheet row satisfies certain conditions.
You can choose Slack from the list of available tasks. This will allow you to specify the conditions under which your workflow will run. By default, the workflow will run for all rows in the Google Sheet, but you can customize this to suit your needs.
To connect Slack to your Google Sheets, you'll need to follow these steps:
- Create a custom app in Slack
- Connect it to your Google Sheets
- Specify the conditions under which your workflow will run
Here's a simple outline of the steps involved:
By following these steps, you'll be able to connect your Google Sheets to Slack and send messages when certain criteria are met.
Activate Workflow
To activate the workflow, click the Preview button. This will send a Slack message from the second row of the selected Google Sheet.
The message will be posted in your Slack channel, allowing you to see how the workflow will function. Click Done to locally apply your changes.
The workflow will also appear in the workflow dashboard, where you can edit, delete, or manually run the workflow.
Featured Images: pexels.com


