diff --git a/README.md b/README.md index 911f6eef..b2fe8b5d 100644 --- a/README.md +++ b/README.md @@ -92,10 +92,16 @@ All phone numbers use the international format. e.g. `+234xxxxxxxx`. - `sendPremium({ to, from, message, enqueue, keyword, linkId, retryDurationInHours })`: Send premium SMS - - `keyword`: You premium product keyword + - `keyword`: Your premium product keyword - `linkId`: We forward the `linkId` to your application when the user send a message to your service - `retryDurationInHours`: It specifies the number of hours your subscription message should be retried in case it's not delivered to the subscriber +- `sendToMaskedNumber({ message, telco, senderId, maskedNumber })`: Send SMS to hashed number + + - `telco`: The telco provider + - `senderId`: Your sender id + - `maskedNumber`: The hashed number provided by the telco + - `fetchMessages({ lastReceivedId })`: Manually retrieve your messages - `lastReceivedId`: "This is the id of the message that you last processed". Defaults to `0` diff --git a/lib/sms.js b/lib/sms.js index b8cd78a7..2856b633 100644 --- a/lib/sms.js +++ b/lib/sms.js @@ -189,6 +189,66 @@ class SMS { return this._send(opts, false, true) } + sendToMaskedNumber (params) { + const _self = this + const opts = _.cloneDeep(params) || {} + const constraints = { + message: { + presence: true, + isString: true + }, + telco: { + presence: true, + isString: true + }, + maskedNumber: { + presence: true, + isString: true + }, + senderId: { + presence: true, + isString: true + } + } + const validationError = validate(opts, constraints) + const body = { + username: _self.options.username, + message: opts.message, + maskedNumber: opts.maskedNumber, + telco: opts.telco, + senderId: opts.senderId, + phoneNumbers: [] + } + return new Promise(function (resolve, reject) { + if (validationError) { + return reject(validationError) + } + + const url = `${Common.SMS_URL}/messaging/bulk` + const headers = { + apikey: _self.options.apiKey, + Accept: _self.options.format + } + + axios({ + method: 'POST', + url, + headers, + data: new URLSearchParams(body) + }) + .then(function (response) { + if (response.status === 201) { + resolve(response.data) + } else { + reject(response.data) + } + }) + .catch(function (error) { + reject(error) + }) + }) + } + fetchMessages = function (params) { const _self = this const opts = _.cloneDeep(params) || {} diff --git a/package.json b/package.json index b0702e50..3cb09e4c 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "africastalking", - "version": "0.7.0", + "version": "0.7.0-beta.3", "description": "Official AfricasTalking node.js API wrapper", "main": "index.js", "scripts": {