<

Getting Started with Incoming Calls

This guide helps you to answering your first incoming call on your Plivo number using Plivo XML. In this example, when an incoming call is received, Plivo’s text-to-speech engine will play a message using the Speak XML and then the call gets bridged to your number.

First steps

Before you can receive and answer calls on your Plivo number, you will first have to determine how you want the call to be handled and appropriate XML should be written. This XML should be then hosted on a webserver and the URL to the XML should be updated as answer_url in the Application (if you aren’t aware of applications, here is a quick guide to get you started with applications) that you attach to a Plivo number.

This enables Plivo to reach out to the answer_url that is configured in the number’s Application whenever there is an incoming call on that number.

The following code snippet in Python will help you generate an XML that speaks the text “Good Morning” to the user once they pick up the call.

1
2
3
4
response = (plivoxml.ResponseElement().add(
    plivoxml.SpeakElement('Thanks for calling.'))
)
print(response.to_string())

The above code would generate the following XML.

1
2
3
<Response>
    <Speak>Thanks for calling.</Speak>
</Response>

So, when a new incoming call is received, Plivo fetches this XML from the answer_url and speaks the text “Thanks for calling.” to the caller. Since there are no further instructions the call will be hung up after speaking the mentioned text. Since there are no further instructions the call will be hung up after speaking the mentioned text.

Instead of just hanging up the call, if you want to join the call and directly speak to the end user, you could use a Dial element to dial your number and bridge the call. In this case, the following XML could be used:

1
2
3
4
5
6
<Response>
    <Speak>Good Morning</Speak>
    <Dial>
        <Number>1415000000</Number>
    </Dial>
</Response>

The Dial element along with the Number element instructs Plivo to dial the number given in the XML and bridge the call with the end user.

Enhancing your call flow

The above XML is a very simple example to basically get you started with how calls can be controlled using Plivo XML. You can refer to the Plivo XML documentation to know more about what is possible with Plivo XML.

Next Steps