This Google Apps Script allows you to send messages to a Google Chat space when new data is added to a Google Sheets document. This README provides instructions on how to set up and use this script.
Before you can use this script, you'll need the following:
- A Google account.
- Access to Google Sheets where you want to trigger message sending.
- A Google Chat space where you want to send messages.
- Familiarity with Google Apps Script.
Follow these step-by-step instructions to set up and use the script:
-
Create a Google Apps Script Project:
- Open your Google Sheets document.
- Click on
Extensions
>Apps Script
to open the script editor. - Delete any existing code in the script editor.
-
Copy and Paste the Provided Code:
- Copy the JavaScript code provided in the
sendChatMessage()
function from your Google Apps Script file.
- Copy the JavaScript code provided in the
-
Configure Webhook URL:
- Replace
webhookUrl
with your Google Chat webhook URL. You can obtain this URL by following Google's official documentation on how to create a webhook in Google Chat.
- Replace
-
Configure Sheet Name:
- Replace
sheetName
with the name of the sheet tab where your form responses are recorded.
- Replace
-
Save the Script:
- Click the floppy disk icon or press
Ctrl + S
to save the script.
- Click the floppy disk icon or press
-
Set Up Trigger:
- Click on the clock icon on the left sidebar to open the "Triggers" page.
- Click on the "+ Add Trigger" button.
- Choose the function
sendChatMessage
. - Choose deployment settings (e.g., run as yourself).
- Choose the event source (e.g., "From spreadsheet," "On form submit").
- Save the trigger.
-
Test the Script:
- Add a new row of data to your Google Sheets document in the specified sheet.
- Wait for the trigger to execute (this may take a few moments).
- Check your Google Chat space for the message.
-
Monitor Logs (Optional):
- You can monitor script execution by going to
View
>Logs
in the script editor.
- You can monitor script execution by going to
Now that you have set up the script and tested it, new Google Sheets rows added to the specified sheet will automatically trigger messages to your Google Chat space with the provided data.
You can customize the message format by modifying the message
object in the code.
- If the script doesn't work as expected, review the logs in the script editor for error messages.
- Make sure that your Google Chat webhook URL is correctly configured.
- Ensure that the trigger is set up correctly and has the necessary permissions.
This script was created using Google Apps Script. Credits to the original author.