Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix Scrubber #2471

Merged
merged 5 commits into from
Oct 1, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading