Skip to main content

Setting Up Voicemail

A popular and important use case is recording a voicemail from your callers when you are unable to speak with them. This guide will show how to do exactly that.

Creating an XML bin

In this guide we are going to see how to implement a voicemail using XML bins, which can be used to define the behavior of phone calls. To create an XML bin, go to the "LaML" section in your SignalWire Space, then click on "Bins".

A screenshot of the LaML page in a SignalWire Space. The Bins tab is selected.
To create a new XML bin, click the blue button in the LaML section of your SignalWire Space.

We are going to write the code for this XML bin. It will use the <Say> verb to play the voicemail prompt to a caller and <Record> to record a message. In the <Record> verb, we will also specify a max length of seconds for the recording and a key that when pressed will execute a new document of instructions. If you do not specify an action URL within the <Record> verb, the recording prompt will loop over and over.

Here is the code:

<?xml version="1.0" encoding="UTF-8"?>
<Response>
<Say>
Please leave a message with your name and number at the beep. Press the
pound key when finished.
</Say>
<Record action="https://<URL-To-Hangup-Bin>" maxLength="15" finishOnKey="#" />
</Response>

Copy the code above into your XML bin, then save it.

Take a moment to notice the action attribute for <Record>. We would like to play a message right after the recording ends, but adding a <Say> verb below <Record> will not wait for the recording to finish. The action attribute allows us to specify the URL of a different bin which should be executed right after the recording ends: we will use this to play a closing message and hang up the call with <Hangup>.

For this reason we also need another bin, which will be executed after the recording in the first one terminates. This second bin will play a short prompt advising the caller that they will be contacted and then it will hang up the call. Even though this bin is simple, it's very important to hang up to avoid looping calls after a recording!

<?xml version="1.0" encoding="UTF-8"?>
<Response>
<Say>Thank you for your message. A member of our team will contact you shortly. Goodbye!</Say>
<Hangup/>
</Response>

Save this new bin. Take note of its Request URL, and go back to the first bin to update the "action" URL in <Record> to point to the second bin!

How to Assign the Bin to a SignalWire Phone Number

If you are not familiar with webhooks, read our advanced guide to configuring webhooks for more information.

Click the Phone Numbers tab on your lefthand side nav within your SignalWire Space, and click the specific number you would like to set up call forwarding on. If you don't have a number yet, now is the time to buy one!

A screenshot of the Phone Numbers page in a SignalWire Space. In the edit pane of a phone number, under Voice and Fax Settings, the user has elected to accept incoming calls as Voice Calls and handle calls using LaML Webhooks. In the field labeled 'When a Call Comes In', the user should paste their bin URL.
To configure your number to handle incoming calls with an XML bin, set "Handle calls using" to "LaML Webhooks", then specify the URL of the XML bin.

Make sure that Accept Calls As is set to Voice Calls, Handle Calls Using is set to LaML Webhooks, and paste your Bin URL in as the value for When a Call Comes In. Click Save, and you're done! Inbound calls to this SignalWire number will execute our voicemail bin.

How to Access the Recordings

To access your recordings, click the "LaML" section on the left-hand side nav. Click the "Recordings" tab, and you will be able to view, listen, and download your recording files. You will also see the call ID and recording ID that you can use to access recordings via our API.

A screenshot of the LaML page of a SignalWire Space. The Recordings tab is selected, showing call recordings.
Access your recordings from the LaML tab.

Wrapping up

We have seen how to build a basic voicemail using XML bins. In particular, we showed how to chain two bins together: we set up our first bin to execute the second one after the recording finished.

If you need more flexibility, you can implement the same application using Node.js: take a look at how to set up a voicemail using Node.js.