Notify Callers

    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
    
    from plivo import plivoxml
    
    response = 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())
    
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    
    require 'rubygems'
    require 'plivo'
    
    include Plivo::XML
    include Plivo::Exceptions
    
    begin
      response = 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)
    
      xml = PlivoXML.new(response)
      puts xml.to_xml
    rescue PlivoXMLError => e
      puts 'Exception: ' + e.message
    end
    
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    
    var plivo = require('plivo');
    
    var response = plivo.Response();
    
    var pre_answer = response.addPreAnswer();
    
    var pre_answer_speak_body = "This call will cost you $2 a minute.";
    pre_answer.addSpeak(pre_answer_speak_body);
    
    var speak_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>
    */
    
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    
    <?php
        require '../vendor/autoload.php';
        use Plivo\XML\Response;
    
        $response = new Response();
    
        $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>
        */
    ?>
    
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    
    // Example for xml - notify callers
    package com.plivo.api.xml.samples.xml;
    
    import com.plivo.api.exceptions.PlivoXmlException;
    import com.plivo.api.xml.PreAnswer;
    import com.plivo.api.xml.Response;
    import com.plivo.api.xml.Speak;
    
    
    class NotifyCallers {
        public static void main(String[] args) throws PlivoXmlException {
            Response response = new Response()
                    .children(
    
    
                            new PreAnswer()
                                    .children(
                                            new Speak("This call will cost you $2 a minute.")
                                    ),
    
    
                            new Speak("Hey, thanks for dropping by.")
                    );
            System.out.println(response.toXmlString());
        }
    }
    
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    
    using System;
    using System.Collections.Generic;
    using Plivo.XML;
    
    namespace Plivo
    {
    	class MainClass
    	{
    		public static void Main(string[] args)
    		{
    			Plivo.XML.Response resp = new Plivo.XML.Response();
    			Plivo.XML.PreAnswer answer = new
    				Plivo.XML.PreAnswer();
    			answer.AddSpeak("This call will cost $2 a min.",
    				new Dictionary<string, string>() { });
    			resp.Add(answer);
    			resp.AddSpeak("Thanks for dropping by.",
    				new Dictionary<string, string>() { });
    
    			var output = resp.ToString();
    			Console.WriteLine(output);
    
    		}
    	}
    }
    
    
    
    //<Response>
    //  <PreAnswer>
    //    <Speak>This call will cost $2 a min.</Speak>
    //  </PreAnswer>
    //  <Speak>Thanks for dropping by.</Speak>
    //</Response>
    
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    
    // Example for xml - pre answer
    package main
    
    import "github.com/plivo/plivo-go/xml"
    
    func main() {
    	response := xml.ResponseElement{
    		Contents: []interface{}{
    
    			new(xml.PreAnswerElement).
    				SetContents([]interface{}{
    
    					new(xml.SpeakElement).
    						SetContents("This call will cost you $2 a minute."),
    				}),
    
    			new(xml.SpeakElement).
    				SetContents("Hey, thanks for dropping by."),
    		},
    	}
    	print(response.String())
    }