How to Integrate Voice Intelligence with Your CRM

October 29, 2024
Written by
Reviewed by
Paul Kamp
Twilion

How to integrate Voice Intelligence with CRM

Think of customer interactions as an untapped treasure trove of data. Twilio Voice Intelligence turns these conversations into actionable insights using AI and machine learning. It automates feedback with real-time transcriptions, sentiment analysis, and keyword spotting, helping businesses understand customer sentiment and behavior. This means you can spot challenges, predict key metrics like NPS and churn, and streamline operations. Plus, it makes compliance and quality assurance easier and integrates smoothly with your existing systems, like CRMs.

For more details, please visit the Twilio Voice Intelligence page.

The benefits of integrating Voice Intelligence with your CRM

Imagine if your sales team could breeze through call summaries effortlessly, like having a reliable assistant who captures all the important details for you. These summaries highlight key points and action items from each conversation, saving time and ensuring nothing important gets overlooked during follow-ups

AI-driven automation further enhances this efficiency by extracting essential CRM data—like phone numbers, emails, competitive insights and follow-up commitments—directly from Voice Intelligence transcripts. This boosts data accuracy and makes lead management a breeze, so your team can focus on meaningful interactions.

When integrated with CRMs like HubSpot or Salesforce, Voice Intelligence data enriches lead profiles with crucial call insights. This helps your team understand customer needs better and personalize their approach, boosting productivity and enhancing customer interactions. Automated data entry means more time for engaging with leads and crafting tailored messages that resonate.

In this blog post, we explore how integrating Twilio Voice Intelligence with your CRM (such as HubSpot) can significantly boost your efficiency. Imagine a real estate company using Voice Intelligence: as soon as a call comes in, Voice Intelligence transcribes the conversation and extracts all the important details. The CRM is then automatically updated with key information—like the caller’s number, the reason for the call, and any specific needs. No manual entry required! This means their realtors can jump in immediately, fully informed and ready to assist. With everything automatically recorded and up-to-date, they're always a step ahead, saving time and ensuring nothing slips through the cracks.

While this blog focuses on a CRM integration with HubSpot, it's worth noting that Voice Intelligence can seamlessly integrate with any existing system. Whether it's your current contact center solution or Twilio Flex with the Voice Intelligence plug-in, you can leverage these capabilities across various platforms to enhance your operations.

The code for this project can also be found on GitHub.

Call handling and data integration workflow

Ready to set up your Voice Intelligence integration? It's simpler than you might think. We'll walk you through the steps to seamlessly integrate voice data into your existing systems. Using Twilio and HubSpot's powerful APIs and user-friendly interfaces, you can easily decode Voice Intelligence and sync it with your CRM. Let's get started!

Call flow when integrating a CRM and Voice Intelligence
  1. The customer calls the agent on the Twilio phone number.
  2. The Studio Flow is activated, and the customer is greeted by an agent. The agent informs the customer that the call is being recorded. The agent then asks for the customer's name, and asks if they would like to leave a message with their desired location and other details. After gathering all the necessary information, the agent ends the call.
  3. Voice Intelligence receives the call recording and generates the transcript of the call, which can also be viewed in the Twilio Console UI Transcripts Viewer. Voice Intelligence also applies the Conversation Summary and Entity Recognition language operators.
Voice Intelligence transcript viewer
  1. Voice Intelligence sends a webhook event to indicate that a transcript is complete, the Twilio function runs and extracts the relevant CRM data fields.
  2. Once all the fields are extracted, Twilio updates the CRM with a new lead.
Example HubSpot contacts

Prerequisites

You will need:

Step 1: Configure HubSpot

  • Login to your HubSpot account.
  • Create a Private App in HubSpot
  • Make a note of the Access token for your private app we will use it in the next step

Step 2: Create a Twilio Function

Twilio Functions is a serverless environment that empowers developers to quickly and easily create production-grade, event-driven Twilio applications that scale with their businesses. Twilio Functions provides a complete runtime environment for executing your Node.js scripts.

To create a function, go to the Twilio Console:

  1. Create a new Function Service, call it voiceintelligence (or anything you like).
  2. Add a new function and give it a name, for example, /transcribe. This function will be used to create a transcript after call recording)
exports.handler = async function(context, event, callback) {
 const client = context.getTwilioClient();
 console.log("Function triggered");
 const { SERVICE_SID } = context;
 const { RecordingSid, callerPhoneNumber, agentPhoneNumber } = event;
 // Log the entire event object to inspect its structure
 console.log("Event Object:", JSON.stringify(event, null, 2));
 if (!RecordingSid) {
   return callback('RecordingSid is missing from the event.');
 }
 try {
   console.log("RecordingSid:", RecordingSid);
   const channelDetails = {
     "media_properties": { "source_sid": RecordingSid },
     "participants": [
       {
         "user_id": agentPhoneNumber,
         "channel_participant": 2,
         "full_name": "Abigail Meyer",
         "email": agentPhoneNumber,
         "full_name": agentPhoneNumber,
         "image_url": "https://images.unsplash.com/photo-1438761681033-6461ffad8d80",
         "role": "Agent"
       },
       {
         "user_id": callerPhoneNumber,
         "channel_participant": 1,
         "email": callerPhoneNumber,
         "full_name": callerPhoneNumber,
         "role": "Customer"
       }
     ]
   };
   console.log("Caller Phone Number:", callerPhoneNumber);
   console.log("Agent Phone Number:", agentPhoneNumber);
   console.log("Channel Details:", JSON.stringify(channelDetails, null, 2));
   const transcriptResponse = await client.intelligence.v2.transcripts.create({
     channel: channelDetails,
     serviceSid: SERVICE_SID,
   });
   console.log("Transcript SID:", transcriptResponse.sid);
   return callback(null, transcriptResponse.sid);
 } catch (error) {
   console.error('Error creating Transcript:', error.message);
   return callback(error);
 }
};

In the above function, please note that if it's an inbound call then the agent is in as channel participant = 2 and if it’s an outbound call then the agent is channel participant = 1. More details on specifying participants info is here.

  1. Create another function /voiceintelligence. This function will be used to update HubSpot.
const axios = require('axios');
exports.handler = async function(context, event, callback) {
 const twilioClient = context.getTwilioClient();
 const hubspotApiKey = context.HUBSPOT_TOKEN;
 const hubspotBaseUrl = 'https://api.hubapi.com';
 const transactionSid = event.transcript_sid;
 if (!transactionSid) {
   return callback('TransactionSid is missing from the event.');
 }
 try {
   const operatorResults = await getOperatorResults(twilioClient, transactionSid);
   const transcriptResponse = await getTranscriptResponse(twilioClient, transactionSid);
   const phoneNumber = extractPhoneNumber(transcriptResponse);
   const { callDate, callTime } = extractCallDateTime(transcriptResponse);
   const contactData = extractContactData(operatorResults, phoneNumber, callDate, callTime);
   const hubspotResponse = await createHubSpotContact(contactData, hubspotApiKey, hubspotBaseUrl);
   console.log(hubspotResponse);
   callback(null, `HubSpot contact created: ${hubspotResponse}`);
 } catch (error) {
   console.error('Error creating HubSpot contact:', error);
   callback(error);
 }
};
async function getOperatorResults(client, sid) {
 try {
   const operatorResults = await client.intelligence.v2
     .transcripts(sid)
     .operatorResults
     .list({ limit: 20 });
   let person = null;
   let location = null;
   let summary = null;
   const entityMap = {};
   for (const record of operatorResults) {
     if (record.name.toLowerCase() === 'entity recognition') {
       for (const utterance of record.utteranceResults) {
         for (const part of utterance.utterance_parts) {
           entityMap[part.label] = part.text;
         }
       }
       person = entityMap.Person;
       location = entityMap.Location;
     } else if (record.name.toLowerCase() === 'conversation summary') {
       summary = record.textGenerationResults.result;
     }
   }
   return {
     person,
     location,
     summary
   };
 } catch (error) {
   throw new Error(`Error fetching operator results: ${error.message}`);
 }
}
async function getTranscriptResponse(client, transcriptSid) {
 try {
   const transcriptResponse = await client.intelligence.v2
     .transcripts(transcriptSid)
     .fetch();
   return transcriptResponse;
 } catch (error) {
   throw new Error(`Error fetching transcript response: ${error.message}`);
 }
}
function extractPhoneNumber(transcriptResponse) {
 const phoneNumber = transcriptResponse.channel.participants.find(p => p.channel_participant === 1).media_participant_id;
 return phoneNumber;
}
function extractCallDateTime(transcriptResponse) {
 const dateCreated = transcriptResponse.dateCreated;
 let callDate = 'Unknown';
 let callTime = 'Unknown';
 try {
   const date = new Date(dateCreated);
   if (!isNaN(date.getTime())) {
     callDate = date.toISOString().split('T')[0]; // Convert to YYYY-MM-DD format
     callTime = date.toISOString().split('T')[1].split('.')[0]; // Extract time as HH:MM:SS
   } else {
     console.error('Invalid date format:', dateCreated);
   }
 } catch (error) {
   console.error('Error parsing date:', error);
 }
 return { callDate, callTime };
}
function extractContactData(operatorResults, phoneNumber, callDate, callTime) {
 console.log(operatorResults.summary);
 console.log(phoneNumber);
 const lead = 'New'; // Define the lead_status inside the function
 return {
   properties: {
     firstname: operatorResults.person || 'Unknown',
     summary: operatorResults.summary || 'No summary available',
     phone: phoneNumber || 'Unknown',
     location: operatorResults.location || 'Unknown',
     date: callDate,
     call_time: callTime,
     lead: lead
   }
 };
}
async function createHubSpotContact(contactData, apiKey, baseUrl) {
 const url = `${baseUrl}/crm/v3/objects/contacts`;
 const headers = {
   'Content-Type': 'application/json',
   'Authorization': `Bearer ${apiKey}`
 };
 const response = await axios.post(url, contactData, { headers });
 return response.data;
}
  1. Setup the following Environment variables:
VariableValue
HUBSPOT_TOKEN HubSpot Private App Token created in Step1 above
SERVICE_SID Voice Intelligence Service SID created in Step 4
We will create SERVICE_SID in Step 4 Configuring Voice Intelligence
  1. Take a note of your function url. We would need these later on in our setup. In this example, it will be something like https://voiceintelligence-xxxx.twil.io/voiceintelligence and https://voiceintelligence-xxxx.twil.io/transcribe
  2. Save and Deploy for your changes to take effect.

Step 3: IVR Setup

Twilio Studio is a straightforward-to-use tool that helps you create and manage communication workflows without needing to write much code. You can drag and drop widgets to build apps for voice calls, messages, and other communication needs. It's designed to make creating complex workflows, like order notifications, phone menus, surveys, and SMS chatbots, straightforward and intuitive. You can also build your own Interactive Voice Response (IVR) system by following the steps outlined in this tutorial.

Below is an example of a basic IVR that will produce call recordings which will be analyzed by Voice Intelligence in Step 4

To get started with Twilio Studio, follow these steps:

  1. Open Studio: In your Twilio Console, navigate to the Studio dashboard.
  2. Create a New Flow: Click on Create a flow. For more detailed guidance, refer to the Twilio Studio Documentation.
  3. An example flow is shown below. You can also get the json file ( voiceIntelligenceFlow.json) from this code repository and import it.
Example of a Studio Flow
  1. Please make sure that your call_recording widget is set to dual recording as shown below. It records each party of a 2-party call into separate channels.
Call recording Studio widget to add recording
  1. Paste the /transcribe function link created in Step 2 as the Recording Status Callback Method as highlighted above. The URL should be something like https://voiceintelligence-xxxx.twil.io/transcribe
  2. Save and Publish your flow.
  3. Setup Your Twilio Number: Go to the Phone Numbers section in your Twilio console, select the number you want to use, and configure it to run your Studio Flow when A Call Comes In. See example below.
Phone Number configuration to add Studio Flow

Step 4: Configure a Voice Intelligence Service

For this example, we'll use the Twilio Console UI to configure Voice Intelligence. However, you can also set it up using the Twilio REST API or even by the Twilio CLI if you prefer.

In the Twilio Console, navigate to Explore Products on the left hand menu. In this screen underneath the Programmable Communications section you’ll find Voice Intelligence.

Tip: To make life easy for future navigation you can pin this to your sidebar by clicking on the Pin to sidebar icon.
Pin Voice Intelligence on the sidebar

After pinning, go to Voice Intelligence and scroll down to the Getting Started Guide on the Overview page. Expand the dropdown for Create Service and click the View Services button. On the Services page, click the Create New Service button. Provide a Unique Name for your Service (using only letters, numbers, dashes, underscores, and periods). Optionally, add a Friendly Name and select one of the available languages from the dropdown list. I will leave the language set to the default English (United States), but you can choose the most appropriate language for your call participants.

In order to use the service you’ll need to accept the Twilio Predictive and Generative AI/ML Features Addendum by checking the box. You also have the option to:

  • Uncheck: Personally Identifiable Information (PII) redaction from both transcripts and recordings to ensure fields are not redacted because these will be sent to our CRM.
  • Uncheck: Auto Transcribe on your Twilio Call Recordings to ensure that the transcription is generated by the /transcribe function above.
  • Check: Enable Data Use option.
Voice Intelligence Service creation

Click Create to set up the service, and you'll be redirected to the Service configuration page. Copy the Voice Intelligence SERVICE_SID and paste it in Step 2 as an Environment Variable.

Set up Language operators

The first tab is the Language Operators tab. In this tab, you can use prebuilt operators or create custom ones based on your needs. Make sure to add them to the service that you wish to use by clicking the adjacent Add button next to each. For this example we’ll use the Entity Recognition, and Conversation Summary. You could also add custom language operators to capture relevant details specific to your use case, such as identifying key phrases or classifying transcripts based on predefined criteria.

Set up Webhooks

Copy and paste the /voiceintelligence Twilio Function URL as a webhook. This webhook will be executed as soon as the call transcription is available.

Voice Intelligence webhook setting

Step 5: Set up HubSpot

You must ensure that all the fields extracted in the /voiceintelligence function are present as columns in HubSpot. This example uses the following columns: Name, Lead, Date, Call Time, Phone Number, Location, and Summary. If you don't see these columns in HubSpot, you can just as easily create a property and add that to your HubSpot default view.

Step 6: Testing and Error Handling

Now that you have everything setup correctly, it’s time to make some calls into our IVR and start populating some test data into our CRM.

Error Handling

Verify Transcript Matches:

  • Check your transcripts to ensure that all values in your transcripts are correctly matched for Conversation Summary and Entity Recognition language operators.

Transcript Not Visible:

  • If your transcript is missing, confirm that a call recording exists in the call recording logs.

HubSpot CRM Update Issues:

  • If the transcript and Language Operator match are correct but the HubSpot CRM is not updated, check for webhook errors, as they likely indicate problems with executing your Twilio Function.
  • Troubleshoot and debug your Function for errors.

Conclusion

By integrating Voice Intelligence into your sales process, you simplify and enhance how your team handles call summaries and manage leads. This tool captures all the important details from conversations and enriches your CRM with accurate, valuable data. This not only saves time but also allows your team to focus on what truly matters—building strong, personalized relationships with customers. With Voice Intelligence, your sales process becomes more efficient and effective, leading to better outcomes and happier customers.

Interested to know more about Voice Intelligence? Check out our developer documentation, or see our tutorial on how to get started with Voice Intelligence and PostmanWe can’t wait to see what you build!


Ankita Tiwari is a Solutions Engineer at Twilio. She is always looking for new ways to improve the customer experience through digital communication

Yukti Ahuja is a Principal Solutions Engineer at Twilio. As an SE, she is a problem solver extraordinaire, blending technical expertise to bridge the gap between complex technology and practical solutions for customers.