メニュー

Rate this page:

Thanks for rating this page!

We are always striving to improve our documentation quality, and your feedback is valuable to us. How could this documentation serve you better?

Implement voicemail

Programmable Voice and Programmable SMS are offered as a developer preview for Wireless SIMs.

You’re able to receive voice calls with a Programmable Wireless SIM, and now you want to set up voicemail. In the next 5 minutes, you’ll learn how to implement voicemail in a classic Twilio style using TwiML. Your TwiML will be configured to record voice messages if the SIM-connected device doesn't answer the call in a pre-determined timeframe.

Note: Your device must be located within the United States, on the T-Mobile network, to use voice. Voice will not work when roaming on T-Mobile partner networks within the United States.

Create <Record> TwiML

  1. Open the TwiML section of the Console
  2. Enter “Take Message” in the Friendly Name input field
  3. Enter the following TwiML the TwiML input box
<?xml version="1.0" encoding="UTF-8"?>
<Response>
<Say>
	Please leave a message at the beep. 
	Press the star key when finished. 
</Say>
<Record
	maxLength="20"
	finishOnKey="*"
/>
</Response>
  1. Click Save
  2. Click the Copy button to the right of the URL input field
    1. You will paste this URL in the next step

Create Voicemail Action in Functions

  1. Visit Twilio Functions
  2. Click the Create a Function button
  3. Click the Blank template
  4. Click the Create button
  5. Enter VoicemailAction as Friendly Name
  6. Enter voicemail for the path
  7. Copy the contents of the Javascript below in the Code textbot
  8. Make note of the full URL of this Function
/**
 *  Voicemail Action URL
 * 
 *  This Function is used in as the action URL in a Dial. If the call isn't answered or the line is busy, 
 *  the call is forwarded to a specified Voicemal URL.
 */

exports.handler = function(context, event, callback) {
  // set-up the variables 
  // generate the TwiML to tell Twilio how to forward this call
  let twiml = new Twilio.twiml.VoiceResponse();

  if (event.DialCallStatus === "completed") {
    twiml.hangup();
  }
  else {
    twiml.redirect('<URL-TO-VOICEMAIL-TWIML>');
  }
  
  // return the TwiML
  callback(null, twiml);
};

Modify your Phone Number's existing Voice TwiML

  1. Open the TwiML section of the Console
  2. Select the TwiML you use to route calls made to a Twilio Phone Number to your SIM connected device
    1. Take a look at the Make and receive phone calls guide if you need help completing this step
  3. Update your TwiML to match the changes in bold
<?xml version="1.0" encoding="UTF-8"?>
<Response>
    <Dial ringTone="us" timeout="10" action="VOICEMAIL_ACTION_URL_HERE">
        <Sim>YOUR_SIM_SID_HERE</Sim>
    </Dial>
</Response>
  1. Enter the URL from the previous section in place of the VOICEMAIL_ACTION_URL_HERE placeholder.
  2. Click Save

Note: Setting ringTone="us" will default the destination's leg ring tone to US carrier default. Ignoring this step will invoke the message "The subscriber you have dialed..." if the mobile-terminated device is not connected to the T-Mobile US cellular network.

Make a phone call to your SIM

You’re all set! Make a phone call to your SIM card and wait 10 seconds for it to go to voicemail. Leave a message and continue reading to learn how to navigate your recording logs.

Navigate and listen to your voice recordings

You can navigate and listen to all your voicemails in the Recordings section of the Console or through the Recordings API.

Want to learn more about the <Record> verb?

Take a look at our in-depth documentation to learn about the <Record> verb.

Jon Davis Evan Cummack Michael Carpenter Glenn Lea
Rate this page:

ヘルプが必要ですか?

We all do sometimes; code is hard. Get help now from our support team, or lean on the wisdom of the crowd browsing the Twilio tag on Stack Overflow.