Skip to content

Instantly share code, notes, and snippets.

@annthurium
Last active May 30, 2021 22:29
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save annthurium/f3662c5f72720763627fb77f05b9e661 to your computer and use it in GitHub Desktop.
Save annthurium/f3662c5f72720763627fb77f05b9e661 to your computer and use it in GitHub Desktop.
nomorobo.js
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