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:
In your LoopBack project:
$ npm install loopback-connector-primotexto
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 callback
Primotexto.send(options, function (err, res) {
});
// or with a Promise
Primotexto.send(options)
.then(function (res) {
})
.catch(function (err) {
});
Note: options
is defined by the JSON objects in the next two sections:
{
"type": "notification",
"receiver": "RECEIVER_PHONE_NUMBER",
"message": "TEXT_MESSAGE",
"sender": "YOUR_PHONE_NUMBER",
"campaignName": "CAMPAIN_NAME",
"category": "CATEGORY"
}
{
"type": "marketing",
"receiver": "RECEIVER_PHONE_NUMBER",
"message": "TEXT_MESSAGE",
"sender": "YOUR_PHONE_NUMBER",
"campaignName": "CAMPAIN_NAME",
"category": "CATEGORY"
}
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
- 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
We welcome your contributions! Thanks for helping make loopback-connector-primotexto a better project for everyone.
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
0.2.1
MIT Copyright (c) 2017 Yelloan