Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Including links in text message using twilio API

Tags:

url

php

sms

api

twilio

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?

like image 734
Lucy Weatherford Avatar asked Dec 28 '22 07:12

Lucy Weatherford


2 Answers

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
like image 62
TrentonMcManus Avatar answered Jan 05 '23 10:01

TrentonMcManus


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.

like image 22
Lucy Weatherford Avatar answered Jan 05 '23 09:01

Lucy Weatherford