Skip to content

Commit

Permalink
Merge pull request #2471 from StateVoicesNational/re/twilio-lookup
Browse files Browse the repository at this point in the history
#2471 Fix Scrubber
  • Loading branch information
engelhartrueben authored Oct 1, 2024
2 parents 93d1041 + 3364e9b commit 2b8c7c5
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 12 deletions.
2 changes: 2 additions & 0 deletions src/extensions/service-managers/scrub-bad-mobilenums/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import { Jobs } from "../../../workers/job-processes";
import { Tasks } from "../../../workers/tasks";
import { jobRunner } from "../../job-runners";
import { getServiceFromOrganization } from "../../service-vendors";
import { log } from "../../../lib/log.js"
// / All functions are OPTIONAL EXCEPT metadata() and const name=.
// / DO NOT IMPLEMENT ANYTHING YOU WILL NOT USE -- the existence of a function adds behavior/UI (sometimes costly)

Expand Down Expand Up @@ -306,6 +307,7 @@ export async function nextBatchJobLookups({
lastCount,
steps
);
log.error("scrub-bad-mobilenums error: ", err);
await r
.knex("job_request")
.where("id", job.id)
Expand Down
26 changes: 14 additions & 12 deletions src/extensions/service-vendors/twilio/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -633,44 +633,46 @@ export async function getContactInfo({
return {};
}
const twilio = await exports.getTwilio(organization);
const types = ["carrier"];
const types = { fields: "line_type_intelligence" };
if (lookupName) {
// caller-name is more expensive
types.push("caller-name");
types.fields = "line_type_intelligence,caller-name";
}
const contactInfo = {
contact_number: contactNumber,
organization_id: organization.id,
service: "twilio"
};
try {
const phoneNumber = await twilio.lookups.v1
const phoneNumber = await twilio.lookups.v2
.phoneNumbers(contactNumber)
.fetch({ type: types });
.fetch(types);

if (phoneNumber.carrier) {
contactInfo.carrier = phoneNumber.carrier.name;
if (phoneNumber.lineTypeIntelligence.carrier_name) {
contactInfo.carrier = phoneNumber.lineTypeIntelligence.carrier_name;
}
if (phoneNumber.carrier.error_code) {
if (phoneNumber.lineTypeIntelligence.error_code) {
// e.g. 60600: Unprovisioned or Out of Coverage
contactInfo.status_code = -2;
contactInfo.last_error_code = phoneNumber.carrier.error_code;
contactInfo.last_error_code = phoneNumber.lineTypeIntelligence.error_code;
} else if (
phoneNumber.carrier.type &&
phoneNumber.carrier.type === "landline"
// mobile or landline
phoneNumber.lineTypeIntelligence.type &&
phoneNumber.lineTypeIntelligence.type === "landline"
) {
// landline (not mobile or voip)
contactInfo.status_code = -1;
} else if (
// example: US
phoneNumber.countryCode &&
getConfig("PHONE_NUMBER_COUNTRY", organization) &&
getConfig("PHONE_NUMBER_COUNTRY", organization) !==
phoneNumber.countryCode
) {
contactInfo.status_code = -3; // wrong country
} else if (
phoneNumber.carrier.type &&
phoneNumber.carrier.type !== "landline"
phoneNumber.lineTypeIntelligence.type &&
phoneNumber.lineTypeIntelligence.type !== "landline"
) {
// mobile, voip
contactInfo.status_code = 1;
Expand Down

0 comments on commit 2b8c7c5

Please sign in to comment.