feature/IO-3182-Phone-Number-Consent - Checkpoint
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
const twilio = require("twilio");
|
||||
const { phone } = require("phone");
|
||||
const { INSERT_MESSAGE, GET_PHONE_NUMBER_CONSENT } = require("../graphql-client/queries");
|
||||
const { INSERT_MESSAGE } = require("../graphql-client/queries");
|
||||
const client = twilio(process.env.TWILIO_AUTH_TOKEN, process.env.TWILIO_AUTH_KEY);
|
||||
const gqlClient = require("../graphql-client/graphql-client").client;
|
||||
|
||||
@@ -42,30 +42,6 @@ const send = async (req, res) => {
|
||||
}
|
||||
|
||||
try {
|
||||
// Check bodyshop's enforce_sms_consent setting
|
||||
const bodyShopData = await getBodyshopFromRedis(bodyshopid);
|
||||
const enforceConsent = bodyShopData?.enforce_sms_consent ?? false;
|
||||
|
||||
// Check consent only if enforcement is enabled
|
||||
if (enforceConsent) {
|
||||
const normalizedPhone = phone(to, "CA").phoneNumber.replace(/^\+1/, "");
|
||||
const consentResponse = await gqlClient.request(GET_PHONE_NUMBER_CONSENT, {
|
||||
bodyshopid,
|
||||
phone_number: normalizedPhone
|
||||
});
|
||||
if (!consentResponse.phone_number_consent?.length || !consentResponse.phone_number_consent[0].consent_status) {
|
||||
logger.log("sms-outbound-error", "ERROR", req.user.email, null, {
|
||||
type: "no-consent",
|
||||
phone_number: normalizedPhone,
|
||||
conversationid
|
||||
});
|
||||
return res.status(403).json({
|
||||
success: false,
|
||||
message: "Phone number has not consented to messaging."
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
const message = await client.messages.create({
|
||||
body,
|
||||
messagingServiceSid,
|
||||
|
||||
Reference in New Issue
Block a user