MFA SMS Leading Zero

Continuing the discussion from A leading zero in user's phone number for MFA causing the message to fail to send: which relied on hooks as a solution.

This same issue still exists. Are there any recommended fixes? If not, can actions be used?

If using actions, is there a way to set the recipient phone number in the action?

e.g.

const pnf = require('google-libphonenumber').PhoneNumberFormat;
const phoneUtil = require('google-libphonenumber').PhoneNumberUtil.getInstance();

exports.onExecuteSendPhoneMessage = async (event, api) => {
    const enteredNum = phoneUtil.parse(event.message_options.recipient);
    ** [set the recipient phone number here, is this possible?] = phoneUtil.format(enteredNum, pnf.E164);  
};

Would one of the inbuilt set functions work maybe? event.message_options.recipient.set*

Hi @Kush1,

Yes, you can most definitely use a Send Phone Message Action to set the recipient phone number.

Since Hooks have been deprecated, here is the converted script in an Action:

exports.onExecuteSendPhoneMessage = async (event, api) => {
  // Start formatting code
  
  const PNF = require('google-libphonenumber').PhoneNumberFormat;
  const phoneUtil = require('google-libphonenumber').PhoneNumberUtil.getInstance();
  
  // // Load recipient into the phone number object.
  let enteredNum = phoneUtil.parse(event.message_options.recipient);
  // // E.164 format recipient
  let e164Num = phoneUtil.format(enteredNum, PNF.E164);
  
  // End formatting code
  
  // Not shown: Call Phone message provider as normal using the value of e164Num instead of recipient.
  
  // Assuming that your message sending logic is synchronous or wrapped in a Promise,
  // you can just await on it here. Example:
  // await sendMessage(e164Num, event.message);
  
  // In an Action, there is no need to explicitly return a success response like in Hooks,
  // unless you wish to terminate the Action execution under certain conditions.
};

Let me know if you have any questions.

Thanks,
Rueben

Thanks Rueben. Since I’m using the Esendex plugin to send the SMS message from the marketplace, I was hoping I was able to format the recipient in the flow before Esendex kicked in, in the next stage. Maybe I need to not use the Esendex plugin, and create an action to use Esendex in the action and hence pass the E.164 number?

Hi @Kush1,

Yes, that’s correct. When using the Esendex integration, there is no option to manipulate the recipient phone number before sending the SMS message.

Because of that, you can use Esendex in an Action and pass in the correct recipient phone number without any leading zeros.

I haven’t come across any examples for this, but you could explore implementing it to see if it works for your use case.

Cheers,
Rueben

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.