# Receiving calls

This guide walks you through answering an inbound call and building a simple menu for it. It assumes you have a phone number on your account. See the dashboard if you do not yet have one.

## Configure a voice URL

Every number on your account has a voice URL: the address PressOne requests whenever a call arrives for that number. In your dashboard, open the number's configuration and set the voice URL to a route on your server, along with the HTTP method used to request it (`POST` by default).

Once configured, every inbound call to that number follows the same sequence:

1. A call arrives at the number.
2. PressOne requests the voice URL, sending call parameters such as `CallSid`, `From`, and `To`. See [webhooks](/voice/webhooks) for the complete parameter set.
3. Your server returns a OneML document, and PressOne executes it on the call.

## Answer with a greeting

The following server answers every inbound call with a spoken greeting. It is complete and runnable. Point your number's voice URL at it to try it.

<CodeTabs syncKey="lang">

```javascript title="Node.js"
const express = require("express");
const app = express();
app.use(express.urlencoded({ extended: false }));

app.post("/voice/incoming", (req, res) => {
  const oneml = `<?xml version="1.0" encoding="UTF-8"?>
<Response>
  <Say>Thank you for calling PressOne. Have a great day.</Say>
  <Hangup/>
</Response>`;

  res.type("text/xml").send(oneml);
});

app.listen(3000);
```

```python title="Python"
from flask import Flask, request, Response

app = Flask(__name__)

@app.route("/voice/incoming", methods=["POST"])
def voice_incoming():
    oneml = """<?xml version="1.0" encoding="UTF-8"?>
<Response>
  <Say>Thank you for calling PressOne. Have a great day.</Say>
  <Hangup/>
</Response>"""

    return Response(oneml, mimetype="text/xml")

if __name__ == "__main__":
    app.run(port=3000)
```

</CodeTabs>

> **Note:** Responses must be served with a `Content-Type` of `text/xml`. `res.type("text/xml")` and `Response(..., mimetype="text/xml")` set it explicitly 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.

<CodeTabs syncKey="lang">

```javascript title="Node.js"
const express = require("express");
const app = express();
app.use(express.urlencoded({ extended: false }));

app.post("/voice/incoming", (req, res) => {
  const oneml = `<?xml version="1.0" encoding="UTF-8"?>
<Response>
  <Gather action="/voice/menu" numDigits="1" timeout="10">
    <Say>For sales, press 1. For support, press 2.</Say>
  </Gather>
  <Say>We did not receive your selection. Goodbye.</Say>
  <Hangup/>
</Response>`;

  res.type("text/xml").send(oneml);
});

app.post("/voice/menu", (req, res) => {
  const digits = req.body.Digits;
  let oneml;

  if (digits === "1") {
    oneml = `<?xml version="1.0" encoding="UTF-8"?>
<Response>
  <Say>Connecting you to sales.</Say>
  <Hangup/>
</Response>`;
  } else if (digits === "2") {
    oneml = `<?xml version="1.0" encoding="UTF-8"?>
<Response>
  <Say>Connecting you to support.</Say>
  <Hangup/>
</Response>`;
  } else {
    oneml = `<?xml version="1.0" encoding="UTF-8"?>
<Response>
  <Say>That is not a valid option. Goodbye.</Say>
  <Hangup/>
</Response>`;
  }

  res.type("text/xml").send(oneml);
});

app.listen(3000);
```

```python title="Python"
from flask import Flask, request, Response

app = Flask(__name__)

@app.route("/voice/incoming", methods=["POST"])
def voice_incoming():
    oneml = """<?xml version="1.0" encoding="UTF-8"?>
<Response>
  <Gather action="/voice/menu" numDigits="1" timeout="10">
    <Say>For sales, press 1. For support, press 2.</Say>
  </Gather>
  <Say>We did not receive your selection. Goodbye.</Say>
  <Hangup/>
</Response>"""

    return Response(oneml, mimetype="text/xml")

@app.route("/voice/menu", methods=["POST"])
def voice_menu():
    digits = request.form.get("Digits")

    if digits == "1":
        oneml = """<?xml version="1.0" encoding="UTF-8"?>
<Response>
  <Say>Connecting you to sales.</Say>
  <Hangup/>
</Response>"""
    elif digits == "2":
        oneml = """<?xml version="1.0" encoding="UTF-8"?>
<Response>
  <Say>Connecting you to support.</Say>
  <Hangup/>
</Response>"""
    else:
        oneml = """<?xml version="1.0" encoding="UTF-8"?>
<Response>
  <Say>That is not a valid option. Goodbye.</Say>
  <Hangup/>
</Response>"""

    return Response(oneml, mimetype="text/xml")

if __name__ == "__main__":
    app.run(port=3000)
```

</CodeTabs>

A real menu would dial an agent instead of hanging up. See [Forwarding calls](/voice/forwarding-calls) for connecting the caller to another number.

## Next steps

- [Webhooks](/voice/webhooks): standard parameters, transport, and signature verification for every request PressOne sends your server.
- [Gather](/voice/oneml/gather): the full set of attributes for collecting DTMF and speech input.
- [OneML overview](/voice/oneml/overview): every verb available for scripting a call.
