Skip to content

feat(#10846): add local_phone mustache helper to strip country code in SMS#10868

Open
megha1807 wants to merge 5 commits intomedic:masterfrom
megha1807:feature/10846-strip-country-code-sms-format
Open

feat(#10846): add local_phone mustache helper to strip country code in SMS#10868
megha1807 wants to merge 5 commits intomedic:masterfrom
megha1807:feature/10846-strip-country-code-sms-format

Conversation

@megha1807
Copy link
Copy Markdown
Contributor

@megha1807 megha1807 commented Apr 15, 2026

Description

Adds a new local_phone Mustache template helper to message-utils that strips the country code prefix from phone numbers in outgoing SMS messages.

This allows SMS message authors to render phone numbers in local format without modifying stored contact data.

Closes #10846

Usage example

Before: +9779841234567
After: 9841234567

Template syntax:
Contact {{#local_phone}}{{facility_phone}}{{/local_phone}} for help.

The helper reads default_country_code from app_settings. If the phone number starts with +{country_code}, the prefix is stripped. Otherwise the number is returned unchanged. Existing templates without this helper are completely unaffected.

AI Disclosure: I used Claude to understand the codebase structure and explore possible approaches for implementing the Mustache helper. The final implementation, testing, and refinements were done by me, and I verified the behavior with SMS workflows to ensure correctness and backward compatibility.

Code review checklist

  • UI/UX backwards compatible
  • Readable
  • Documented
  • Tested
  • Internationalised
  • Backwards compatible

@megha1807
Copy link
Copy Markdown
Contributor Author

megha1807 commented Apr 15, 2026

@binokaryg All 8 integration test failures are pre-existing flaky tests unrelated to this PR:

  • audit.spec.js - timing-sensitive count assertions
  • message-duplicates.spec.js - race condition in duplicate detection
  • sentinel-api-transitions.spec.js - transition count timing issues

None of these touch message-utils or the local_phone helper added in this PR.
The SMS workflow tests all pass. Ready for review.

@binokaryg
Copy link
Copy Markdown
Member

Thanks @megha1807, I will review this. I will retry the failing tests a few more times if needed.

Meanwhile, please make sure that you have gone through our AI guidelines for contributors.

@megha1807
Copy link
Copy Markdown
Contributor Author

Thanks @binokaryg!
Yes, I’ve gone through the AI Assistance Guidelines.

AI Disclosure: I used Claude to understand the codebase structure and explore possible approaches for implementing the Mustache helper. The final implementation, testing, and refinements were done by me, and I verified the behavior with SMS workflows to ensure correctness and backward compatibility.

Please let me know if any changes are needed.

@binokaryg
Copy link
Copy Markdown
Member

AI Disclosure: I used Claude to understand the codebase structure and explore possible approaches for implementing the Mustache helper. The final implementation, testing, and refinements were done by me, and I verified the behavior with SMS workflows to ensure correctness and backward compatibility.

Please let me know if any changes are needed.

Could you please add it to the PR description?

@megha1807
Copy link
Copy Markdown
Contributor Author

Thanks @binokaryg, I’ve added the AI disclosure to the PR description.

@binokaryg binokaryg self-requested a review April 15, 2026 03:44
Copy link
Copy Markdown
Member

@binokaryg binokaryg left a comment

Choose a reason for hiding this comment

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

Hi @megha1807, I think the implementation is good.

Could you please add the following scenarios to the tests?

Also a documentation for usage (separate PR on medic/cht-docs) would be helpful for users to discover and use this helper. Would you be able to do it?

@megha1807
Copy link
Copy Markdown
Contributor Author

Hi @binokaryg, thank you for reviewing this and for the helpful suggestions. I’ll add the requested test scenarios for numeric "default_country_code" and numbers already in local format.

I’ll also prepare a separate documentation PR in "medic/cht-docs" explaining the usage of this helper so it’s easier for users to discover and implement.

Thanks again - I’ll work on these updates shortly.

@megha1807
Copy link
Copy Markdown
Contributor Author

@binokaryg I've added both test cases:

  • numeric default_country_code (e.g. 977 instead of '977')
  • phone number already in local format (e.g. 9841234567)

Also updated stripCountryCode to handle numeric country codes via String() conversion.

I'll prepare the cht-docs PR for the usage documentation separately.

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.

Allow configuring phone number display format in outgoing SMS messages (strip country code)

2 participants