Building a Google Chatbot for Workspace Reminders

Zeeshan Ahmad
4 min readSep 5, 2023

--

Google Chatbot, Workspace Reminders
Google Chatbot for Workspace Reminders

Introduction: The Future of Workspace Reminders 🚀

In today’s fast-paced digital world, managing time and staying on top of tasks is paramount. Timely reminders in workspace environments aren’t just a luxury; they’re essential. They ensure we don’t drop the ball on important tasks, attend meetings on time, and remember our commitments. Enter the world of chatbots, which offer automated, efficient, and interactive ways to send and manage reminders.

Why Google Chatbot Scheduler: Yoga Reminder? 🤔

As we transitioned to remote work, our team found a recurring issue: remembering our collaborative yoga sessions! Traditional reminders were easily overlooked amidst the sea of notifications. What we needed was an engaging, interactive way to send, receive, and act on these reminders. Thus, the idea of the Google Chatbot Scheduler was born, specifically tailored for our yoga sessions.

Setting the Stage: What You Will Need 🛠️

To build this bot, arm yourself with:

  • An active Google Workspace account.
  • Familiarity with Google App Scripts (GAS).
  • Basic understanding of chatbot mechanics.
  • A sprinkle of enthusiasm!

Diving Deep: Understanding the Architecture 🏗️

Our bot follows a modular architecture, ensuring clarity and maintainability. At its core, it has configurations, chat interactions, a voting system, email notifications, and a scheduler.

Let’s Code: Building the Bot, Step-by-Step 🖥️

Configurations First:

Set up essential configurations. Define thresholds, chat space details, and email templates in settings.gs.

// settings.gs
var VOTE_THRESHOLD = 10;
var GOOGLE_CHAT_SPACE = "YOUR_GOOGLE_CHAT_SPACE_URL";
var GOOGLE_CHAT_THREAD = "YOUR_GOOGLE_CHAT_THREAD_ID";

Chat Interactions:

The bot needs to communicate. Use chatService.gs to handle chat interactions.

// chatService.gs

var GOOGLE_CHAT_WEBHOOK_URL = https://webhook.site/#!/732d3d88-3483-4b27-b2b4-328e986f67fe // Replace with your Google Chat Webhook URL

/**
* Send a reminder message to a specific Google Chat space.
*/
function sendReminderToChatSpace() {
var payload = {
"text": "Who is going to yoga tomorrow? Click on 👍 for 'Yes' and 👎 for 'No'."
};

var options = {
"method": "post",
"contentType": "application/json",
"payload": JSON.stringify(payload)
};

UrlFetchApp.fetch(GOOGLE_CHAT_WEBHOOK_URL, options);
}
Chat Interactions

Voting Mechanism:

Gather opinions effortlessly. The votingService.gs facilitates this.

// votingService.gs

var SPREADSHEET_ID = "YOUR_SPREADSHEET_ID";
var SHEET_NAME = "Votes";

/**
* Collect and return the number of "Yes" votes.
*/
function collectVotes() {
var sheet = SpreadsheetApp.openById(SPREADSHEET_ID).getSheetByName(SHEET_NAME);
var votesRange = sheet.getRange("A:A"); // Assuming votes are stored in column A
var votes = votesRange.getValues();

var yesVotesCount = 0;
for (var i = 0; i < votes.length; i++) {
if (votes[i][0] === "Yes") {
yesVotesCount++;
}
}

return yesVotesCount;
}
Voting Mechanism
Mechanism

Email Notifications:

Keep everyone informed. Use emailService.gs to send emails based on votes.

// emailService.gs

/**
* Send a positive email based on the voting results.
*/
function sendPositiveEmail() {
var emailAddress = "recipient@example.com"; // Replace with the recipient's email address
var subject = "Yoga Session Reminder Results";
var message = "Good news! More than the threshold number of people have confirmed attendance for the yoga session tomorrow. See you there!";

GmailApp.sendEmail(emailAddress, subject, message);
}
Email Notification

Scheduling Magic: Automating the Reminders 🕰️

Automation is key! Use Google App Scripts’ built-in triggers to schedule reminders. The scheduledReminders.gs handles this.

// scheduledReminders.gs

/**
* Schedule a daily reminder to be sent at a specific time.
*/
function scheduleReminders() {
// Clear any existing triggers
var triggers = ScriptApp.getProjectTriggers();
for (var i = 0; i < triggers.length; i++) {
ScriptApp.deleteTrigger(triggers[i]);
}

// Set a new daily trigger for the reminder function
ScriptApp.newTrigger('sendReminderToChatSpace')
.timeBased()
.atHour(10) // Example: 10 AM. Adjust the hour as needed.
.everyDays(1) // Daily trigger
.create();
}

/**
* This function will be triggered to send the reminder to Google Chat space.
*/
function sendReminderToChatSpace() {
// Logic to send a reminder to a specific Google Chat space and thread
// Utilize Google Chat API or other methods here
// ...
}

Stuck? Troubleshooting Common Issues 🩺

  • Reminder Not Sending? Check Google Chat API permissions.
  • Voting Issues? Ensure countVotes() integrates well with Google Chat.
  • Emails Missing? Confirm Gmail API is enabled with required permissions.

Taking It Further: Enhancements & Future Scope 🌟

Our bot is ever-evolving. Future enhancements include:

  • An Analytics Dashboard.
  • Calendar Integration.
  • User Profiles with rewards!

Want to contribute? Check out our GitHub repository and make this bot even better!

Conclusion: Wrapping It Up & Your Next Steps 🚀

The Google Chatbot Scheduler: Yoga Reminder is more than just a bot; it’s a testament to how automation can simplify our lives. As you embark on building your version, remember the essence lies in its interactivity and efficiency. Check out the complete project on GitHub and start automating your reminders!

Additional Resources & Further Reading 📚

FriendTech Notifier Bot (FTNB)

Threads Scraper: A Comprehensive Guide

Automating ChatGPT with Python and Sele

nium

--

--

Zeeshan Ahmad

AI/ML/DL enthusiast | Python/Web Automation expert | Passionate Problem Solver