Contact Sales

All fields are required

Create a Simple Voicemail Box Using LaML Bins | SignalWire
Developers

Create a Simple Voicemail Box Using LaML Bins

How to use LaML Bins to build your own voicemail box - No coding experience required.

What are LaML Bins?

LaML Bins, or XML bins, are a type of container that provide instructions for handling phone calls, SMS, or fax. They're made for simple logic with commands such as recording or text-to-speech. These commands are so easy to organize in a LaML bin that you do not need to be a developer in order to use them.

In this post, we'll go over how to route inbound calls to a number towards a SIP endpoint. If the call is not answered within a specified amount of time, it will be redirected to voicemail. All you need to get started with LaML bins are a SignalWire account and a purchased or verified phone number.

You can build out this project fully without having to set up any external servers. Follow the steps below to accept incoming calls to a SignalWire or verified number, route the call to your SIP endpoint, then allow the caller to leave a voicemail if the call to the endpoint is not answered.

Step 1: Register a SIP endpoint

If you already have your SIP endpoint, skip to step two. If you do not already have one you would like to use, create a new SIP endpoint with a username and password of your choice.

Take note of the SIP endpoint URL you create when you set your username, because you will need it later. It should look something like <username>@<sip-uri>.sip.signalwire.com.

Refer to our simple guides for registering your SIP endpoints to softphones if you do not already have a method for answering SIP calls on your end.

Step 2: Create the first LaML bin

Now we'll create the first of this project’s two LaML bins which will be responsible for recording the voicemail. Name this bin something like "John User Voicemail" to easily identify it as the voicemail box later. You can do this by navigating to the new LaML bin form.

Paste in the LaML code below that we’ve already written for you. You can edit the variables and the text-to-speech to suit your needs.

The text-to-speech is generated using the <Say> verb. The <Record> verb allows the user to leave a voicemail recording.

The variables for the <Record> verb are optional, but recommended. MaxLength is the maximum length of the recording. PlayBeep will play a tone as the recording is starting, which will prompt the caller to begin leaving their message. Lastly, finishOnKey will allow any digit or key to be pressed to end the recording.

Once the voicemail LaML bin has been configured and saved, use the copy icon next to the Request URL to copy it to the clipboard. We will need this information when creating the next LaML Bin.

Step 3: Create the second LaML bin

Next, create the second LaML bin, which is responsible for attempting to dial the SIP endpoint and redirecting the call to voicemail if it is not answered. Name it something like “Incoming calls to John User” or "John User" for a shorter version. Copy in the code below:

The <Dial> verb is used to route the call towards the SIP endpoint. This will call the SIP endpoint we created earlier with a nested <SIP> noun. Retrieve your SIP Endpoint URL that you noted in step 1 and paste it in <SIP>. Be sure to copy both the username and the URL in the format of John@your-sip-uri.sip.signalwire.com.

The timeout variable on the <Dial> verb is optional, but necessary for this project. This will control how long the call will attempt to ring the SIP extension. Each ring cycle is about 5 or 6 seconds, so the timeout can be adjusted based on how many rings are preferred before redirecting to voicemail.

When the dial timeout is reached, The <Redirect> verb will re-route the call towards the first LaML bin we created for the voicemail. That value should be the Request URL we copied in step 2 for John User Voicemail.

Your LaML bin should look like this:

After you save your data, copy this Request URL for John User.

Step 4: Purchase or verify a phone number

Lastly, we will set up the entry point with a phone number in your SignalWire Space. You can verify a personal phone number or purchase a new number at any time.

Navigate to the Phone Numbers tab, and select the number you would like to register. Edit the settings to change how the phone number will handle inbound calls under Voice and Fax Settings. Accept incoming calls as Voice Calls, and handle calls using a LaML webhook.

Paste the copied Request URL for the John User LaML bin under When a call comes in. Name the phone number something that can easily identify who the number belongs to.

Now callers should be able to call into that phone number, and be redirected to voicemail if the called party does not answer at the SIP Endpoint within a certain amount of time.

For the user to retrieve any voicemails, they can view the voicemail record under LaML recordings.

This post was inspired by a specific question asked by a customer about how to set up basic voicemail functionality. If you have any questions about voicemail, our Voice offerings, LaML bins, or what’s possible to build with SignalWire, you can stop by our Community Slack or our Forum at any time to connect with our team!

Related Articles