Skip to content

task(recovery-phone, auth): Allow for fallback sms messages#18433

Merged
vpomerleau merged 1 commit intomainfrom
FXA-11072
Feb 26, 2025
Merged

task(recovery-phone, auth): Allow for fallback sms messages#18433
vpomerleau merged 1 commit intomainfrom
FXA-11072

Conversation

@dschom
Copy link
Copy Markdown
Contributor

@dschom dschom commented Feb 22, 2025

Because

  • We want the messages we send out to be under one gsm segment in length
  • Length isn't straightforwards. It varies based on encoding.
  • Language translation may impact length.

This pull request

  • Adds fallback messages for 'formatted messages'
  • Adds ability to determine SMS segment length
  • Removes some stray logs found in session.js
  • Changes config to specify max segment length
  • Makes getFormattedMessages a required parameter

Issue that this pull request solves

Closes: FXA-11072

Checklist

Put an x in the boxes that apply

  • My commit is GPG signed.
  • If applicable, I have modified or added tests which pass locally.
  • I have added necessary documentation (if appropriate).
  • I have verified that my changes render correctly in RTL (if appropriate).

Screenshots (Optional)

Please attach the screenshots of the changes made in case of change in user interface.

Other information (Optional)

Any other information that is important to this pull request.

@dschom dschom requested a review from a team as a code owner February 22, 2025 02:11
@dschom dschom requested a review from vpomerleau February 22, 2025 02:12
});

it('Should setup a phone number', async () => {
it.only('Should setup a phone number', async () => {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Stray .only

};
const mockGetFormattedMessage = async (code: string) => {
return {
msg: `${code} is your Mozilla verification code. Expires in 5 minutes.`,
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe I'm over thinking but I wonder if we need to include the expiration. The expiration is on the webpage. For reference Twilio sends this message, Your Twilio verification code is: 859440 and does not include expiration time. In this case, the text lenght would be rough 40 characters so the risk for translations being over 160 would be much lower.

? `${code} is your Mozilla verification code. Expires in 5 minutes.`
: `${code} is your Mozilla recovery code. Expires in 5 minutes.`;
const l10nTypeMap = {
setup: {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I do really like the flexibility of this 👍🏽

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is much nicer 👍

Comment thread packages/fxa-auth-server/lib/routes/recovery-phone.ts
@vbudhram vbudhram force-pushed the FXA-11072 branch 2 times, most recently from 1caa3ee to 82915e3 Compare February 24, 2025 21:03
@vbudhram vbudhram requested a review from a team as a code owner February 24, 2025 21:03
@vbudhram vbudhram requested a review from vpomerleau February 24, 2025 21:05
Copy link
Copy Markdown
Contributor

@vbudhram vbudhram left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I had to resolve some merge conflicts on main, but made the recommended changes. Wouldn't hurt to have another set of eyes.

Copy link
Copy Markdown
Contributor

@bcolsson bcolsson left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These strings should still probably use the brand term

# https://twiliodeved.github.io/message-segment-calculator/
# Messages should be limited to one segment
# $code - 6 digit code used to verify phone ownership when registering a recovery phone
recovery-phone-setup-sms-short-body = Mozilla verification code: ${code}
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should use the brand term for Mozilla. Additionally - placeholders should be formatted as { $variable }

# https://twiliodeved.github.io/message-segment-calculator/
# Messages should be limited to one segment
# $code - 6 digit code used to verify phone ownership when registering a recovery phone
recovery-phone-setup-sms-short-body = Mozilla code: ${code} No newline at end of file
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should use the brand term for Mozilla. Additionally - placeholders should be formatted as { $variable }

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Id should be recovery-phone-signin-sms-short-body.

Copy link
Copy Markdown
Contributor

@vpomerleau vpomerleau left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Spotted a ftl id mismatch, other comments are mainly questions/nits that are not blocking.

env: 'RECOVERY_PHONE__SMS__MAX_MESSAGE_LENGTH',
maxMessageSegmentLength: {
default: 1,
doc: 'Max allows sms message segment length',
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit

Suggested change
doc: 'Max allows sms message segment length',
doc: 'Max allowed sms message segment length',

# https://twiliodeved.github.io/message-segment-calculator/
# Messages should be limited to one segment
# $code - 6 digit code used to verify phone ownership when registering a recovery phone
recovery-phone-setup-sms-short-body = Mozilla code: ${code} No newline at end of file
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Id should be recovery-phone-signin-sms-short-body.

? `${code} is your Mozilla verification code. Expires in 5 minutes.`
: `${code} is your Mozilla recovery code. Expires in 5 minutes.`;
const l10nTypeMap = {
setup: {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is much nicer 👍

return {
msg: localizedMessage,
shortMsg: shortLocalizedMessage,
failsafeMsg: `Mozilla: ${code}`,
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Using this failsafe all the time would save a lot of trouble 😅

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

😓

it('handles message template when provided to set up phone number', async () => {
mockOtpManager.generateCode.mockReturnValue(code);
const getFormattedMessage = jest.fn().mockResolvedValue('message');
// const getFormattedMessage = jest.fn().mockResolvedValue('message');
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Delete this line?

'${code} is your Mozilla recovery code. Expires in 5 minutes.',
},
'signin-short': {
id: 'recovery-phone-setup-sms-short-body',
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
id: 'recovery-phone-setup-sms-short-body',
id: 'recovery-phone-signin-sms-short-body',

# https://twiliodeved.github.io/message-segment-calculator/
# Messages should be limited to one segment
# $code - 6 digit code used to verify phone ownership when registering a recovery phone
recovery-phone-setup-sms-short-body = { -brand-mozilla } code: { $code } No newline at end of file
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
recovery-phone-setup-sms-short-body = { -brand-mozilla } code: { $code }
recovery-phone-signin-sms-short-body = { -brand-mozilla } code: { $code }

# Shorter message sent by SMS with limited character length, please test translation with the messaging segment calculator
# https://twiliodeved.github.io/message-segment-calculator/
# Messages should be limited to one segment
# $code - 6 digit code used to verify phone ownership when registering a recovery phone
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
# $code - 6 digit code used to verify phone ownership when registering a recovery phone
# $code - 6 digit code used to sign in with a recovery phone as backup for two-step authentication

// Pick the message with the best length and send it
const formattedMessages = await getFormattedMessages(code);
const body = this.getSafeSmsBody(formattedMessages);
const msg = await this.smsManager.sendSMS({
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should this be wrapped in a try/catch block to prevent MessageBodyTooLong errors (though unlikely) from bubbling up to the user?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'll punt on that for now, maybe ok to fail hard and fast here.

Because:
- We want the messages we send out to be under one gsm segment in length
- Length isn't straightforwards. It varies based on encoding.
- Language translation may impact length.

This Commit:
- Adds fallbacks for 'formatted messages'
- Adds ability to determine sms segment length
- Removes some stray logs found in session.js
- Changes config to specify max segment length
@vpomerleau vpomerleau merged commit fed0072 into main Feb 26, 2025
@vpomerleau vpomerleau deleted the FXA-11072 branch February 26, 2025 00:23
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants