@journeyapps-solutions/cc-twilio
v1.0.1
Published
Twilio wrapper
Downloads
452
Keywords
Readme
cc-twilio
This is a wrapping class for twilio SMS This will enable Cloud Code to send a sms safely in the enviroment.
@see https://www.twilio.com/docs/libraries/node
Documentation
All code is clearly documented, please see code for more details. View an example below.
Installation
Per machine
# Once as setup
npm login
> journeyapps-solutions-user
> see password on 1Password
> [email protected]
yarn add @journeyapps-solutions/cc-sendgrid --savePer CloudCode app
NPM_TOKEN=... # Token for journeyapps-solutions-user from 1Password
echo "//registry.npmjs.org/:_authToken=$NPM_TOKEN" > ./app/cloudcode/.npmrcPer CloudCode task
yarn add @journeyapps-solutions/cc-sendgridDeploying
yarn versionUsage
Environment Variables
The send function will check the environment in which it is running by using the config.env variable passed in on the constructor. Default environment is 'testing'.
Note:
- In testing and staging it will only send sms to numbers in the whitelist.
- In production it will not filter any mails.
To add a whitelist number, see example below
Constructing a SMS
cc-twilio is essentially a wrapper for the twilio node module. We add some validation and reporting. That being said, to construct a sms, you can directly follow the twilio documentation:
https://www.twilio.com/docs/libraries/node
Cloud Code:
config.js:
// Credentials used
let config = {};
config.accountSid = '<something>';
config.authToken = '<something>';
config.textFrom = '<something>'; // This needs to be the twilio from number from journeys twilio account
config.whiteList : ['+27741234567'];
index.js:
// make sure config.js has the relevant credentials
const config = require('./config');
const ccTwilio = require('@journeyapps-solutions/cc-twilio');
export async function run() {
let _twilio = new ccTwilio(config.accountSid, config.authToken, config.textFrom, CloudCode.task.env, config.whiteList);
try {
await _twilio.sms(['+27741413459'], "This is a twilio Unit Test, test message. Please ignore.");
} catch(error) {
log.error(error);
//ROLLBAR HERE
}
}Testing
To test the module tape is used.
yarn test