Xbasic

twilio_send_sms Function

Syntax

L result = twilio_send_sms(pResult as p, to as c, message as c, namedResource as c [, from = "" , accountSID = "" , authCode = ""])

Arguments

pResultPointer

An object that contains return information provided by Twilio. For example, if the SMS fails ( result = .f.) the pResult object will have a property explaining why the SMS failed.

toCharacter

The number to send the SMS message.

messageCharacter

The message to send.

namedResourceCharacter

The [Named Resource] that defines your Twilio settings.

Set to an empty string if you want to explicitly set the account SID, authorization token, and from arguments.

fromCharacter

The phone number sending the message. Required if namedResource is an empty string.

accountSIDCharacter

Your Twilio account SID. Required if namedResource is an empty string.

authCodeCharacter

Your Twilio authorization token. Required if namedResource is an empty string.

Returns

resultLogical

Returns .t. if the operation succeeds, otherwise .f.. twilion_send_sms() will return false if the Twilio endpoint cannot be reached or if Twilio reports an error. The pResult argument will contain additional details if an error occurs.

Description

Send SMS messages from Xbasic to a mobile phone using Twilio. Requires a Twilio account and a phone number authorized to send SMS messages.

Discussion

The twilio_send_sms() function sends an sms to a phone number using the Twilio messaging service.

Before you can use this function, you must first set up an account with Twilio. You must also own a phone number that is authorized to send SMS messages. Go to www.twilio.com to setup your Twilio account and learn more.

Once you have a Twilio account and phone number, Twilio will give you the following items that are needed to use the twilio_send_sms() function:

  • AccountSID
  • Authorization Token

When you use the twilio_send_sms() function, you can either pass in the values for the account SID, the authorization token, and 'From' phone number explicitly, or you can create an entry in the Named Providers property in Project Properties to store these values and pass the name of the stored settings to the function (the named resource).

Using Named Resources is the preferred method because you can redefine any of the parameter values in the stored setting when you define a publishing profile.

If you explicitly set the accountSID, authCode and from arguments, set the namedResource argument must be set to an empty string.

pResult is an object that contains return information provided by Twilio. For example, if the SMS fails (twilio_send_sms() returns .f.) the pResult object will have a property explaining why the SMS failed.

See Resource Providers to learn how to create a named resource provider.

dim to as c
to = "+15551111"
dim message as c = "Sent from Xbasic at: " + now()

dim namedResource as c = "MyTwilioSettings"
dim pResult as p
dim flag as l
flag = twilio_send_sms(pResult,to,message,namedResource)

'to see what's in the pResult object
showvarscript(pResult, "" + flag)

See Also