Pro tier (post-launch) provides dedicated 10DLC numbers with custom message sending.
Template Benefits (All Tiers)
Save time - Pre-written messages for common scenarios
Type-safe - Full TypeScript support with auto-completion
Validated - Runtime validation catches errors before sending
Compliance-ready - 10DLC campaign metadata included
SMS-optimized - Character counting and segment calculation built-in
Installation
Code
npm install @relay-works/templates
Quick Start
Code
const { getTemplate, renderTemplate } = require('@relay-works/templates');// Get a templateconst otpTemplate = getTemplate('otp-verify');// Render with your dataconst result = renderTemplate(otpTemplate, { code: '482916', company: 'Acme'});console.log(result.text);// "482916 is your Acme verification code."console.log(result.segments);// 1
Available Templates
Authentication Templates (4)
OTP Verification
Send one-time password codes for 2FA.
Code
const template = getTemplate('otp-verify');const result = renderTemplate(template, { code: '482916', company: 'Acme'});// "482916 is your Acme verification code."
Variables:
code (string) - 6-digit verification code
company (string) - Your company name
Best for: Two-factor authentication, login verification, account verification
Password Reset
Send password reset links with expiration time.
Code
const template = getTemplate('password-reset');const result = renderTemplate(template, { company: 'Acme', url: 'https://relay.link/rst-x7k', minutes: 15});// "Reset your Acme password: https://relay.link/rst-x7k. Link expires in 15 min."
Variables:
company (string) - Your company name
url (string) - Password reset URL (use short links)
minutes (number) - Expiration time in minutes
Best for: Password recovery, account access restoration
New Login Alert
Notify users of new login from unrecognized device.
Code
const template = getTemplate('new-login-alert');const result = renderTemplate(template, { company: 'Acme', location: 'New York, NY', device: 'iPhone 15', url: 'https://relay.link/secure'});// "New login to your Acme account from iPhone 15 in New York, NY. Not you? Secure account: https://relay.link/secure"
Variables:
company (string) - Your company name
location (string) - City and state/country
device (string) - Device name
url (string) - Security action URL
Best for: Security notifications, suspicious activity alerts
Account Security Alert
Generic security notification for account changes.
Send appointment reminders with confirmation option.
Code
const template = getTemplate('appointment-reminder');const result = renderTemplate(template, { company: 'Acme Clinic', date: 'Jan 15', time: '2:00 PM', location: 'Downtown Office', confirmUrl: 'https://relay.link/confirm'});// "Reminder: Your Acme Clinic appointment is Jan 15 at 2:00 PM at Downtown Office. Confirm: https://relay.link/confirm"
Variables:
company (string) - Your business name
date (string) - Appointment date (keep short)
time (string) - Appointment time
location (string) - Location name
confirmUrl (string) - Confirmation URL
Best for: Appointment reminders, booking confirmations, calendar events
Validation
Templates include built-in validation to catch errors before sending.
Code
const { validateTemplateData } = require('@relay-works/templates');const template = getTemplate('otp-verify');// Validate your dataconst validation = validateTemplateData(template, { code: '123', // Too short! company: 'A'.repeat(50) // Too long!});if (!validation.valid) { validation.errors.forEach(error => { console.log(`${error.field}: ${error.message}`); console.log(`Suggestion: ${error.suggestion}`); });}// Output:// code: Must be exactly 6 characters// Suggestion: Use a 6-digit verification code// company: Must be 20 characters or less// Suggestion: Use a shorter company name or abbreviation
Sending Templates with Relay
Starter Tier: This is Your Primary API
For Starter tier users, the template API (sendTypedTemplate / POST /v1/messages/send-template) is the only way to send messages. The examples below are not optional - they are required.
const { templates, getTemplatesByCategory, getTemplatesByTag, searchTemplates} from '@relay-works/templates';// All templatesconsole.log(`${templates.length} templates available`);// Get by categoryconst authTemplates = getTemplatesByCategory('authentication');console.log(`${authTemplates.length} auth templates`);// Get by tagconst securityTemplates = getTemplatesByTag('security');// Searchconst passwordTemplates = searchTemplates('password');