Message XML example

    This sample XML is used to send out an SMS. Plivo will send the delivery report the callback URL using the HTTP POST method.

    Response

    <Response>
      <Message src="12023222222" dst="15671234567" type="sms" callbackUrl="http://foo.com/sms_status/" callbackMethod="POST">
        Hi, Message from Plivo
      </Message>
    </Response>
    

    Example Request

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    
    from plivo import plivoxml
    
    response = plivoxml.ResponseElement()
    response.add(
        plivoxml.MessageElement(
            'Hi, Message from Plivo',
            src='+12023222222',
            dst='+15671234567',
            type='sms',
            callback_url='http://foo.com/sms_status/',
            callback_method='POST'))
    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
    23
    24
    
    require rubygems
    require plivo
    
    include Plivo::XML
    include Plivo::Exceptions
    
    begin
      response = Response.new
    
      params = {
          src: '+12023222222',
          dst: '+15671234567',
          type: 'sms',
          callbackUrl: 'https://www.foo.com/sms_status',
          callbackMethod: 'POST'
      }
      message_body = 'Hi, Message from Plivo'
      response.addMessage(message_body, params)
    
      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
    24
    
    var plivo = require('plivo');
    
    var response = plivo.Response();
    
    var params = {
        'src': "+12023222222",
        'dst': "+15671234567",
        'type': "sms",
        'callbackUrl': "https://www.foo.com/sms_status",
        'callbackMethod': "POST"
    };
    var message_body = "Hi, Message from Plivo";
    response.addMessage(message_body, params);
    
    console.log(response.toXML());
    
    /*
    Sample Output
    <Response>
        <Message src="1111111111" dst="2222222222" type="sms" callbackUrl="https://www.foo.com/sms_status" callbackMethod="POST">
            Hi, Message from Plivo
        </Message>
    </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
    
    <?php
        require '../vendor/autoload.php';
        use Plivo\XML\Response;
    
        $response = new Response();
    
        $params = array(
            'src' => "+12023222222",
            'dst' => "+15671234567",
            'type' => "sms",
            'callbackUrl' => "https://www.foo.com/sms_status/",
            'callbackMethod' => "POST"
        );
        $message_body = "Hi, Message from Plivo";
        $response->addMessage($message_body, $params);
    
        Header('Content-type: text/xml');
        echo($response->toXML());
    
        /*
        Sample Output
    
        <Response>
            <Message src="1111111111" dst="2222222222" type="sms" callbackUrl="https://www.foo.com/sms_status/" callbackMethod="POST">
                Hi, Message from Plivo
            </Message>
        </Response>
        */
    ?>
    
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    
    // Example for xml - send an sms
    package com.plivo.api.xml.samples.xml;
    
    import com.plivo.api.exceptions.PlivoXmlException;
    import com.plivo.api.xml.Message;
    import com.plivo.api.xml.Response;
    
    
    class SendAnSms {
        public static void main(String[] args) throws PlivoXmlException {
            Response response = new Response()
                    .children(
    
    
                            new Message("+12023222222", "+15671234567", "Hi, message from Plivo.")
                                    .callbackMethod("POST")
                                    .callbackUrl("http://foo.com/sms status/")
                                    .type("sms")
    
                    );
            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
    35
    36
    37
    
    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();
    			resp.AddMessage("Hi, message from Plivo.",
    							new Dictionary<string, string>()
    			{
    				{"src", "+12023222222"},
    				{"dst", "+15671234567" } ,
    				{"type", "sms"},
    				{"callbackUrl", "http://foo.com/sms_status/"},
    				{"callbackMethod", "POST"}
    			});
    
    			var output = resp.ToString();
    			Console.WriteLine(output);
    
    		}
    	}
    }
    
    
    
    //<Response>
    //  <Message src = "12023222222" dst="15671234567" 
    //    type="sms" callbackUrl="http://foo.com/sms_status/" 
    //    callbackMethod="POST">
    //        Hi, message from Plivo.
    //  </Message>
    //</Response>
    
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    
    // Example for xml - message
    package main
    
    import "github.com/plivo/plivo-go/xml"
    
    func main() {
    	response := xml.ResponseElement{
    		Contents: []interface{}{
    
    			new(xml.MessageElement).
    				SetCallbackMethod("POST").
    				SetCallbackUrl("http://foo.com/sms status/").
    				SetDst("+15671234567").
    				SetSrc("+12023222222").
    				SetType("sms").
    				SetContents("Hi, message from Plivo."),
    		},
    	}
    	print(response.String())
    }