Receiving calls
This guide walks you through answering inbound calls: you create a voice application that points at your server, route a number to it, and return OneML that greets the caller and offers a menu.
How inbound calls reach your server
A voice application holds the URLs on your server that Signals uses for a call. A number route points a number your project owns at that application. When someone dials the number:
- Signals finds the voice application the number is routed to.
- Signals requests the application's voice URL, sending parameters such as
CallSid,FromandTo. See Webhooks for the full set. - Your server returns a OneML document, and Signals runs it on the call.
One application can serve many numbers. Changing the application's voice URL changes it for every number routed to it.
Create a voice application
A voice application has these fields:
| Field | Required | Description |
|---|---|---|
name | Yes | A label, 1 to 120 characters. |
voice_url | Yes | The URL Signals requests when a call arrives. Must use https://, at most 2,048 characters, with no username, password or fragment. |
voice_method | Yes | POST or GET. |
status_callback_url, status_callback_method | No | Where Signals reports that a call ended. Set both or neither. See Status callbacks. |
fallback_url, fallback_method | No | Requested once when the voice URL cannot be reached, times out or returns a document Signals cannot run. Set both or neither. See Fallback URL. |
In the console
- Switch the console to Programmable Voice and open Applications.
- Create an application, enter its name and voice URL, and choose the method.
With the Signals API
Send a POST to /v1/voice/applications with an API key and an Idempotency-Key. Repeating the request with the same key within 24 hours returns the same application instead of creating a second one.
Code
A 201 response returns the application. Note its id, which starts with vap_:
Code
The application is live as soon as the API returns it. If your organization has more than one project, add an X-Project-ID header naming the project. See Authentication and the Programmable Voice API reference.
Route a number to the application
- In the console, open Numbers and select the number or block.
- Open Routes, choose the numbers to route, and pick your voice application as the target.
- Save. The route shows as pending until the voice network applies it, then as applied.
To route numbers through the API, see Numbers and routing and the Numbers API reference. A number routed to a voice application stops reaching any SIP trunk it was routed to before.
Answer with a greeting
The following server answers every inbound call with a spoken greeting. It is complete and runnable. Signals only requests https:// URLs, so put it behind HTTPS (a tunnel works for testing) and set the application's voice URL to https://YOUR_HOST/voice/incoming.
Serve responses with a Content-Type of text/xml. res.type("text/xml") and Response(..., mimetype="text/xml") set it in the examples above.
Build a two-option menu
Extend the same server into a menu that branches on caller input. The voice URL route returns a <Gather> that collects one digit and sends it to an action route, which returns a different document for each option.
A production menu dials an agent instead of hanging up. See Forwarding calls to connect the caller to another number.
Next steps
- Webhooks: parameters, timeouts, fallback and call events for every request Signals sends your server.
- Gather: every attribute for collecting digits and speech.
- OneML overview: every verb available for scripting a call.