Full disclosure: I never check my voicemail. I assume if what you need is pressing enough youâll call back or send me a text message. But maybe there are times Iâd want to know who called and what they needed. In that case, I need to receive that information in one of the channels I normally check, like email.
So I built a workflow that allows people to call and leave me a message that will automatically be transcribed and emailed to me. This tutorial will show you how to build the same workflow using Twilio Studio, Pipedream, and Deepgram.
How It Works
First, weâll create a Twilio Studio Flow that will handle all calls to a Twilio Voice number. That Flow will ask the caller to leave a message, then send the recording to Deepgram for transcription. Twilio Studio is a low-code workflow builder that allows you to build workflows that connect to Twilioâs APIs and other third-party APIs.
Once the transcription is complete, Twilio will send a webhook to a Pipedream workflow with information about the transcription. Pipedream is a low-code integration platform that allows you to build workflows that connect to hundreds of third-party APIs.
Pipedream will make a request to the Twilio API to get the actual transcription, format it, and send it to my email address. Then, we can use the transcription to respond to the caller.
Prerequisites
Before we get started, make sure you have the following:
- A Twilio account. Sign up for a free account here.
- A Twilio phone number. You can get one here.
- A Pipedream account. Sign up for a free account here.
Creating a Twilio Studio Flow
First, letâs create a Twilio Studio Flow that will trigger when a call is received. This Flow will ask the caller to leave a message, then send the recording to Deepgram for transcription. The name of your Flow doesnât matter. I named mine âTranscribe Voicemail.â
In the next prompt, choose the âStart from scratchâ option and press the âNextâ button. This will create a blank Flow.
Play a Message when a Call is Received
Now that we have a new Flow, letâs add a widget to prompt the caller to leave a message. In the widget library, click and drag the âSay/Playâ widget into the Flow. Be sure to connect the âIncoming Callâ trigger to the new widget.
Next click on the âsay_play_1â widget in your Flow and change the âText to Sayâ field to âHello. Leave a message please.â Then click the âSaveâ button. At this point, your Flow should look like this:
Record the Callers Message
Now that weâve prompted the caller to leave a message, letâs add a widget to record the callerâs message. In the widget library, click and drag the âRecord Voicemailâ widget into the Flow. Be sure to connect the âSay/Playâ widgetâs âAudio Completeâ output to the new widget.
Next click on the ârecord_voicemail_1â widget in your Flow and change the âTrimâ field to âTrim silenceâ and the âPlay Beepâ field to âTrueâ. This will remove silence at the beginning and end of the recording and provide a beep prompt for the caller to begin speaking. Click the âSaveâ button. At this point, your Flow should look like this:
Configuring Your Twilio Phone Number
The Flow now has everything it needs to record a callerâs message. But we need to configure our Twilio phone number to use this Flow. In the Twilio console, click on the âPhone Numbersâ link in the left sidebar. Then click on the phone number you want to use for this Flow.
In the âVoice & Faxâ section, click on the âA Call Comes Inâ dropdown and choose âStudio Flowâ. Then choose your newly created Flow and click the âSaveâ button.
Creating a Pipedream Workflow
Before we can configure the Deepgram add-on for Twilio, we need to create a Pipedream workflow that will handle the webhook from Twilio. Create a new workflow by clicking on the âNew Workflowâ button in the top right corner of the Pipedream dashboard.
Triggering the Workflow
Our trigger will be a webhook from Twilio, so choose âHTTP / Webhookâ from the list of triggers. Then choose âHTTP Requests with a Bodyâ from the list of options.
Finally, press the âSave and continueâ button. This will add the trigger to the workflow and display a webhook URL. Copy this URL and weâll return to our Twilio Console to enable the Deepgram add-on.
Enabling the Deepgram Addon for Twilio
Back in the Twilio Console, click on the âAdd-onsâ link in the left sidebar. There are two Deepgram transcription add-ons; âDeepgram Base Transcriptionâ and âDeepgram Enhanced Transcriptionâ. Letâs enable the âDeepgram Enhanced Transcriptionâ add-on by clicking on it and pressing the âInstallâ button.
On the âConfigureâ tab, make the following configurations:
- Ensure the âUnique Nameâ is
deepgram_enhanced_transcription
- Check each option under âUse Inâ
- Paste the webhook URL from Pipedream into the âCallback URLâ field
- Choose âPOSTâ from the âCallback Request Methodâ dropdown
Finally, click the âSaveâ button. Your configuration should look like this:
Testing the Webhook Trigger
We canât continue building out our Pipedream workflow until we know what type of data weâll receive from Twilio. Place a call to your Twilio phone number and leave a message. Then open the Pipedream workflow. You should see a new event in the âResultsâ section of the webhook trigger. Click on the event to view the data.
Parsing the Webhook Payload
The event
property of the webhook has an AddOns
property that contains metadata about any Twilio Add-Ons that were executed, including our deepgram_enhanced_transcription
add-on. However, that property is a string containing JSON data. Weâll need to parse that string into a JavaScript object so we can access it.
Add a new step to the workflow and choose âNodeâ from the list of actions. Then choose the âRun Node codeâ option. This will add a new step to the workflow and display a code editor. Replace the code in the editor with the following:
export default defineComponent({
async run({ steps, $ }) {
const addOnData = JSON.parse(steps.trigger.event.AddOns);
return addOnData;
},
})
This code will parse the AddOns
property of the webhook payload and return the resulting JavaScript object. Click the âTestâ button to save the step. At this point, your workflow should look like this:
Requesting the Transcription Data
With our webhook payload parsed into a JavaScript object, we can see that Twilio doesnât send back our transcription with the webhook. Instead, it provides a URL where we can request the transcription data. Letâs add a new step to our workflow that will request the transcription data from Twilio.
Click on the âAdd a stepâ button and choose âSend any HTTP Requestâ from the list of actions. Then choose âMake an HTTP Requestâ from the list of options. This will add a new step to the workflow and display a form for configuring the HTTP request.
This will be a âGETâ request. The URL will come from the previous step so weâll need to add some Pipedream magic to get data from a previous step. In the request URL field, enter {{steps.node.$return_value.results.deepgram_enhanced_transcription.payload[0].url}}
. This will use the Pipedream $return_value
magic variable to get the return value of the previous step and then access the url
property of the deepgram_enhanced_transcription
add-on.
Requests to the Twilio API must be authenticated. In the âAuthenticationâ section, choose âBasic Authâ from the âAuthentication Typeâ dropdown. Then enter your Twilio Account SID in the âUsernameâ field and Auth Token in the âPasswordâ field.
Then press the âTestâ button to save the step. After that request returns, you should see the Deepgram transcription results in the âResultsâ section of the step.
Sending the Transcript as an Email
Now that we have the transcript, we can email ourselves a copy. Add a new step to the workflow and choose âSend Emailâ from the list of actions. This will add a new step to the workflow and display a form for configuring the email.
You can choose whatever youâd like as the âSubjectâ. I chose Call Transcript - {{steps.trigger.context.ts}}
. This will use the Pipedream context
magic variable to get the timestamp of the call.
The âBodyâ of the email will be the transcript. Enter {{steps.custom_request.$return_value.results.channels[0].alternatives[0].transcript}}
in the âBodyâ field. This will use the Pipedream $return_value
magic variable to get the return value of the previous step and then access the transcript
property.
Press the âTestâ button to save the step. You should receive an email to the email address associated with your Pipedream account with the transcript included.
Conclusion
In this tutorial, we built a workflow that will transcribe voicemails and email them to us. We used Twilio to receive the voicemail, Deepgram to transcribe it, and Pipedream to send the email. Itâs always fun mashing up APIs to create new functionality. I hope you enjoyed this tutorial and found it useful.