Opening Problem Statement
Meet Lisa, a project manager constantly juggling multiple Google Sheets filled with client data updates. Every day, she spends over an hour copying new entries manually and posting them to her team’s Mattermost channel. These manual steps often cause delays, errors, and duplicate notifications that frustrate her team and compromise project communication.
Lisa’s pain: losing valuable time, risking missed updates, and battling inconsistent communication that can cost her team deadlines and client trust.
What This Automation Does
This n8n workflow streamlines Lisa’s process by automatically monitoring changes in a specified Google Sheet and sending messages with the new data to a Mattermost channel every 45 minutes. Here’s how it benefits her:
- Automated Data Monitoring: It reads the Google Sheet periodically, identifying only new entries not sent before.
- Efficient Notifications: Sends precise messages to Mattermost with details like ID, Name, and Email from the sheet.
- Prevents Duplicates: Uses static data storage within n8n to keep track of already processed IDs, ensuring no repeated alerts.
- Time Savings: Automates an hour of manual work, freeing Lisa to focus on priorities.
- Reliable and Consistent: Runs every 45 minutes on a fixed schedule, guaranteeing team updates on time.
Prerequisites ⚙️
- n8n account with workflows enabled 🔑
- Google Sheets account with Access to the sheet to track 📊
- Mattermost workspace with API credentials set up for message posting 💬
- OAuth2 credentials configured for Google Sheets access 🔐
Step-by-Step Guide
Step 1: Create a new workflow and add the Interval node to trigger every 45 minutes
Navigate to the n8n dashboard. Click New Workflow. From the nodes panel, drag the Interval node onto the canvas. Configure the Unit as minutes and set the value to 45. This node will schedule the workflow to run periodically.
Common mistake: Forgetting to save or activate the workflow after setting the interval.
Step 2: Add the Google Sheets node to read sheet data
Drag the Google Sheets node next to the Interval node. Choose your OAuth2 credentials for authentication. Input the Google Sheet ID (the long string in the sheet URL) into the node parameters. Leave options default unless advanced filtering is needed.
You should see a preview of your sheet data when you run this node in test mode.
Common mistake: Inputting an incorrect Sheet ID or not setting up OAuth2 properly.
Step 3: Add the Function node to check for new data
Connect the output of the Google Sheets node to a Function node. Paste this JavaScript code exactly into the Function Code box:
const new_items = [];
const data = this.getWorkflowStaticData("node");
data.ids = data.ids || [];
for (let i = items.length - 1; i >= 0; i--) {
if (data.ids.includes(items[i].json.ID)) {
break;
} else {
new_items.push({
json: {
id: items[i].json.ID,
name: items[i].json.Name,
email: items[i].json.Email
},
});
}
}
data.ids = items.map((item) => item.json.ID);
return new_items;This code checks which rows are new by comparing IDs with previously processed IDs stored in the node’s static data.
Common mistake: Using inconsistent column names in your sheet versus in the code (“ID”, “Name”, “Email” must exactly match).
Step 4: Add the Mattermost node to send notifications
Drag the Mattermost node and connect it to the Function node output. Configure with your Mattermost API credentials. In the message field, paste this template:
New information was added to your Google Sheet.
ID: {{$json["id"]}}
Name: {{$json["name"]}}
Email: {{$json["email"]}}This sends a formatted message with details from the new rows directly to your Mattermost channel.
Common mistake: Not setting up the Mattermost API credentials or wrong URL endpoints.
Step 5: Connect all nodes and test the workflow
Connect the Interval node to the Google Sheets node, then connect Google Sheets to the Function node, and finally to the Mattermost node. Save and activate your workflow. Run manually or wait for the next interval trigger.
You should see new row messages post automatically to Mattermost if new data exists.
Customizations ✏️
- Change Notification Frequency: In the Interval node, adjust the timing to run every 30 minutes or hourly based on your team’s update needs.
- Include Additional Fields: Add more columns from Google Sheets into the message by editing the Function node code and Mattermost message template.
- Filter Specific Rows: Modify the Function node to only process rows matching certain criteria, such as a status column value.
Troubleshooting 🔧
Problem: “Function node returns no data”
Cause: The Google Sheets node did not retrieve data or column names don’t match the code.
Solution: Verify the Sheet ID is correct. Check OAuth2 credentials. Ensure that your sheet columns are named exactly “ID”, “Name”, and “Email” because the Function node’s code depends on these labels.
Problem: “Mattermost node fails to send message”
Cause: Incorrect Mattermost API credential setup or invalid endpoint.
Solution: Go to the Mattermost node credentials and reconfigure the API URL and token. Test with a simple message to confirm connectivity.
Pre-Production Checklist ✅
- Verify Google Sheet ID and OAuth2 permission scope includes reading sheet data.
- Confirm Mattermost API token is active and has posting permissions.
- Test the Function node logic by running with sample data.
- Run a manual workflow execution to confirm messages appear in Mattermost.
- Backup existing sheet data in case errors require rollback.
Deployment Guide
After final testing, activate the workflow in n8n. Confirm it is set to run every 45 minutes via the Interval node. Monitor the first few runs through the execution history on your n8n dashboard to catch any errors early.
Consider setting up error notifications in n8n for workflow issues. If self-hosting n8n, ensure your server has reliable uptime to avoid missing updates.
FAQs
Q: Can I use Slack instead of Mattermost?
A: Yes! You can swap the Mattermost node with a Slack node and adjust message formatting accordingly.
Q: Does this workflow consume Google API credits?
A: Yes, each Google Sheets node execution counts as an API call, but moderate intervals like 45 minutes keep usage low.
Q: Is my data safe?
A: Yes, OAuth2 authentication secures your Google Sheets access, and Mattermost API tokens are stored securely in n8n credentials.
Q: What if my sheet has many columns?
A: You can customize the Function node code to send just the relevant columns for notifications to avoid noise.
Conclusion
By building this n8n workflow, you automated the tedious task of monitoring Google Sheets and updating your Mattermost team with fresh data every 45 minutes. Your team stays informed without manual effort. Lisa, in our scenario, saves upwards of an hour daily and avoids errors from manual copying.
Next steps? Consider automating data validation in Google Sheets before sending messages, or integrating other communication channels like email or SMS for urgent alerts.