Skip to content

Instantly share code, notes, and snippets.

@annthurium annthurium/nomorobo.js

Last active Jun 28, 2019
Embed
What would you like to do?
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
You can’t perform that action at this time.