feat: implement subscriber info retrieval
This commit is contained in:
parent
149a2f99c8
commit
a6eb4b904f
7 changed files with 110 additions and 11 deletions
|
|
@ -1,8 +1,19 @@
|
|||
const _ = require('lodash/fp')
|
||||
|
||||
exports.NAME = 'MockSMS'
|
||||
const NAME = 'MockSMS'
|
||||
|
||||
exports.sendMessage = function sendMessage (account, rec) {
|
||||
function getLookup (account, number) {
|
||||
console.log('Looking up number: %j', number)
|
||||
return new Promise((resolve, reject) => {
|
||||
if (_.endsWith('666', number)) {
|
||||
reject (new Error(`${exports.NAME} mocked error!`))
|
||||
} else {
|
||||
setTimeout(resolve, 1)
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
function sendMessage (account, rec) {
|
||||
console.log('Sending SMS: %j', rec)
|
||||
return new Promise((resolve, reject) => {
|
||||
if (_.endsWith('666', _.getOr(false, 'sms.toNumber', rec))) {
|
||||
|
|
@ -12,3 +23,9 @@ exports.sendMessage = function sendMessage (account, rec) {
|
|||
}
|
||||
})
|
||||
}
|
||||
|
||||
module.exports = {
|
||||
NAME,
|
||||
sendMessage,
|
||||
getLookup
|
||||
}
|
||||
|
|
|
|||
|
|
@ -37,7 +37,27 @@ function sendMessage (account, rec) {
|
|||
})
|
||||
}
|
||||
|
||||
function getLookup (account, number) {
|
||||
return Promise.resolve()
|
||||
.then(() => {
|
||||
const client = twilio(account.accountSid, account.authToken)
|
||||
return client.lookups.v1.phoneNumbers(number)
|
||||
.fetch({ addOns: ['lamassu_ekata'] })
|
||||
})
|
||||
.then(info => info.addOns.results['lamassu_ekata'])
|
||||
.catch(err => {
|
||||
if (_.includes(err.code, BAD_NUMBER_CODES)) {
|
||||
const badNumberError = new Error(err.message)
|
||||
badNumberError.name = 'BadNumberError'
|
||||
throw badNumberError
|
||||
}
|
||||
|
||||
throw new Error(`Twilio error: ${err.message}`)
|
||||
})
|
||||
}
|
||||
|
||||
module.exports = {
|
||||
NAME,
|
||||
sendMessage
|
||||
sendMessage,
|
||||
getLookup
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue