> ## Documentation Index
> Fetch the complete documentation index at: https://plivo.com/docs/llms.txt
> Use this file to discover all available pages before exploring further.

# Message Element

> Send SMS messages using the Message XML element

Use the Message element to send a message during your call flow. For instance, if you want to send out an SMS notification when you receive an incoming call on your Plivo number, you can use the `<Message>` element in your application.

To receive a message, you must set a message URL in your Plivo application [via the API](https://plivo.com/docs/account/api/application.md) or in the Plivo console at Messaging > [Applications](https://cx.plivo.com).

***

## Attributes

Here are the attributes the Message element supports. You can modify the default behavior of each attribute by using the allowed values.

| Name | Type | Description |
| - | - | - |
| src | string | Source number — for example, `12025550000`. Must be a purchased, valid number. |
| dst | string | Destination number. Must be a valid number. To use bulk numbers, specify them separated by `<` — for example, `12025551111<12025552222`. |
| type | string | Type of the message. Allowed values: `sms` |
| callbackUrl | string | A valid, reachable URL that Plivo notifies when a response is available and to which the response is sent (Delivery reports). |
| callbackMethod | string | The method used to notify the `callbackUrl`. Allowed values: `GET`, `POST`. Defaults to `POST`. |

***

## Example

This example XML document is used to send out an SMS message. Plivo sends a delivery report to the callback URL using the HTTP POST method.

```python Python theme={null}
from plivo import plivoxml

response = plivoxml.ResponseElement()
response.add(
    plivoxml.MessageElement(
        'Hi, this is a sample text',
        src='+12025550000',
        dst='+12025551111',
        type='sms',
        callback_url='https://<yourdomain>.com/sms_status/',
        callback_method='POST'))
print(response.to_string())
```

```javascript Node.js theme={null}
var plivo = require('plivo');

var response = plivo.Response();

var params = {
    'src': "+12025550000",
    'dst': "+12025551111",
    'type': "sms",
    'callbackUrl': "https://<yourdomain>.com/sms_status/",
    'callbackMethod': "POST"
};
var message_body = "Hi, this is a sample text";
response.addMessage(message_body, params);

console.log(response.toXML());
```

```ruby Ruby theme={null}
require 'rubygems'
require 'plivo'

include Plivo::XML
include Plivo::Exceptions

begin
  response = Response.new

  params = {
      src: '+12025550000',
      dst: '+12025551111',
      type: 'sms',
      callbackUrl: 'https://<yourdomain>.com/sms_status/',
      callbackMethod: 'POST'
  }
  message_body = 'Hi, this is a sample text'
  response.addMessage(message_body, params)

  xml = PlivoXML.new(response)
  puts xml.to_xml
rescue PlivoXMLError => e
  puts 'Exception: ' + e.message
end
```

```php PHP theme={null}
<?php
    require '../vendor/autoload.php';
    use Plivo\XML\Response;

    $response = new Response();

    $params = array(
        'src' => "+12025550000",
        'dst' => "+12025551111",
        'type' => "sms",
        'callbackUrl' => "https://<yourdomain>.com/sms_status/",
        'callbackMethod' => "POST"
    );
    $message_body = "Hi, this is a sample text";
    $response->addMessage($message_body, $params);

    Header('Content-type: text/xml');
    echo($response->toXML());
?>
```

```java Java theme={null}
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("+12025550000", "+12025551111", "Hi, this is a sample text")
                                .callbackMethod("POST")
                                .callbackUrl("https://<yourdomain>.com/sms status/")
                                .type("sms")
                );
        System.out.println(response.toXmlString());
    }
}
```

```csharp .NET theme={null}
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, this is a sample text",
                            new Dictionary<string, string>()
            {
                {"src", "+12025550000"},
                {"dst", "+12025551111" } ,
                {"type", "sms"},
                {"callbackUrl", "https://<yourdomain>.com/sms_status/"},
                {"callbackMethod", "POST"}
            });

            var output = resp.ToString();
            Console.WriteLine(output);
        }
    }
}
```

```go Go theme={null}
package main

import "github.com/plivo/plivo-go/v7/xml"

func main() {
    response := xml.ResponseElement{
        Contents: []interface{}{
            new(xml.MessageElement).
                SetCallbackMethod("POST").
                SetCallbackUrl("https://<yourdomain>.com/sms_status/").
                SetDst("+12025551111").
                SetSrc("+12025550000").
                SetType("sms").
                SetContents("Hi, this is a sample text"),
        },
    }
    print(response.String())
}
```

### Response

```xml theme={null}
<Response>
  <Message src="12022220000" dst="12025551111" type="sms" callbackUrl="https://<yourdomain>.com/sms_status/" callbackMethod="POST">
    Hi, this is a text message
  </Message>
</Response>
```
