Skip to main content

SMS Templates

Where it lives
JSON Pointer: /smsTemplates
JSONPath: $.smsTemplates
Parent: Root of the metadata file

Overview

SMS Templates in SOLID allow you to create and manage SMS templates with dynamic content.

Example: SMS Templates Metadata

Below is an example of configuring an SMS template which sends an OTP when a user logs in.

SMS Templates Schema

{
..., // Other metadata
"smsTemplates": [
{
"name": "otp-on-login-custom",
"displayName": "Custom: Otp On Login",
"body": "otp-on-login-custom.handlebars.txt",
"description": "Send sms with OTP when logging in.",
"smsProviderTemplateId": "<TEMPLATE_ID_FROM_SMS_PROVIDER>",
"active": true,
"type": "text"
},

]
}

Example : SMS Template File

Below is an example of the content of the SMS template file otp-on-login-custom.handlebars.txt referenced in the above metadata. This file contains the actual SMS message with dynamic placeholders.

SMS Template File

Hi {{ firstName }}, Login to {{ solidAppName }}, using {{ mobileVerificationTokenOnLogin }} as your verification code.

Example : Sending SMS Using Template (TODO ticket)

Below is a code snippet demonstrating how to send an SMS using the defined SMS templates via the SmsServiceFactory. This example shows how to send an OTP verification SMS to a user.

SMS Sending Code Snippet

import { SmsServiceFactory } from 'your-sms-service';

async sendOtpSms(user: { mobile: string; firstName?: string; username: string, mobileVerificationTokenOnLogin: string }, otp: string) {
const smsService = SmsServiceFactory.getSmsService();

await smsService.sendSmsUsingTemplate(
user.mobile,
'otp-on-login',
{
solidAppName: process.env.SOLID_APP_NAME,
mobileVerificationTokenOnLogin: user.mobileVerificationTokenOnLogin,
firstName: user.username,
fullName: user.fullName ? user.fullName : user.username,
}
);

SMS Templates Metadata Attributes

name (string, required, unique)

Unique name for the sms template. It should be in kebab-case format (e.g., example-template-name).

displayName (string, required)

Display name for the sms template.

body (string, required)

  • In the metadata json, the filename of the sms template is specified. The templates are searched for in the module-metadata/<module-name>/sms-templates/ directory of the module.
  • The body is then replaced with the content of the sms template file. This will include plain text content. The body can include dynamic placeholders using Handlebars syntax (e.g., {{placeholderName}}), as shown in the SMS Template file above.

Further Reference

Info

Please refer to the Handlebars Documentation for more information on using Handlebars syntax in email templates.

smsProviderTemplateId (string, optional)

Unique identifier for the SMS template from the SMS provider (e.g., Twilio, Nexmo). This ID is used to reference the template when sending SMS messages through the provider's API.

description (string, optional)

A brief description of the SMS template.

active (boolean, optional)

Indicates whether the SMS template is active. Defaults to true.

type (string, optional)

Type of the SMS template. Currently supports text only.