Message Template Compilation
This chapter breaks down the compilation and structural interpolation of text messages using the `buildSmsTemplate` function. It details how transactional variables—such as localized currency formatting and explicit line-break architectures—are structurally managed to ensure clean, readable, and compliant handset layout presentations.
When delivering transactional receipts via cellular SMS, readability and visual layout directly impact the customer experience. Multi-line breaks, organized spacing, and clear currency isolation prevent textual clutter and help the customer immediately find critical payment variables (like the Receipt Number and Total Amount).
The Receipt Manager platform uses the buildSmsTemplate utility function to safely map raw data models into cleanly formatted multi-line notification texts.
Structural Specification & Data Mapping
The compilation engine expects a typed parameter object containing three specific fields:
customerName(string): The human-readable name or business moniker assigned to the payment account.amount(number): The numerical transaction payment amount. This is formatted inline usingtoLocaleString()to inject proper regional thousands separators (e.g.,10000turns into10,000).receiptNumber(string): The unique alpha-numeric tracking or transaction reference string generated by the database ledger.
Implementation Code Reference
The template engine relies on standard JavaScript Template Literals to enforce strict layout lines:
typescriptexport function buildSmsTemplate(params: {
customerName: string;
amount: number;
receiptNumber: string;
}): string {
return `Dear ${params.customerName},
We have received your payment of
KES ${params.amount.toLocaleString()}
Receipt No:
${params.receiptNumber}
Thank you.
Company Name`;
}
Handset Presentation Model
When compiled and transferred to a recipient's handset, the text resolves with explicit structural spacing as follows:
textDear John Doe, We have received your payment of KES 75,320 Receipt No: REC-2026-08942 Thank you. Company Name
Character Count & Multi-part SMS Considerations
When writing text templates for SMS gateways, it is critical to track character footprints to minimize per-message billing costs:
- GSM-7 encoding limits: A single standard text message can contain up to 160 characters.
- Concatenated Messages: If the combination of a long customer name and a receipt identifier pushes the final text beyond 160 characters, carriers split the text into a multi-part payload (billing for 2 or more messages), using 153-character blocks to account for user data headers (UDH).
- Optimization Note: To avoid unintended character duplication fees, use clean, concise names during payload creation.