Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

YODA-T-52: YODA-T-52: Add hashed number api to sms #128

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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`
Expand Down
60 changes: 60 additions & 0 deletions lib/sms.js
Original file line number Diff line number Diff line change
Expand Up @@ -189,6 +189,66 @@ class SMS {
return this._send(opts, false, true)
}

sendToMaskedNumber (params) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@nicholas-ngatia Why not keep the existing send() function and play on the passed 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) || {}
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -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": {
Expand Down
Loading