Your First GroupMe-to-Email Notification Bot with Google Apps Script (GAS)

Your First GroupMe-to-Email Notification Bot with Google Apps Script (GAS)

Goal: To guide you through setting up a GroupMe bot using Google Apps Script (GAS) that acts as a monitor. This tutorial will focus on receiving a message from your group and immediately forwarding it to a specific email address.

Why Google Apps Script?

Google Apps Script is a fantastic platform for beginners because it’s:

  • Free: No need to pay for hosting.
  • Serverless: You don’t need to manage your own server.
  • JavaScript-based: Leverages a widely-used programming language.
  • Integrated with Google Services: It connects natively to Gmail, making sending emails incredibly easy.

Prerequisites:


Step 1: Creating Your Google Apps Script Web App

First, we need to create a script that GroupMe can talk to. This script will act as our “Callback URL.”

  1. Go to Google Apps Script: Visit script.google.com and click on “+ New project.”

  2. Rename Your Project:

    • Click on “Untitled project” in the top left corner.
    • Rename it something descriptive, like “GroupMe Email Notifier.”
  3. Understand doPost(e):
    Every time GroupMe sends data to your Web App, it uses a POST request. Google Apps Script has a special function, doPost(e), that automatically runs when it receives such a request. The e parameter contains all the information about the incoming message.

  4. Understanding the return Statement:
    Even though we are sending an email, we still need to tell GroupMe we received the data.

    • return ContentService.createTextOutput("OK");
      This sends back an HTTP 200 OK status code. This tells GroupMe: “Yes, I received your message.” If you don’t do this, GroupMe might think your bot is broken and stop sending updates.

Step 2: The Code (Parsing and Emailing)

We will now write the logic to parse the incoming JSON message and trigger an email via Gmail.

  1. Delete any code currently in the editor (function myFunction...).
  2. Paste the following code:
// CONFIGURATION: Enter your email address here
const RECIPIENT_EMAIL = "your-email@example.com";

function doPost(e) {
  try {
    // 1. Parse the incoming message data from GroupMe
    var messageData = JSON.parse(e.postData.contents);
    Logger.log("Received message: " + JSON.stringify(messageData, null, 2));

    // 2. Extract key information
    var senderName = messageData.name;
    var messageText = messageData.text;
    var senderType = messageData.sender_type; // "user" or "bot"
    var groupName = "GroupMe Group"; // You can hardcode this or fetch it if needed

    // 3. Logic: Filter out bot messages
    // We usually don't want emails when other bots (or this bot) post messages.
    if (senderType === "bot") {
      Logger.log("Ignoring message from bot.");
      return ContentService.createTextOutput("Ignored bot message.");
    }

    // 4. Construct the Email
    var subject = "New GroupMe Message from " + senderName;
    var body = "Sender: " + senderName + "\n" +
               "Message: " + messageText + "\n\n" +
               "--------------------------------\n" +
               "Sent via Google Apps Script Webhook.";

    // 5. Send the Email using GmailApp
    if (messageText) { // Only send if there is actual text (ignores image-only posts unless modified)
       GmailApp.sendEmail(RECIPIENT_EMAIL, subject, body);
       Logger.log("Email sent to " + RECIPIENT_EMAIL);
    }

    // 6. Return a 200 OK to GroupMe
    return ContentService.createTextOutput("Message processed and email sent.");

  } catch (error) {
    // Log error for debugging
    Logger.log("Error processing message: " + error.toString());
    
    // Even if we fail to send email, we return a success to GroupMe so they don't retry endlessly
    return ContentService.createTextOutput("Error processing request").setStatusCode(200);
  }
}

IMPORTANT: Change const RECIPIENT_EMAIL at the very top to your actual email address!


Step 3: Deploying Your Google Apps Script as a Web App

Now we need to make this script publicly accessible so GroupMe can send requests to it.

  1. Save Your Script: Click the floppy disk icon (Save project).

  2. Create a New Deployment:

    • Click the “Deploy” button (usually blue) in the top right corner.
    • Select “New deployment.”
  3. Configure the Deployment:

    • Type: Click the gear icon next to “Select type” and choose “Web app.”
    • Description: “GroupMe Emailer.”
    • Execute as: Choose “Me” (your Google account). This is vital because it uses your Gmail to send the message.
    • Who has access: Change this to “Anyone.” This allows GroupMe’s servers to reach your script without needing a Google password.
    • Click “Deploy.”
  4. Authorize the Script:

    • Click “Authorize.”
    • Choose your Google account.
    • Safety Screen: You will see a “Google hasn’t verified this app” screen. Click “Advanced,” then “Go to [Your Project Name] (unsafe).”
    • Permissions: You will see that the script wants permission to Send email as you. Click “Allow.”
  5. Copy Your Web App URL:

    • Copy the URL generated (starts with https://script.google.com/macros/s/...). This is your Callback URL.

Step 4: Configuring Your Bot in GroupMe

Let’s tell your GroupMe bot where to send the data.

  1. Go to GroupMe Developers: Visit dev.groupme.com.

  2. Edit (or Create) Your Bot:

    • If you haven’t created one, click Create Bot, select your group, and give it a name.
    • If you already have one, click the bot name.
  3. Update the Callback URL:

    • Find the “Callback URL” field.
    • Paste the Web App URL you copied from Google Apps Script into this field.
  4. Save Changes: Click “Submit” or “Save.”


Step 5: Testing Your Email Bot!

It’s time to see it in action!

  1. Send a Message: Go to your GroupMe group (on your phone or desktop) and send a message: “Testing email bot.”

  2. Check Your Inbox: Go to the email inbox you defined in the script.

    • Note: It might take 5-10 seconds.
    • Check Spam: Since the email is coming from yourself to yourself via a script, Google sometimes marks it as spam initially.
  3. Check Your GAS Logs (If it doesn’t work):

    • Go back to your Google Apps Script project.
    • Click on “Executions” in the left-hand menu.
    • Look for Logger.log entries to see if the script ran and if it hit the GmailApp.sendEmail line.

Troubleshooting Common Issues

  • No Email Received:
    • Did you Authorize the script? If you changed code and redeployed, you might need to re-authorize.
    • Is the email in your Sent folder? Since you are “executing as Me,” the email will appear in your Sent folder.
    • Is sender_type “bot”? The script is designed to ignore other bots. Ensure you are sending the message as a human user.
  • “Script function not found” or 404 Error:
    • Ensure you deployed as Web App.
    • Ensure “Who has access” is set to Anyone.
  • Permissions Error:
    • If you see permission errors in the Executions tab, try deleting the deployment and creating a fresh new one to force the authorization prompt again.

Mastered This?

Check Out Advanced: Adding Gemini to GroupMe using a GroupMe Bot, GAS, and the GroupMe API

If you have any suggestions or edits, please reply at

And if you found this helpful, a :+1: would be much appreciated!

2 Likes