loopback-connector-primotexto
Introduction
A Primotexto connector for LoopBack.
This connector is an adaptation of loopback-connector-twilio and loopback-connector-yunpian for primotexto API.
The connector supports the following aspects of the Primotexto REST API:
Installation
In your LoopBack project:
$ npm install loopback-connector-primotexto
Using the Connector
To use the connector, define the datasource using the connector in your datasources.json
file:
"primotexto": { "name": "primotexto", "connector": "loopback-connector-primotexto", "apiKey": "YOUR_PRIMOTEXTO_API_KEY"}
Next, attach the created datasource to a model in the model-config.json
file:
"Primotexto": { "dataSource": "primotexto", "public": true}
Now, using the created model, you can send a SMS using the send
method of the model:
// with a callbackPrimotexto.send(options, function (err, res) { }); // or with a PromisePrimotexto.send(options) .then(function (res) { }) .catch(function (err) { });
Note: options
is defined by the JSON objects in the next two sections:
Sending a notification SMS
{ "type": "notification", "receiver": "RECEIVER_PHONE_NUMBER", "message": "TEXT_MESSAGE", "sender": "YOUR_PHONE_NUMBER", "campaignName": "CAMPAIN_NAME", "category": "CATEGORY"}
Sending a marketing SMS
{ "type": "marketing", "receiver": "RECEIVER_PHONE_NUMBER", "message": "TEXT_MESSAGE", "sender": "YOUR_PHONE_NUMBER", "campaignName": "CAMPAIN_NAME", "category": "CATEGORY"}
Running the Example
To run the example in the /example/example.js
directory, you must set the following values in the file:
const apiKey = 'YOUR_PRIMOTEXTO_API_KEY'const receiver = 'RECEIVER_PHONE_NUMBER'const sender = 'SPC'
Next, from the from the /loopback-connector-primotexto/
directory, install the loopback
module using the following command:
$ npm install loopback
Finally, run the example app using the following command from the /loopback-connector-primotexto/
directory:
$ node ./example/example.js
Improvements
- Add to npmjs.com
- Plug with travis-ci
- Plug with coveralls.io
- Wrap the returned error codes in callback
- Improve verification of the input data in the Primotexto._internals.formatData
- Add functions to validate phone numbers with libphonenumber
Contributing
We welcome your contributions! Thanks for helping make loopback-connector-primotexto a better project for everyone.
Testing
To start the test from test/test.js
, use the following command :
$ npm test
You can also run code coverage with :
$ npm run-script cover
Version
0.2.1
License
MIT Copyright (c) 2017 Yelloan