13

I recently got a new phone number, and I want people who contact me at my old number to be automatically informed of my new number. I've ported my old phone number to Google Voice and set up a prerecorded voicemail greeting that says "this isn't my number anymore, here is my new number...."

Now I would like to do the same thing for texts received at the old number. In other words, when people text me at the Google Voice number, I want them to receive an automated text reply that says "this isn't my number anymore, here is my new number...."

I tried following the instructions from this ZDNet article to set up a Gmail label filter that sends a canned response to all text messages coming from Google Voice.

Unfortunately, this didn't work because Gmail's auto-respond feature will NOT reply to the address in the From field, it instead responds to the Return-Path header. Thus the auto-reply was sent to the bounce catcher grandcentral.bounces.google.com, which is the mailed-by address instead of the necessary txt.voice.google.com address.

I have it set up to work with IFTTT which sends an auto-reply from IFTTT but I would love to use Google to do everything. Is that at all possible?

Is there a script that will auto-reply to the txt.voice.google.com?

2
  • Are you sure the "Send canned response" action on the filter doesn't work? It seems to work fine on my tests. Perhaps the filter needs to be on the Gmail account for the original number.
    – ale
    Oct 2 '14 at 2:36
  • What ifttt recipe did you use?
    – user81513
    Nov 16 '14 at 22:40
1

So what we're going to do is configure Google Voice to send an email to Gmail when it gets a text. When Gmail gets that email, based on matching filter selection rules, it will automatically reply with a canned response. Because Google Voice passes along the texting details in the address of the email, when Gmail's filter does its automatic reply, that reply will actually be texted to the the sender.

1

I had the same issue you're describing; it's because Canned Responses and Vacation Responders are sent to the return address found in the SMTP envelope (displayed as the Return-Path in the headers), rather than the 'from' value.

Luckily, I found a different tutorial: llyang's google voice auto-reply tutorial. This awesome little tutorial uses Google Apps Script to accomplish the task. It is super simple, and the entire process only takes about 5 minutes to get up and running, even if you have never used Google Apps Scripts before (I had not..). I have tested it out and it works! It's currently running on my google voice account. Give it a shot!

Below is a summary of llyang's tutorial, along with the script code (with some minor modifications) which can be pasted directly in to Google Apps Script. Feel free to go directly to the tutorial and check it out there instead.

Strategy:

  1. Set up your Google Voice account to forward message to your Gmail account (set up to get an email any time someone texts you.)

  2. In the Gmail account the GV texts get forwarded to, create a label called 'autoreply'.

  3. Now, in that same gmail account, create a filter that assigns all the incoming text message emails to the 'autoreply' label created in Step 2. (Example filter - match all emails with the subject "New text message from", or whatever it displays for you...)

  4. Create a script on Google Apps Script which circulates through all emails in the 'autoreply' label in your Gmail account, and responds to the unread ones (code below). (To do this: go to Google Apps Script (make sure you are logged in!). Click the "New Project" button to the left. An editor will open up with a skeleton function. Delete it, and paste in the code below...). About the script and how it works: the script circulates through unread emails in the 'autoreplay' label. It parses the 'from' data from the email header (the value which ends in the desired txt.voice.google.com, rather than the grandcentral.bounces.google.com one that the canned response sends to). When it sends the email reply, it will send it to that 'from' value (avoiding the problem that vacation auto-replies in Gmail experience...). After responding to the email, the script marks the email as read, that way it isn't caught the next time the script runs.. Important: Make sure script.google.com is logged in to the correct Google account - the one associated with the GMAIL account where the GV texts are being forwarded to.

  5. once you've saved the script, run the script once (you can use the little 'run' button on the editor) so you can grant any required permissions to the script. (You must grant it permissions to read and respond to your emails; if you run it manually, google apps script will automatically prompt you for this.)

  6. Create a trigger to make the new script run every minute. (To do this - go back to the main dashboard on Google Apps Script. Click the 3 dots which appear to the right for the row the project displays on. Select 'Trigger' from the drop-down menu. A new page appears; click 'Add Trigger' on bottom right of the page. A small screen will pop up which will allow you to select options for the trigger). There's various options for configuring your project trigger - you can make it run every minute continuously, you can make it run based on a calendar range (so if you're on vacation for example...) up to you.

If you ever want to turn off the auto-responses, just modify the project and delete the trigger.

Below is my own variation of llyang's code; it can be pasted directly in to the editor in Step 4 (just make sure to modify the variable 'blackList', to include your own numbers). This is based on his strategy, but with a few modifications. I've also added the ability to exclude (blacklist) certain numbers from receiving auto-replies - this is important, because many businesses/etc., send their own auto-replies to unexpected texts. You might want to exclude them, or you could end up in an endless loop of auto-replies. (Example - notifications from shipping services like Fedex - if you send an auto-response to their texts, you will get an auto-response back saying "invalid", you will respond to that, etc..)

If you find my code confusing, I'd encourage you to check out llyang's tutorial, to see if you find it more pleasing.

P.S. - If you wish to see console output (console.log lines) in Google Apps Script, you can run the script manually by pressing the little run button above the editor - the console output will appear beneath the editor.

/**
 * CODE TO PASTE INTO EDITOR IN STEP 4
 *
 *   you should modify the following 3 variables:
 *   (1) labelName (2) AUTOREPLYMSG, (3) blackList
 *
 * everything else can remain as it is.
 *
 */

/**
 *   ---> (1) labelName
 *
 * Name of the label you created in STEP 2
 * (if your label is nested, add "/" for each level of nesting -
 *  ex: 'gvtexts/autoreply'. If it's not nested, it's just
 *  whatever you named the label.)
 */
var labelName = "autoreply";

/**
 *  ---> (2) AUTOREPLYMSG
 *
 * The message you want to send in the auto-replies
 */
var AUTOREPLYMSG = "AUTO-REPLY: I'm on vacation. Talk to you later!";

/**
 *  ---> (3) blackList
 *
 * Any numbers you do NOT want auto-replies sent to
 *
 * Write numbers as they appear in the "From" header of the text message emails
 * Example:
 * A "From" header:
 *      "My Friend" <12345551234.14025555555.VNHql2FJD8@txt.voice.google.com>
 * The sender's number in that header is:
 *      14025555555
 * So if you want to exclude this sender from receiving autoreplies,
 * add "4025555555", or some substring of that, to this array
 */
var blackList = ["18005555555", "28777", "4025555555"];


               /** REMAINING CODE STAYS THE SAME **/

// hash maps to keep track if you've already replied to a sender, or if they're excluded from auto-replies
var repliedToMap = {};
var canAutoReplyToSenderMap = {};

function autoReplier() {

  // get GmailLabel object for the label set up in Step 2.
  var labelObj = GmailApp.getUserLabelByName(labelName);

  // get all email threads in the label
  var labelThreads = labelObj.getThreads();

  var numUnreadThreads = labelObj.getUnreadCount();

  var labelThread;
  var messages;
  var message;
  var fromStr;

  // iterate through the threads in the label until you've found all
  // the unread ones (the unread threads contain the new text messages)
  var numUnreadThreadsFound = 0;
  for (var gg = 0; gg < labelThreads.length; gg++) {

    if (numUnreadThreadsFound === numUnreadThreads) {
      // no more new text messages - you're done
      break;
    }

    // get next thread in label
    labelThread = labelThreads[gg];
    // check if any unread emails (new text messages) in thread
    if (labelThread.isUnread()) {
      numUnreadThreadsFound++;

      // get all email messages in the thread
      messages = labelThread.getMessages();
      for (var ii = 0; ii < messages.length; ii++) {

        message = messages[ii];
        if (message.isUnread()) {

          // get 'From' String from email header
          fromStr = message.getFrom();
          console.log("'From' header of email: " + fromStr);

          // get sender's number from the 'From' string
          var sender = getSenderNumber(fromStr);
          console.log("sender's phone number: " + sender);
          if (sender === null) {
            throw new Error("issue getting sender number");
          } else {

            // check if sender's number excluded from auto-replies (in blackList array)
            if(canAutoReplyToSender(sender)) {

              // sender not blacklisted. Check if already replied to them
              if (!(sender in repliedToMap)) {

                console.log("sending auto-reply to sender " + fromStr);
                MailApp.sendEmail(fromStr, "Auto Reply", AUTOREPLYMSG);

                /**
                 * IMPORTANT:: mark that you've replied to this sender,
                 * or you could end up sending them multiple replies
                 * (multiple threads can exist for a single sender,
                 * so you could encounter same sender in a later iteration)
                 */
                repliedToMap[sender] = true;
              }
            }

            // any remaining messages in thread are from the same number; skip them
            break;
          }
        }
      }

      // mark all msgs in thread as read, or will keep replying every time script runs
      labelThread.markRead();
    }
  }
}

/**
* Takes 'From' String of email header and returns sender's phone number.
* Example:
* String of 'From' header:
*    "(402) 555-5555 <12345551234.14025555555.VNH-l2FJD8@txt.voice.google.com>"
* returns: "14025555555"
*/
function getSenderNumber(fromHeader) {
  var fromRegex = /.*<\d+\.(\d+)\..+@txt.voice.google.com.*/;
  var senderInfo = fromHeader.match(fromRegex);
  if (senderInfo === null) {
    throw new Error("Couldn't extract sender's number "
      + " from 'from' string of email:\n"
      + fromHeader
      + "\n(Has header format changed?)");
  } else {
    return senderInfo[1]; // found sender's phone number
  }
}

/**
* checks if a sender can receive auto-replies (not blacklisted)
* hash result as number may be queried multiple times
*
* var sender <String> (the number you want to check, i.e. "18005555555")
* returns <Boolean>: true if not in blackList, false if in blackList
*/
function canAutoReplyToSender(sender) {
  if(!(sender in canAutoReplyToSenderMap)) {
    // haven't yet checked this number against blacklist entries 
    // check if any entries in blackList are substrings
    var canAutoReplyToSender = true;
    for (var jj = 0; jj < blackList.length; jj++) {
      if (sender.indexOf(blackList[jj]) > -1) {
        console.log("Sender " + sender + " black listed from receiving auto-replies.");
        canAutoReplyToSender = false;
        break;
      }
    }
    canAutoReplyToSenderMap[sender] = canAutoReplyToSender;
  }
  var canSend = canAutoReplyToSenderMap[sender];
  console.log("Can send auto-replies to " + sender + " ? " + canSend);
  return canSend;
}

Hope this helps. I have this running and it's working great for me.

-1

Try transferring the phone number

Contact your Phone Carrier I tried that but maybe it only works with[Verizon Wireless][1] so switch to Verizon if you didn’t already maybe they can help you :)

Kind Regards, Nico Slafter (The Twitter account is not mine)

-1

is there way to not have the auto reply run when our patients confirm with a "Y" without blocking all the numbers because that defeats point of auto reply

New contributor
Bruce Dohner is a new contributor to this site. Take care in asking for clarification, commenting, and answering. Check out our Code of Conduct.
1
  • As it’s currently written, your answer is unclear. Please edit to add additional details that will help others understand how this addresses the question asked. You can find more information on how to write good answers in the help center.
    – Community Bot
    yesterday

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.