This example notifies the caller that the cost of the current call is $2 a minute.
Response
<Response><PreAnswer><Speak>This call will cost you $2 a minute.</Speak></PreAnswer><Speak>Hey, thanks for dropping by.</Speak></Response>
Example Request
1
2
3
4
5
6
7
fromplivoimportplivoxmlresponse=plivoxml.ResponseElement()response.add(plivoxml.PreAnswerElement().add(plivoxml.SpeakElement('This call will cost you $2 a minute.')))response.add(plivoxml.SpeakElement('Hey, thanks for dropping by.'))print(response.to_string())
require'rubygems'require'plivo'includePlivo::XMLincludePlivo::Exceptionsbeginresponse=Response.newpre_answer=response.addPreAnswer()pre_answer_speak_body='This call will cost you $2 a minute.'pre_answer.addSpeak(pre_answer_speak_body)speak_body='Hey, thanks for dropping by.'response.addSpeak(speak_body)xml=PlivoXML.new(response)putsxml.to_xmlrescuePlivoXMLError=>eputs'Exception: '+e.messageend
varplivo=require('plivo');varresponse=plivo.Response();varpre_answer=response.addPreAnswer();varpre_answer_speak_body="This call will cost you $2 a minute.";pre_answer.addSpeak(pre_answer_speak_body);varspeak_body="Hey, thanks for dropping by.";response.addSpeak(speak_body);console.log(response.toXML());/*
Sample Output
<Response>
<PreAnswer>
<Speak>This call will cost you $2 a minute.</Speak>
</PreAnswer>
<Speak>Hey, thanks for dropping by.</Speak>
</Response>
*/
<?phprequire'../vendor/autoload.php';usePlivo\XML\Response;$response=newResponse();$pre_answser=$response->addPreAnswer();$pre_answer_speak_body="This call will cost you $2 a minute.";$pre_answser->addSpeak($pre_answer_speak_body);$speak_body="Hey, thanks for dropping by.";$response->addSpeak($speak_body);Header('Content-type: text/xml');echo($response->toXML());/*
Sample Output
<Response>
<PreAnswer>
<Speak>
This call will cost you $2 a minute.
</Speak>
</PreAnswer>
<Speak>Hey, thanks for dropping by.</Speak>
</Response>
*/?>
// Example for xml - notify callerspackagecom.plivo.api.xml.samples.xml;importcom.plivo.api.exceptions.PlivoXmlException;importcom.plivo.api.xml.PreAnswer;importcom.plivo.api.xml.Response;importcom.plivo.api.xml.Speak;classNotifyCallers{publicstaticvoidmain(String[]args)throwsPlivoXmlException{Responseresponse=newResponse().children(newPreAnswer().children(newSpeak("This call will cost you $2 a minute.")),newSpeak("Hey, thanks for dropping by."));System.out.println(response.toXmlString());}}
usingSystem;usingSystem.Collections.Generic;usingPlivo.XML;namespacePlivo{classMainClass{publicstaticvoidMain(string[]args){Plivo.XML.Responseresp=newPlivo.XML.Response();Plivo.XML.PreAnsweranswer=newPlivo.XML.PreAnswer();answer.AddSpeak("This call will cost $2 a min.",newDictionary<string,string>(){});resp.Add(answer);resp.AddSpeak("Thanks for dropping by.",newDictionary<string,string>(){});varoutput=resp.ToString();Console.WriteLine(output);}}}//<Response>// <PreAnswer>// <Speak>This call will cost $2 a min.</Speak>// </PreAnswer>// <Speak>Thanks for dropping by.</Speak>//</Response>
// Example for xml - pre answerpackagemainimport"github.com/plivo/plivo-go/v7/xml"funcmain(){response:=xml.ResponseElement{Contents:[]interface{}{new(xml.PreAnswerElement).SetContents([]interface{}{new(xml.SpeakElement).AddSpeak("This call will cost you $2 a minute."),}),new(xml.SpeakElement).AddSpeak("Hey, thanks for dropping by."),},}print(response.String())}
fromflaskimportFlask,Response,requestimportplivoxmlapp=Flask(__name__)@app.route('/pre_answer/',methods=['GET','POST'])defpre_answer():response=plivoxml.Response()preAnswer=response.addPreAnswer()preAnswer.addSpeak("This call will cost you $2 a minute.")response.addSpeak("Hey, thanks for dropping by.")returnResponse(str(response),mimetype='text/xml')if__name__=="__main__":app.run(host='0.0.0.0',debug=True)# Sample Conference XML
# <Response>
# <PreAnswer>
# <Speak>This call will cost you $2 a minute.</Speak>
# </PreAnswer>
# <Speak>Hey, thanks for dropping by.</Speak>
# </Response>
require'rubygems'require'plivo'includePlivoresponse=Response.new()pre_answer=response.addPreAnswer()pre_answer_speak_body="This call will cost you $2 a minute."pre_answer.addSpeak(pre_answer_speak_body)speak_body="Hey, thanks for dropping by."response.addSpeak(speak_body)putsresponse.to_xml()=begin
Sample Output
<Response>
<PreAnswer>
<Speak>This call will cost you $2 a minute.</Speak>
</PreAnswer>
<Speak>Hey, thanks for dropping by.</Speak>
</Response>
=end
varplivo=require('plivo');varresponse=plivo.Response();varpre_answer=response.addPreAnswer();varpre_answer_speak_body="This call will cost you $2 a minute.";pre_answer.addSpeak(pre_answer_speak_body);varspeak_body="Hey, thanks for dropping by.";response.addSpeak(speak_body);console.log(response.toXML());/*
Sample Output
<Response>
<PreAnswer>
<Speak>This call will cost you $2 a minute.</Speak>
</PreAnswer>
<Speak>Hey, thanks for dropping by.</Speak>
</Response>
*/
<?phprequire'../vendor/autoload.php';usePlivo\Response;$response=newResponse();$pre_answser=$response->addPreAnswer();$pre_answer_speak_body="This call will cost you $2 a minute.";$pre_answser->addSpeak($pre_answer_speak_body);$speak_body="Hey, thanks for dropping by.";$response->addSpeak($speak_body);Header('Content-type: text/xml');echo($response->toXML());/*
Sample Output
<Response>
<PreAnswer>
<Speak>
This call will cost you $2 a minute.
</Speak>
</PreAnswer>
<Speak>Hey, thanks for dropping by.</Speak>
</Response>
*/?>
importjava.io.IOException;importcom.plivo.helper.exception.PlivoException;importcom.plivo.helper.xml.elements.Speak;importcom.plivo.helper.xml.elements.PreAnswer;importcom.plivo.helper.xml.elements.PlivoResponse;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;publicclasspreAnswerextendsHttpServlet{privatestaticfinallongserialVersionUID=1L;@OverrideprotectedvoiddoGet(HttpServletRequestreq,HttpServletResponseresp)throwsServletException,IOException{PlivoResponseresponse=newPlivoResponse();PreAnswerpre_answer=newPreAnswer();Speakspeak1=newSpeak("This call will cost you $2 a minute.");Speakspeak2=newSpeak("Hey, thanks for dropping by.");try{response.append(pre_answer);pre_answer.append(speak1);response.append(speak2);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(newpreAnswer()),"/pre_answer");server.start();server.join();}}/*
Sample Output
<Response>
<PreAnswer>
<Speak>This call will cost you $2 a minute.</Speak>
</PreAnswer>
<Speak>Hey, thanks for dropping by.</Speak>
</Response>
*/
usingSystem;usingSystem.Collections.Generic;usingPlivo.XML;namespacePlivo{classMainClass{publicstaticvoidMain(string[]args){Plivo.XML.Responseresp=newPlivo.XML.Response();Plivo.XML.PreAnsweranswer=newPlivo.XML.PreAnswer();answer.AddSpeak("This call will cost $2 a min.",newDictionary<string,string>(){});resp.Add(answer);resp.AddSpeak("Thanks for dropping by.",newDictionary<string,string>(){});varoutput=resp.ToString();Console.WriteLine(output);}}}//<Response>// <PreAnswer>// <Speak>This call will cost $2 a min.</Speak>// </PreAnswer>// <Speak>Thanks for dropping by.</Speak>//</Response>
// Example for xml - pre answerpackagemainimport"github.com/plivo/plivo-go/v7/xml"funcmain(){response:=xml.ResponseElement{Contents:[]interface{}{new(xml.PreAnswerElement).SetContents([]interface{}{new(xml.SpeakElement).AddSpeak("This call will cost you $2 a minute."),}),new(xml.SpeakElement).AddSpeak("Hey, thanks for dropping by."),},}print(response.String())}
Rate this page
🥳 Thank you! It means a lot to us!
×
Help Us Improve
Thank you so much for rating the page, we would like to get your input
for further improvements!