feat: implement subscriber info retrieval

This commit is contained in:
Sérgio Salgado 2021-08-05 01:26:05 +01:00 committed by Josh Harvey
parent 149a2f99c8
commit a6eb4b904f
7 changed files with 110 additions and 11 deletions

View file

@ -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
}