Lucy Weatherford
Lucy Weatherford

Reputation: 5544

Including links in text message using twilio API

How can I include a url in an outgoing text message using twilio API? I tried, but the message was not sent. Is there a specific format? syntax?

Update: Here's the code: (I am using the php api) Perhaps the problem is with using a variable in the link? or maybe in a different format?

$sms = $client->account->sms_messages->create(
    "xxx-xxx-xxxx", 
    $send_to_number, 
    "Hey $var1. words words $var2. via example.com. 
    see: https://graph.facebook.com/$fb_id/picture"); 

The example.com link works perfect, so do $var1 and $var2. But when adding the last link which includes a variable (and it is from facebook graph api, but I don't think that matters), then the message is not sent. Is there any way to solve this without url shortener?

Upvotes: 4

Views: 8821

Answers (3)

TrentonMcManus
TrentonMcManus

Reputation: 507

SMS messages sent via Twilio are limited to 160 characters because carriers will break messages up into 160 character sized chunks. These chunks doen't necessarily arrive in order, so it is recommended to send some sort of pagination along with the message if you expect it to be over 160 chars.

https://www.twilio.com/help/faq/sms#sms-technical-3

The official Twilio PHP helper library will error out if you attempt to send a message longer than 160 characters.

Something else to watch out for: if you break your message into two lines like you have done here, PHP will include the characters you used for indentation in the message, so the above code will produce an SMS message that looks like this:

Hey $var1. words words $var2. via example.com. 
                     see: https://graph.facebook.com/$fb_id/picture

Upvotes: 7

user1727249
user1727249

Reputation: 19

Twilio recently updated their api. You can now send messages longer than 140 characters.

Such messages will be automatically split into pieces for each carrier.

Upvotes: 0

Lucy Weatherford
Lucy Weatherford

Reputation: 5544

The message is too long. There is a limit of characters in a twilio message. This has nothing to do with the variable. It now works, just shortened the text.

Upvotes: 3

Related Questions