One use for the Deepgram API is to transcribe calls between a caller and an agent. When paired with Twilio, a cloud communication platform that lets developers integrate a number of communication technologies into their applications, Deepgram’s API can be used to streamline your workflow by providing bite-sized versions of call recordings.
In this guide, you’ll learn how to use Twilio Functions and Deepgram’s Summarization feature to send phone call summaries via SMS once a conversation has ended. Using Twilio, you will build a phone number that forwards callers to your agent and begins recording. When the call is complete, Deepgram will provide both a transcript and summary of the call. Finally, the transcript and summary will be sent to both the caller and agent via SMS.
If you need reference material or you’d rather not follow along with this guide, we provide a full version of the sample code after the tutorial.
Before you run the code, you’ll need to do a few things.
Before you can use Deepgram, you’ll need to create a Deepgram account. Signup is free and includes $200 in free credit and access to all of Deepgram’s features!
Before you start, you’ll need to follow the steps in the Make Your First API Request guide to obtain a Deepgram API key, and configure your environment if you are choosing to use a Deepgram SDK.
Before you can use Twilio, you’ll need to sign up for a Twilio account. Once signed up, make sure you have a phone number with SMS and Voice capabilities set up in your account.
To test your project, you’ll need access to two phones—one to make a call and one to receive a call.
To use Twilio, you will need to create a new service, add the Deepgram SDK as a dependency, and add the appropriate environment variables.
Create a new service, which can contain multiple Twilio Functions and assets related to a single project.
Inside your new service, add the Deepgram SDK as a dependency:
@deepgram/sdk. To get the latest version, omit the version number.Inside your new service, add your Deepgram API Key and your agent phone number as environment variables:
Locate the Environment Variables section.
Add the following variables:
Create a Twilio function that receives incoming call data and forwards it to your agent while recording it:
Rename the /welcome function to /inbound.
Replace the entire file with the following code:
When the call is completed, call data will be sent to /recordings, which you will create later in this guide.
Now that you have created a function to receive incoming calls, apply it to your Twilio number:
/inbound.
Now that your Twilio number is configured to record the phone call, you can use Deepgram to transcribe and summarize it.
When a call is received, use Deepgram to transcribe it:
Create a new Twilio function named /transcribe.
Replace the boilerplate code with the following code:
This code uses the CallSid to look up the call to find additional call information. Once done, the caller’s phone number will be available in a variable called caller, and the number they placed the call to will be available in a variable called twilioNumber.
Generate a transcription of the call using Deepgram’s Node.js SDK:
From Deepgram’s transcription, isolate the summary:
Now that you have a summary of the call, you can send it to both the caller and the agent.
Finally, you can send Deepgram’s summary via SMS:
Save both files again, and deploy all functions in your service.
To test your implementation, call your Twilio number, pick it up on your “agent device”, speak, and hang up. You should receive a summary message via SMS a few seconds later.
In case you need it for reference, we provide the full sample code used in this tutorial below: