Last active
May 30, 2021 22:29
-
-
Save annthurium/f3662c5f72720763627fb77f05b9e661 to your computer and use it in GitHub Desktop.
nomorobo.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const client = require('twilio')(process.env.TWILIO_ACCOUNT_SID, process.env.TWILIO_AUTH_TOKEN); | |
/** | |
* Detect whether a number is a robo caller. | |
* | |
* @param {string} phoneNumber - The number the call is coming from. in e.164 format | |
* @return {Promise<boolean>} true if the number belongs to a robocaller | |
* | |
*/ | |
async function isRoboCaller(phoneNumber) { | |
try { | |
const response = await client | |
.lookups.phoneNumbers(phoneNumber) | |
.fetch({addOns: 'nomorobo_spamscore'}); | |
const score = response.addOns.results.nomorobo_spamscore.result.score; | |
return score === 1; | |
} catch (error) { | |
console.log(error); | |
return null; | |
} | |
}; | |
if (process.argv.length < 3) { | |
console.log('Please provide a phone number in E.164 format like this: +19892008374'); | |
return; | |
} | |
const number = process.argv[2]; | |
isRoboCaller(number).then(result => { | |
if (result !== null) { | |
console.log(`${number} is a robocaller: ${result}`); | |
} | |
}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment