1. Opening Problem Statement
Meet Emily, an HR coordinator at a fast-growing tech startup. Every Monday morning, Emily faces the daunting task of manually organizing virtual coffee chats among team members to foster connection and camaraderie. She spends hours collecting names, randomizing groups, sending messages on Mattermost, and creating calendar invites. Despite her efforts, mistakes slip through: groups end up uneven, invites get missed, and some people feel left out.
This manual approach wastes Emily roughly 2-3 hours weekly—time that could be better spent on strategic HR initiatives. It also causes frustration for employees who look forward to these coffee chats as a way to stay connected remotely. The lack of automation in this routine task causes inefficiencies and errors impacting team morale and HR productivity.
2. What This Automation Does
This n8n workflow automates the entire process of organizing weekly virtual coffee chats for teams using Mattermost and Google Calendar. Here’s what happens when it runs every Monday at 10 AM:
- Automatically triggers on Monday mornings to kick off the coffee chat scheduling.
- Retrieves a list of active users currently in a specified Mattermost channel dedicated to coffee chats.
- Randomly groups team members into ideal groups of three, ensuring no group is smaller than two people.
- Announces the groups in the Mattermost channel with a friendly message, so everyone knows their coffee chat partners.
- Sends Google Calendar invites with conference links to each group, making it easy for participants to join at the scheduled time.
By automating these tasks, Emily saves around 2 hours every week and eliminates errors from manual grouping and invitation sending. Teams get organized notifications and calendar reminders without any hassle.
3. Prerequisites ⚙️
- n8n account for workflow automation.
- Mattermost account with API access and an API credential configured in n8n.
- Google Calendar account with OAuth2 credentials set up in n8n.
- A dedicated Mattermost channel for the coffee chat group where participants are members.
- Basic knowledge of n8n’s interface and credential management.
4. Step-by-Step Guide
Step 1: Set Up the Weekly Trigger Node
Navigate to your n8n editor and drag in the Cron node.
- Click “+ Add Trigger” → choose Weekly.
- Set Day to Monday and Hour to 10:00 AM.
- Save this to trigger the workflow every Monday.
Outcome: This node will fire the workflow on schedule, initiating coffee chat automation.
Common mistake: Forgetting to set the correct timezone can cause unexpected trigger times.
Step 2: Configure the Greetings Node
Drag in a Mattermost node to send a welcoming message.
- Select the Message operation.
- Input the greeting message:
👋 Happy MondayGroups for this week's virtual coffee are:
- Enter your dedicated Mattermost Channel ID.
- Select your saved Mattermost API credentials.
Outcome: Sends an introductory message in the channel before listing groups.
Common mistake: Using the wrong Channel ID causes messages not to appear.
Step 3: Fetch Users from Coffee Chat Channel
Add another Mattermost node configured to fetch users.
- Set Resource to
userand Operation togetAll. - In Additional Fields, input the same Channel ID under
inChannel. - Use the same Mattermost credentials.
Outcome: Retrieves a current list of users available for coffee chats.
Common mistake: Misspelling or mismatching the Channel ID will yield zero users.
Step 4: Divide Users into Groups with Function Node
Add a Function node named “Divide into groups” to randomize and group users.
Copy and paste the following JavaScript code exactly:
const ideal_group_size = 3;
let groups = [];
let data_as_array = [];
let newItems = [];
// Take all users from input
for (let j = 0; j < items.length; j++) {
data_as_array.push({ username: items[j].json.username, email: items[j].json.email });
}
// Shuffle function
function shuffle(array) {
let currentIndex = array.length, temporaryValue, randomIndex;
while (currentIndex !== 0) {
randomIndex = Math.floor(Math.random() * currentIndex);
currentIndex--;
temporaryValue = array[currentIndex];
array[currentIndex] = array[randomIndex];
array[randomIndex] = temporaryValue;
}
return array;
}
data_as_array = shuffle(data_as_array);
// Create groups of 3
for (let i = 0; i < data_as_array.length; i += ideal_group_size) {
groups.push(data_as_array.slice(i, i + ideal_group_size));
}
// Avoid groups with single person
for (let k = 0; k < groups.length; k++) {
if (groups[k].length === 1) {
groups[k].push(groups[k - 1].shift());
}
}
for (let l = 0; l < groups.length; l++) {
newItems.push({ json: { groupsUsername: groups[l].map(a => a.username), groupsEmail: groups[l].map(b => b.email) } });
}
return newItems;Explanation: This code randomizes users, groups them into threes, and ensures no group ends with a single member by adjusting previous groups if needed.
Outcome: Function node outputs grouped users for messaging and calendar invites.
Common mistake: Editing the code incorrectly may cause runtime errors or unbalanced groups.
Step 5: Announce Groups in Mattermost
Add a new Mattermost node to announce groups.
- Set the message to
=☀️ {{$node["Divide into groups"].json["groupsUsername"].join(', ')}} - Set Channel ID to your coffee chat channel.
- Select your Mattermost credentials.
Outcome: Posted grouped usernames in the chat channel for all to see.
Common mistake: Forgetting the equals (=) sign before the expression leads to the string not evaluating.
Step 6: Send Google Calendar Invites
Add a Google Calendar node to send calendar invites with Meet links.
- Set Calendar to your primary or chosen calendar.
- Configure start and end times (use ISO date format or expressions for dynamic dates).
- Under Additional Fields, set Summary to “n8n coffee catchup”.
- Set Attendees to emails from grouped users:
= {{$node["Divide into groups"].json["groupsEmail"].join(",")}} - Enable conference data for Google Meet links.
- Authenticate with your Google Calendar OAuth2 credentials.
Outcome: Each group receives an invite with conference details directly on their calendars.
Common mistake: Misconfigured dates or invalid email formats can cause invite failures.
5. Customizations ✏️
- Change Group Size: In the “Divide into groups” Function node, modify
ideal_group_sizeto any number that fits your team better (e.g., 4 or 2). - Adjust Meeting Time: Update the Google Calendar node’s start and end parameters to reflect your preferred coffee chat time.
- Personalize Messages: Edit the Mattermost “Greetings” and “Announce groups” nodes to add personalized emojis or motivational quotes.
- Multiple Channels: Duplicate the workflow’s Mattermost user fetch and group announcement nodes to run separate coffee chats for different departments.
- Add Reminder Notifications: Integrate another Mattermost node with a delayed trigger to remind users 10 minutes before the chat.
6. Troubleshooting 🔧
Problem: “No users found in the specified channel.”
Cause: Incorrect or missing Channel ID in the “Employees in coffee chat channel” node.
Solution: Double-check the Channel ID from Mattermost’s channel settings and update the node accordingly.
Problem: “Function node returns empty groups or runtime error.”
Cause: Errors in the JavaScript code or empty input data.
Solution: Verify the user fetch node is correctly retrieving users. Copy-paste the provided function code exactly without alterations.
Problem: “Google Calendar invite not sent or invalid email error.”
Cause: Emails are missing or formatted incorrectly in the group data.
Solution: Confirm user emails exist in Mattermost profiles and are fetched correctly. Check that the Function node maps emails properly as JSON.
7. Pre-Production Checklist ✅
- Verify Mattermost API credentials are active and permissions allow user reading and message posting.
- Confirm Google Calendar OAuth credentials have calendar write and event invite scopes.
- Test the Cron node trigger manually to ensure workflow initiation.
- Run the user fetch node separately to confirm user list accuracy.
- Preview the Function node output to verify groups are formed correctly.
- Send a test message in Mattermost channel from the workflow to validate posting permissions.
- Try sending a calendar invite with your own email for validation.
8. Deployment Guide
Once tested, activate the workflow by toggling the workflow’s active switch in n8n.
The workflow will now run on schedule every Monday at 10 AM, handling user grouping, messaging, and calendar invites without any manual input.
Monitor execution logs in n8n for any errors and review Mattermost channel posts and Google Calendar entries to ensure everything runs smoothly.
10. Conclusion
By following this workflow setup, you’ve automated Emily’s tedious task of organizing virtual coffee chats using Mattermost and Google Calendar, saving her around 2 hours every Monday. This automation ensures fair, randomized groups, timely notifications, and calendar events with conference links all handled hands-free.
Next, consider expanding this automation to include automated reminders, integration with Slack instead of Mattermost, or even recording feedback post-chat for continuous team improvement.
Happy automating your team’s coffee catchups!