Jump to content


How-to: X2flows - Send an SMS with Twilio using Zapier

  • Please log in to reply
No replies to this topic

#1 that0n3guy


    Advanced Member

  • Premium Members
  • PipPipPip
  • 284 posts

Posted 23 February 2015 - 01:06 PM

This how-to will be a little bit technical, but its really not that bad.  It also requires the pro or platnium downloadable version of x2engine.  It also requires the use of composer...



  • Install Composer: Make sure you have composer installed: https://getcomposer....-linux-unix-osx
  • Add phone number package: Add https://github.com/g...enumber-for-phpto your main composer.json: composer require giggsey/libphonenumber-for-php:~7.0
  • Add composer autoload to config files:
    • Create the file custom/protected/config/web.php . Add to the top (after <?php):  require_once dirname(__FILE__)."/../../../vendor/autoload.php";
    • Create the file custom/protected/config/console.php . Add to the top (after <?php):  require_once dirname(__FILE__)."/../../../vendor/autoload.php";
    • Also add to the bottom of custom/protected/config/console.php: $config['components']['request']['hostInfo'] = 'https://yourx2.domain.com';

Setup should be done.   Reload your site, see if it still works.  If not, you broke something.  Also test out a console command and see if it still works.

  • NOTE:  In my custom console.php, I also have to have this line: unset($config['controllerMap']); // Fix weird error when running console commands.  Some where proConfig.php is getting included.
    • I'm not sure why... could be my servers setup... could be an x2engine bug.

Create a custom shortcode.php

  • Create a new file here: custom/protected/components/x2flow/shortcodes.php
  • Add the following contents to the shortcodes.php: 

/* pulling the "core" file so that if it changes, my tweaks will just be added to the end */
$originalFile = str_replace(DIRECTORY_SEPARATOR.'custom','',__FILE__);
$shortcodes = include($originalFile);

$myShortCodes = array(
    'twilioFormattedPhone'=> '
        $phoneUtil = \libphonenumber\PhoneNumberUtil::getInstance();
        try {
            $USnumberProto = $phoneUtil->parse($model->phone, "US");
            $formatedphone = $phoneUtil->format($USnumberProto, \libphonenumber\PhoneNumberFormat::E164);
            return $formatedphone;
        } catch (\libphonenumber\NumberParseException $e) {
            //@todo do something here??

return array_merge($shortcodes, $myShortCodes)

This basically adds any shortcodes we put in this file to the default shortcodes that are found here: protected/components/x2flow/shortcodes.php .   The above file adds the shortcode {twilioFormattedPhone}.  This is JUST for the contact field with the name of 'phone'.   I should note that if you use this on other entities (opportunities, accounts, etc...) it won't probably won't work.  If you have a contact field called something different than 'phone'... you can change where you see `$model->phone` above to `$model->yourphonefield'.


A {twilioFormattedPhone} shortcode will be replaced with a phone number formatted in a way that twilio likes.  


How to use it in x2flows


Use a remote api action like so:

Attached File  x2_send_sms_zapier.png   30.59KB   4 downloads


  1. The url provided by zapier
  2. our shortcode (the phone number formatted how twilio likes).
  3. our message that we want sent
  4. A key.  Used just so that other people can't use our zapier url to send SMS's to people.

Setup Zapier like so:


Attached File  x2_send_sms_zapier_zap.png   430.47KB   4 downloads

0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users