0

In a case i have to send SMS with two whitespaces at the beginning of the message content as like below

  setparam 3003:70eac;

This is for some device configuration. But while receiving the SMS it is

setparam 3003:70eac;

The whitespaces are gone. This is how i send the SMS with php helper library

$client = new Client($account_sid, $auth_token);
$client->messages->create(
    '<to_number>',
    array(
        'from' => '<from_number>',
        'body' => '  setparam 3003:70eac;'
    )
);

I had also tried by sending as encoded like below

%20%20setparam%203003%3A70eac%3B

This results without parsing

%20%20setparam%203003%3A70eac%3B

Any help will be great support to me.

Rajez
  • 3,717
  • 1
  • 14
  • 21

2 Answers2

2

We couldn't use whitspaces normaly while sending SMS in Twilio or Plivo, as those were trimmed automatically. But can be send by escaping the unicode value of whitspace in the message.

Examples:

Python

from twilio.rest import Client

# Your Account SID from twilio.com/console
account_sid = "<twilio_sid>"
# Your Auth Token from twilio.com/console
auth_token  = "<twilio_token>"

client = Client(account_sid, auth_token)

message = client.messages.create(
    to="<to_number>",
    from_="<from_number>",
    body="\U00002001\U00002001Whitspace at front")

print(message.sid)

JSON

{
"src" : "<from_number>",
"dst" : "<to_number>", 
"text" : "\u0020\u0020Whitspace at front", 
"type" : "sms", 
"method" : "POST" 
}

PHP

<?php
// Required if your environment does not handle autoloading
require __DIR__ . '/vendor/autoload.php';

// Use the REST API Client to make requests to the Twilio REST API
use Twilio\Rest\Client;

// Your Account SID and Auth Token from twilio.com/console
$sid = 'ACfe1c3f0e87c51710e95e842f2e71922b';
$token = 'your_auth_token';
$client = new Client($sid, $token);

// Use the client to do fun stuff like send text messages!
$client->messages->create(
    // the number you'd like to send the message to
    '+15558675309',
    array(
        // A Twilio phone number you purchased at twilio.com/console
        'from' => '+15017250604',
        // the body of the text message you'd like to send
        'body' => "\020\020Whitspace at front"
    )
);

You can see the message body is denoted with double quotes(") . That is important in PHP. Denoting with single quote(') won't work. The different quote usages in PHP and Double quoted strings.

More reference links for PHP.

Result:

'  Whitspace at front'
Rajez
  • 3,717
  • 1
  • 14
  • 21
0

In twilio you will have to use Unicode 'Punctuation Space' which is '\2008'. '\0020' wont work.