In addition to running GoogleFlows.com I am also the founder of FantasyBrawls - an online monster taming game complete with PvP and belt achievement system similar to badges in Pokemon. As such, I deal with my fair share of bug reports and support tickets. Regardless of why they are submitted, all users want two things. To know their issue has been heard and that it's getting fixed. The first part can be solved with a simple auto responder but if you want to level up your customer service keep on reading.
With the power of the mighty Google App Scripts and Google Workspace you can provide common resolutions to issues based on the description of the problem your users add on the ticket. You can even take a step further and schedule Google Meet sessions for real time troubleshooting.
Here's how I built a smart e-mail responder using nothing but Gmail and App Scripts.
Prerequisites:
A Gmail managed email account needs to be configured in your ticket management system, website, or bug reporting tool. I built my tool using Python's Flask framework which gives me a great deal more control than I would have using a CMS like WordPress.
Users can submit tickets directly from the forum. You will need something similar to get tickets out into your Gmail inbox. In addition to this, configure your subject line to include static text that never changes. This will act as the indicator for our automation to know which emails to grab.
Alternatively, you can just provide users with a contact form on your website and include a dropdown to allow them to choose a category their problem fits in. This allows you to better triage your responses and avoids contending with the typos that come in when you use free text boxes.
Create your script
Visit script.google.com using the same gmail that the emails will be routed to. Make sure you are on the right account before setting up the automation as the script will only execute within the confines of the account you configure it in.
Once you log in select the New Project button.
Next, give your project a name by clicking on the âUntitled Projectâ text box. From there, itâs time to write a little bit of code. You donât really need to be a software engineer here, but it does help a bit if you know what the code is doing. To help you get started, hereâs some boilerplate code that you can play with. Alternatively, you can ask Gemini to help you modify this code.
Overwrite the code in the box with the below.
function checkGmailSubjects() {
// Reuse label if it exists, otherwise create it once
const labelName = "FantasyBrawls-Auto";
let autoLabel = GmailApp.getUserLabelByName(labelName);
if (!autoLabel) autoLabel = GmailApp.createLabel(labelName);
// Only unread emails, and never reply to yourself
const threads = GmailApp.search('is:unread -from:me');
threads.forEach(thread => {
const messages = thread.getMessages();
messages.forEach(message => {
if (!message.isUnread()) return;
const subject = (message.getSubject() || "").toLowerCase();
const sender = message.getFrom();
let reply = null;
if (subject.includes("pvp")) {
reply = "Welcome to the Fantasy Brawls arena. PvP help is available at https://www.fantasybrawls.com/pvp/help";
} else if (subject.includes("support")) {
reply = "Your Fantasy Brawls support request has been received. A brawl master will assist you shortly.";
} else if (subject.includes("account")) {
reply = "Need help with your Fantasy Brawls account? Visit https://www.fantasybrawls.com/account or reply with more details.";
} else if (subject.includes("bug") || subject.includes("issue")) {
reply = "Thanks for reporting an issue. Our team will investigate and get back to you soon.";
}
if (reply) {
GmailApp.sendEmail(sender, "Re: " + message.getSubject(), reply);
message.markRead();
thread.addLabel(autoLabel);
}
});
});
}
What the code is doing
const threads = GmailApp.search('is:unread -from:me');
This line is telling Google to give you every email that did not come from me only. A small, but crucial component of this code is the -from:me piece. Without it, Gmail could end up auto replying to its own messages, creating an unholy infinite loop.
threads.forEach(thread => {
This part is grouping emails into âthreadsâ. It will loop through each new conversation that contains unread messages.
const subject = message.getSubject().toLowerCase();
Here, we capture the subject line. This is important because its where we decide which response to give the sender.
if (subject.includes("pvp")) { ... }
This is your routing logic. It functions very similar to rules in Outlook but with much greater control, and the ability to write to Google Sheets, if youâre bold enough. This is the area youâll want to modify to cater to your business needs.
Triggers and deployment
Once youâve modified the code to your liking, its time to save it to your Google Drive. Click the Click Save (or hit Cmd+S / Ctrl+S).
Once the project is save, click the Run button. You should now get a prompt asking you to authorize the script.
Click Review Permissions and allow the application to violate your right to privacyâŚjust kidding.
Once youâve granted the appropriate permissions, it's time to set your triggers.
To set a trigger, click the alarm clock icon on the left hand side of the screen.
If youâre building a help desk type automation, youâll want to set a Select type of time based trigger to Minutes Timer and the Select minute interval field to Every Minute.
Once you save your automation will be live. Head over to your Gmail and check your sent box. You should start to see messages from your automation if it finds messages with your target keywords in the subject.
Just be careful about doing in your production inbox. I ended up sending all sorts of messages to business contacts that were completely irrelevant to them. When testing, use very specific keywords, so you donât confuse your address book like I did.
Key Takeaways
Remember, your automation is only as good as your business processes. Keywords are, well, key here. Define the appropriate keywords and adjust them as your needs change.
AppScript + Gmail = HubSpot Replacement
Many of my colleagues and clients pay thousands of dollars a month for features that you can develop in App Script for free. Intelligent responders like this are premium tools that enable businesses to excel in customer service and reduce the strain on their help desk. And, if once you've mastered the ticket system, check out our tutorial on making a free PTO system with nothing but your Gmail, Google Forms, and a spreadsheet.
And, while youâre here, be sure to join our newsletter to be among the first to know about giveaways, new articles, and tools. Finally, if youâre on LinkedIn, letâs connect using the link below.