The Wait element waits silently for a specified number of seconds. If Wait is the first element in a XML document, Plivo will wait the specified number of seconds before picking up the call.
Check out our server-side SDKs page and install the right helper based on the programming language you want to use.
Buy a Plivo phone number. A phone number is required to receive calls. You can buy a Plivo phone number in over 20+ countries through the Buy Numbers tab on your Plivo account UI. Check the Voice API coverage page for all the supported countries.
Use a web hosting service to host your web application. There are many inexpensive cloud hosting providers that you can use for just a few dollars a month. Follow the instructions of your hosting provider to host your web application.
Set up a Web Server
Let’s assume your web server is located at example.com. The code snippet below will create three routes on your webserver:
/basic_wait/
this route will say to the caller “I will wait for 10 seconds”, then wait for 10 seconds, then say “I just waited 10 seconds”.
/delayed_wait/
this route will wait 10 seconds, answer the call, then say to the caller “Hello”.
/beep_det/
this route will answer the call, wait for 100 seconds, then say to the caller “Hello”. During the 100 second wait, if a beep is detected like that of an answering machine or voicemail, the Wait XML will immediately end and the caller will hear “Hello”.
Now when we send an HTTP request to example.com/basic_wait/, example.com/delayed_wait/, or example.com/beep_det/ these routes will be invoked.
Note: For PHP, the routes will be `example.com/basic_wait.php`, `example.com/delayed_wait.php`, and `example.com/beep_det.php`.
Copy the relevant code below into a text file called wait and save it.
Next, you will now have to configure this URL in your Plivo application.
importplivoxmlfromflaskimportFlask,Responseapp=Flask(__name__)# Example for Basic Wait
@app.route('/basic_wait/',methods=['GET','POST'])defbasic_wait():r=plivoxml.Response()r.addSpeak("I will wait for 10 seconds")params={'length':"10"# Time to wait in seconds
}r.addWait(**params)r.addSpeak("I just waited 10 seconds")printr.to_xml()returnResponse(str(r),mimetype='text/xml')# Example for Delayed Call Answer
@app.route('/delayed_wait/',methods=['GET','POST'])defdelayed_wait():r=plivoxml.Response()params={'length':"10"# Time to wait in seconds
}r.addWait(**params)r.addSpeak("Hello")printr.to_xml()returnResponse(str(r),mimetype='text/xml')# Example for Beep Detection
@app.route('/beep_det/',methods=['GET','POST'])defbeep_det():r=plivoxml.Response()params={'length':"100",# Time to wait in seconds
'beep':"true"# If a beep is detected, immediately end Wait and process next XML element
}r.addWait(**params)r.addSpeak("Hello")printr.to_xml()returnResponse(str(r),mimetype='text/xml')if__name__=='__main__':app.run(host='0.0.0.0',debug='True')
require'rubygems'require'sinatra'require'plivo'includePlivo# Example for Basic Waitget'/basic_wait/'dor=Response.new()r.addSpeak("I will wait for 10 seconds")params={'length'=>"10"# Time to wait in seconds}r.addWait(params)r.addSpeak("I just waited 10 seconds")putsr.to_xml()content_type'text/xml'returnr.to_s()end# Example for Delayed Call Answerget'/delayed_wait/'dor=Response.new()params={'length'=>"10"# Time to wait in seconds}r.addWait(params)r.addSpeak("Hello")putsr.to_xml()content_type'text/xml'returnr.to_s()end# Example for Beep Detectionget'/beep_det/'dor=Response.new()params={'length'=>"100",# Time to wait in seconds'beep'=>"true"# If a beep is detected, immediately end Wait and process next XML element}r.addWait(params)r.addSpeak("Hello")putsr.to_xml()content_type'text/xml'returnr.to_s()end
varexpress=require('express');varexpress=require('express');varapp=express();varplivo=require('plivo');varp=plivo.RestAPI({authId:'Your_AUTH_ID',authToken:'Your_AUTH_TOKEN'});app.set('port',(process.env.PORT||5000));// Example for Basic Waitapp.get('/basic_wait/',function(request,response){varr=plivo.Response();r.addSpeak("I will wait for 10 seconds");varparams={'length':"10"// Time to wait in seconds};r.addWait(params);r.addSpeak("I just waited 10 seconds");console.log(r.toXML());response.set({'Content-Type':'text/xml'});response.send(r.toXML());});// Example for Delayed Call Answerapp.get('/delayed_wait/',function(request,response){varr=plivo.Response();varparams={'length':"10"// Time to wait in seconds};r.addWait(params);r.addSpeak("Hello");console.log(r.toXML());response.set({'Content-Type':'text/xml'});response.send(r.toXML());});// Example for Beep Detectionapp.get('/beep_det/',function(request,response){varr=plivo.Response();varparams={'length':"100",// Time to wait in seconds'beep':"true"// If a beep is detected, immediately end Wait and process next XML element};r.addWait(params);r.addSpeak("Hello");console.log(r.toXML());response.set({'Content-Type':'text/xml'});response.send(r.toXML());});app.listen(app.get('port'),function(){console.log('Node app is running on port',app.get('port'));});
<!-- basic_wait.php --><?phprequire'vendor/autoload.php';usePlivo\Response;$r=newResponse();$body="I will wait for 10 seconds";$r->addSpeak($body);$params=array('length'=>'10'# Time to wait in seconds);$r->addWait($params);$body1="I just waited 10 seconds";$r->addSpeak($body1);Header('Content-type: text/xml');echo($r->toXML());?><!-- delayed_wait.php --><?phprequire'vendor/autoload.php';usePlivo\Response;$r=newResponse();$params=array('length'=>'10'# Time to wait in seconds);$r->addWait($params);$body="Hello";$r->addSpeak($body);Header('Content-type: text/xml');echo($r->toXML());?><!-- beep_det.php --><?phprequire'vendor/autoload.php';usePlivo\Response;$r=newResponse();$params=array('length'=>'10',# Time to wait in seconds'beep'=>'true'# If a beep is detected, immediately end Wait and process next XML element);$r->addWait($params);$body="Hello";$r->addSpeak($body);Header('Content-type: text/xml');echo($r->toXML());?>
// basicWait.javapackageplivoexample;importjava.io.IOException;importcom.plivo.helper.exception.PlivoException;importcom.plivo.helper.xml.elements.PlivoResponse;importcom.plivo.helper.xml.elements.Speak;importcom.plivo.helper.xml.elements.Wait;importjavax.servlet.ServletException;importjavax.servlet.http.HttpServlet;importjavax.servlet.http.HttpServletRequest;importjavax.servlet.http.HttpServletResponse;importorg.eclipse.jetty.server.Server;importorg.eclipse.jetty.servlet.ServletContextHandler;importorg.eclipse.jetty.servlet.ServletHolder;publicclassbasicWaitextendsHttpServlet{privatestaticfinallongserialVersionUID=1L;@OverrideprotectedvoiddoGet(HttpServletRequestreq,HttpServletResponseresp)throwsServletException,IOException{PlivoResponseresponse=newPlivoResponse();Speakspeak=newSpeak("I will wait for 10 seconds");Waitwait=newWait();wait.setLength(10);// Time to wait in secondsSpeakspk=newSpeak("I just waited 10 seconds");try{response.append(speak);response.append(wait);response.append(spk);System.out.println(response.toXML());resp.addHeader("Content-Type","text/xml");resp.getWriter().print(response.toXML());;}catch(PlivoExceptione){e.printStackTrace();}}publicstaticvoidmain(String[]args)throwsException{Stringport=System.getenv("PORT");if(port==null)port="8000";Serverserver=newServer(Integer.valueOf(port));ServletContextHandlercontext=newServletContextHandler(ServletContextHandler.SESSIONS);context.setContextPath("/");server.setHandler(context);context.addServlet(newServletHolder(newbasicWait()),"/basic_wait/");context.addServlet(newServletHolder(newdelayedWait()),"/delayed_wait/");context.addServlet(newServletHolder(newbeepDetection()),"/beep_det/");server.start();server.join();}}// delayedWait.javapackageplivoexample;importjava.io.IOException;importcom.plivo.helper.exception.PlivoException;importcom.plivo.helper.xml.elements.PlivoResponse;importcom.plivo.helper.xml.elements.Speak;importcom.plivo.helper.xml.elements.Wait;importjavax.servlet.ServletException;importjavax.servlet.http.HttpServlet;importjavax.servlet.http.HttpServletRequest;importjavax.servlet.http.HttpServletResponse;publicclassdelayedWaitextendsHttpServlet{privatestaticfinallongserialVersionUID=1L;@OverrideprotectedvoiddoGet(HttpServletRequestreq,HttpServletResponseresp)throwsServletException,IOException{PlivoResponseresponse=newPlivoResponse();Waitwait=newWait();wait.setLength(10);// Time to wait in secondsSpeakspk=newSpeak("Hello");try{response.append(wait);response.append(spk);System.out.println(response.toXML());resp.addHeader("Content-Type","text/xml");resp.getWriter().print(response.toXML());;}catch(PlivoExceptione){e.printStackTrace();}}}// beepDetection.javapackageplivoexample;importjava.io.IOException;importcom.plivo.helper.exception.PlivoException;importcom.plivo.helper.xml.elements.PlivoResponse;importcom.plivo.helper.xml.elements.Speak;importcom.plivo.helper.xml.elements.Wait;importjavax.servlet.ServletException;importjavax.servlet.http.HttpServlet;importjavax.servlet.http.HttpServletRequest;importjavax.servlet.http.HttpServletResponse;publicclassbeepDetectionextendsHttpServlet{privatestaticfinallongserialVersionUID=1L;@OverrideprotectedvoiddoGet(HttpServletRequestreq,HttpServletResponseresp)throwsServletException,IOException{PlivoResponseresponse=newPlivoResponse();Waitwait=newWait();wait.setLength(100);// Time to wait in secondswait.setBeep(true);// If a beep is detected, immediately end Wait and process next XML elementSpeakspk=newSpeak("Hello");try{response.append(wait);response.append(spk);System.out.println(response.toXML());resp.addHeader("Content-Type","text/xml");resp.getWriter().print(response.toXML());;}catch(PlivoExceptione){e.printStackTrace();}}}
usingSystem;usingSystem.Collections.Generic;usingSystem.Diagnostics;usingRestSharp;usingPlivo.XML;usingNancy;namespacewait_xml{publicclassProgram:NancyModule{publicProgram(){Get["/basic_wait/"]=x=>{Plivo.XML.Responseresp=newPlivo.XML.Response();resp.AddSpeak("I will wait for 10 seconds",newDictionary<string,string>(){});resp.AddWait(newDictionary<string,string>(){{"length","10"}// Time to wait in seconds});resp.AddSpeak("I just waited 10 seconds",newDictionary<string,string>(){});Debug.WriteLine(resp.ToString());varoutput=resp.ToString();varres=(Nancy.Response)output;res.ContentType="text/xml";returnres;};Get["/delayed_wait/"]=x=>{Plivo.XML.Responseresp=newPlivo.XML.Response();resp.AddWait(newDictionary<string,string>(){{"length","10"}// Time to wait in seconds});resp.AddSpeak("Hello",newDictionary<string,string>(){});Debug.WriteLine(resp.ToString());varoutput=resp.ToString();varres=(Nancy.Response)output;res.ContentType="text/xml";returnres;};Get["/beep_det/"]=x=>{Plivo.XML.Responseresp=newPlivo.XML.Response();resp.AddWait(newDictionary<string,string>(){{"length","100"},// Time to wait in seconds{"beep","true"}// If a beep is detected, immediately end Wait and process next XML element});resp.AddSpeak("Hello",newDictionary<string,string>(){});Debug.WriteLine(resp.ToString());varoutput=resp.ToString();varres=(Nancy.Response)output;res.ContentType="text/xml";returnres;};}}}
Give your application a name. Let’s call it Wait XML. Enter your server URL (e.g., http://www.example.com/wait) in the Answer URL field and set the method as POST. See our Application API docs to learn how to modify your application through our APIs.
Click on Create to save your application.
Assign a Plivo number to your app
Navigate to the Numbers page and select the phone number you want to use for this app.
Select Wait XML (name of the app) from the Plivo App dropdown list.
Click on ‘Update’ to save.
If you don’t have a number, go to the Buy Number page to purchase a Plivo phone number.
Test it out
When you make a call to your Plivo number, the call will be answered by Plivo and the message will be played.