BoxLang 🚀 A New JVM Dynamic Language Learn More...

twilio-sdk

v2.5.0 Modules

WELCOME TO THE COLDBOX TWILIO SDK

This module is a CFML SDK to interact with the Twilio API

LICENSE

Apache License, Version 2.0.

SYSTEM REQUIREMENTS

  • Boxlang
  • Lucee 4.5+
  • Adobe ColdFusion 11+

Setup

Configure your Twilio credentials in the config/ColdBox.cfc file.

moduleSettings = {
    "twilio-sdk" = {
        accountSID = "",
        authToken = ""
    }
};

Methods

lookup

Look up information about a phone number. Returns a configured HyperRequest instance.

NameTypeRequired?DefaultDescription
phoneNumberStringtrue The phone number to look up
withCallerNameBooleanfalsefalseShould caller information be included in the response. (This costs extra.) [DEPRECATED]
typesArrayfalse[]An optional array of lookup types to process and include in the response. (This may cost extra.)
addonsArrayfalse[]An optional array of addons to process and include in the response. (This may cost extra.)

sms

Send an sms message. Returns a configured HyperRequest instance.

NameTypeRequired?DefaultDescription
toStringtrue The phone number the sms is going to.
fromStringtrue The phone number the sms is from. This must be a valid Twilio number.
bodyStringtrue The body of the sms message.

getSMS

Get information of a SMS sent with Twilio

NameTypeRequired?DefaultDescription
sidStringtrue Sid of the Message

The information of the sms is in the field data as json of the returned object. To get that information you need to deserialize it:

responseObj = getSMS(sid);
smsData = deserializejson( responseObj.data );

Hyper Integration

The Twilio SDK uses the Hyper HTTP Client under the hood. This entire power is exposed to you.

All methods on the Twilio SDK return a HyperRequest instance. This instance can be immediately executed by calling send, or it can be configured further.

The following is an example of creating an SMS message but then overriding the default URL to allow for subaccount billing.

var req = twilioClient
  .sms( from = "+15005550006", to = "+18015550005", body = "Testing 123" )
  .setUrl( "/Accounts/#subAccountSID#/Messages.json" )
  .send();

Additionally, you may call any HyperRequest method on the TwilioSDK and a new request will be created, your method called, and the result returned to you.

Hyper is so powerful in this case because it can be pre-configured with common values. This is done for your in the ModuleConfig.cfc:

binder.map( "TwilioHyperClient@twilio-sdk" )
    .to( "hyper.models.HyperBuilder" )
    .asSingleton()
    .initWith(
        username = settings.accountSID,
        password = settings.authToken,
        baseURL = "https://api.twilio.com/2010-04-01",
        bodyFormat = "formFields",
        headers = {
            "Content-Type" = "application/x-www-form-urlencoded"
        }
    );

Because of Hyper, you don't have to specify those parameters every request. 👍

Non-ColdBox App

In a non-ColdBox application, you'll need to initialize the models and settings yourself, like so:

var hyperClient = new Hyper.models.HyperBuilder(
    username = accountSID,
    password = authToken,
    baseURL = "https://api.twilio.com/2010-04-01",
    bodyFormat = "formFields",
    headers = {
        "Content-Type" = "application/x-www-form-urlencoded"
    }
);

// store in some sort of singleton scope
application.twilioClient = new twilio-sdk.models.TwilioClient();
application.twilioClient.setAccountSID( accountSID );
application.twilioClient.setHyperClient( hyperClient );

// use as normal
var lookupInfo = application.twilioClient.lookupPhoneNumber( "415-701-2311" );
********************************************************************************
Copyright Since 2005 ColdBox Framework by Luis Majano and Ortus Solutions, Corp
www.coldbox.org | www.luismajano.com | www.ortussolutions.com
********************************************************************************

HONOR GOES TO GOD ABOVE ALL

Because of His grace, this project exists. If you don't like this, then don't read it, its not for you.

"Therefore being justified by faith, we have peace with God through our Lord Jesus Christ: By whom also we have access by faith into this grace wherein we stand, and rejoice in hope of the glory of God. And not only so, but we glory in tribulations also: knowing that tribulation worketh patience; And patience, experience; and experience, hope: And hope maketh not ashamed; because the love of God is shed abroad in our hearts by the Holy Ghost which is given unto us. ." Romans 5:5

THE DAILY BREAD

"I am the way, and the truth, and the life; no one comes to the Father, but by me (JESUS)" Jn 14:1-12

v2.5.0

12 Dec 2024 — 17:03: 17 UTC

chore

  • release: Add semantic-release (6c85f8d)
  • env: Provide example env file (30cc729)
  • tests: Set up testbox watching (88f49a3)

docs

  • README: Add initial documentation (6c6deff)

feat

  • call: Use either Twiml or URL when calling (98664c7)
  • calls: Allow passing additionalParams to calls (5778dd8)
  • lookup: Add ability to lookup information about a phone number (44db9cf)
  • lookup: Add ability to look up phone numbers (82b8dde)
  • SMS: Add ability to send text messages (f440b85)

fix

  • calls: Fix for case-sensitive parameters (2bc1c3d)
  • sms: Escape newline characters when sending text messages (e27d6cd)
  • box.json: Use https link for download url (5a3cecc)
  • box.json: Fix hyper version (ce4b1ec)
  • box.json: Add missing ColdBox devDependency (5964dab)

other

  • *: docs: add boxlang to system requirements (75d9831)
  • *: upgrade actions/cache due scheduled deprecation (c76378f)
  • *: Merge pull request #7 from coldbox-modules/ci/addBoxlangToMatrix (4970f77)
  • *: upgrade EnricoMi/publish-unit-test-result-action action version (2cc8d58)
  • *: set correct names to artifact (63e99c3)
  • *: use repository base directory as webroot (987ea11)
  • *: add missing serverConfigFiles and missing extension (64eb306)
  • *: update deprecated action version (8e31c15)
  • *: Apply cfformat changes (4f95e32)
  • *: add boxlang to matrix (087c0fd)
  • *: feat: Add function getSMS to get the info of a sent SMS (83f8d09)
  • *: chore: Test on latest CFEngines (184ad08)
  • *: chore: Update to latest dependencies (5336a51)
  • *: Merge remote-tracking branch 'origin/main' (4981c02)
  • *: fix: Use Hyper 4 to send duplicate query params with the same name (a61c439)
  • *: chore: Format (d7c9127)
  • *: feat: Add support for multiple types to lookup request (018cb87)
  • *: feat: New module template and calls endpoint (b2f0cb2)
  • *: 1.3.1 (9075bb8)
  • *: Version bump (2511b3e)
  • *: Remove hyper from being a committed dependency (70dec7d)
  • *: Use box dsl namespace over coldbox so CommandBox can use this module (dbe6de9)
  • *: Please work (7aa8d37)
  • *: Figure out publishing (e130c3c)
  • *: Update test runners (257f49c)
  • *: Use newer distro (217b6bf)
  • *: Swap out GPG key download (d481f93)
  • *: Trigger build (84df9a8)
  • *: Update dependenfies to latest versions (d91599a)
  • *: modify http to https (840cef8)
  • *: Merge pull request #2 from Daemach/Daemach-patch-1 (aba82af)
  • *: Update readme.md (2dbe356)
  • *: Update module version (a2bd42e)
  • *: Add ability to validate Twilio requests. (436bde8)
  • *: Update hyper dependency version (234bfa0)
  • *: Update README with configuration information (b6d26fc)
  • *: Update readme code formatting (3aaaf39)
  • *: Prepare 1.0.0 release (10c4c44)
  • *: Fix twilio-sdk code not being added (3556cb7)
  • *: Try to make tests pass? (cb8ce1e)
  • *: Merge branch 'migrate_to_unified_workbench' into development (3a02fc2)
  • *: Migrate to Ortus' unified workbench (c248213)
  • *: Merge pull request #1 from coldbox-modules/development (f7750d7)
  • *: Initial commit (b3ef248)

v2.3.2

19 Mar 2024 — 17:57: 50 UTC

other

  • *: chore: Test on latest CFEngines (184ad08)
  • *: chore: Update to latest dependencies (5336a51)

$ box install twilio-sdk

No collaborators yet.
     
  • {{ getFullDate("2017-12-04T22:26:09Z") }}
  • {{ getFullDate("2024-12-12T17:03:22Z") }}
  • 6,662
  • 33,246