Create Google Contacts from Google Voice Mail

Published in: Gmail - Google Contacts - Google Apps Script

Google Voice sends you an email notification where there’s a missed call or a voicemail for you. The email includes the caller’s name, the caller’s phone number and, in case of voicemails, the text transcript of the message. The message also includes a link to download the Google Voice MP3.

The Google Scripts scans all your Google Voice emails, parses the content uses regex and creates a new Google contact. The transcript of the voice message is set to the notes field of the new Google contact.

Link: Save Google Voice Messages to Google Drive

// Search Google Voicemail emails
function searchGoogleVoiceEmails() {

  var threads ="", 0, 100);

  for (var t = 0; t < threads.length; t++) {

    var response = extractVoicemail_(threads[t].getMessages()[0]);

    if (response) {


// Extract the caller's name, phone number and voice message transcription
function extractVoicemail_(msg) {

  var result = {
    "Message Date": msg.getDate(),
    "Message Subject": msg.getSubject(),
    "Message Body": msg.getPlainBody().replace(/<[^>]+>/g, "").replace(/\s+/g, " "),
    "Transcription": msg.getPlainBody()

  var trans = /transcript:(.*)?play message/i.exec(result["Message Body"]);

  if (trans) result.Transcription = trans[1];

  //Voicemail from: John Q Public (202) 123-456 at 6:08 PM

  var match = /(Missed Call|Voicemail) from:([*\+\s\w]+)([\d\-\s\(\)\+]*)? at [\d\:\s]+[ap]m/i.exec(result["Message Body"]);

  if (match) {
    result["Call Type"] = match[1];
    result["Contact Name"] = match[2].replace(/^+/, "");
    result["Contact Number"] = match[3].replace(/^+/, "");
  } else {
    return null;

  return result;

// Create a new Google contact from Voicemail
function createContact_(result) {

  var contacts = ContactsApp.getContactsByPhone(result["Contact Number"], ContactsApp.Field.WORK_PHONE);

  if (contacts.length > 0) {

    return "Contact Exists";

  } else {

    var contact = ContactsApp.createContact(result["Contact Name"], result["Contact Name"], result["Call Type"]);

    contact.addPhone(ContactsApp.Field.WORK_PHONE, result["Contact Number"]);

    return contact.getId();

📮  Subscribe to our Email Newsletter for Google tips and tutorials!
Published in: Gmail - Google Contacts - Google Apps Script

Looking for something? Find here!

Meet the Author

Web Geek, Google Developer Expert
Amit Agarwal

Amit Agarwal is a Google Developer Expert in Google Workspace and Google Apps Script. He holds an engineering degree in Computer Science (I.I.T.) and is the first professional blogger in India. He is the developer of Mail Merge for Gmail and Document Studio. Read more on Lifehacker and YourStory

Get in touch

Google Add-ons

Do more with your Gmail and GSuite account

We build bespoke solutions that use the capabilities and the features of Google Workspace for automating business processes and driving work productivity.

  1. Mail Merge with Attachments
    Send personalized email to your Google Contact with a Google Sheet and Gmail
  2. Save Emails and Attachments
    Download email messages and file attachments from Gmail to your Google Drive
  3. Google Forms Email Notifications
    Send email notifications to multiple people when a new Google Form is submitted
  4. Document Studio
    Create beautiful pixel perfect documents merging data from Google Sheets and Google Forms
  5. Creator Studio for Google Slides
    Turn your Google Slides presentations into animated GIFs and videos for uploading to YouTube