Skip to content

Notifications: Twilio SMS provider #41

Description

@manoahLinks

Summary

Implement the Twilio SMS provider for sending ticket confirmations and critical alerts to Nigerian phone numbers (+234).

API Reference

  • Docs: https://www.twilio.com/docs/messaging/api
  • Endpoint: POST https://api.twilio.com/2010-04-01/Accounts/{AccountSid}/Messages.json
  • Auth: Basic auth with Account SID + Auth Token
  • From: Twilio phone number (configured in env)

SMS Templates

SMS messages must be concise (160 chars for single SMS, up to 1600 for concatenated).

Ticket Confirmation

HostIT: Your {ticketType} ticket for {eventName} is confirmed!
Ref: {reference}
Date: {date}
Venue: {venue}
View ticket: https://hostit.ng/tickets/{reference}

(~200 chars — 2 SMS segments)

Payment Failed

HostIT: Payment failed for {eventName}. Please try again: https://hostit.ng/events/{slug}

Implementation

// src/notifications/providers/twilio-sms.provider.ts

import * as twilio from 'twilio';

@Injectable()
export class TwilioSmsProvider {
  private client: twilio.Twilio;

  constructor(private configService: ConfigService) {
    this.client = twilio(
      this.configService.get('TWILIO_ACCOUNT_SID'),
      this.configService.get('TWILIO_AUTH_TOKEN'),
    );
  }

  async send(params: { to: string; body: string }): Promise<void> {
    await this.client.messages.create({
      to: params.to,        // +234XXXXXXXXXX
      from: this.configService.get('TWILIO_PHONE_NUMBER'),
      body: params.body,
    });
  }
}

Tasks

  • Install Twilio SDK: pnpm add twilio
  • Create src/notifications/providers/twilio-sms.provider.ts:
    • Initialize Twilio client with credentials from config
    • Implement send() with to and body
    • Validate phone number format (+234)
    • Handle Twilio API errors (invalid number, rate limit, insufficient balance)
  • Create SMS message templates:
    • renderSmsTemplate(type, data) → string
    • Keep within SMS length limits where possible
  • Add development fallback: log SMS to console in dev mode

Nigerian Phone Number Notes

  • Format: +234XXXXXXXXXX (13 chars total)
  • Remove leading 0 if user enters local format (0801... → +234801...)
  • Twilio supports Nigerian numbers on standard messaging

Acceptance Criteria

  • SMS sent via Twilio API to +234 numbers
  • Ticket confirmation SMS includes reference, event, venue, and link
  • Phone number validated before sending
  • Twilio errors handled gracefully (logged, notification marked FAILED)
  • Dev mode: SMS logged to console
  • Messages kept concise for cost efficiency

Metadata

Metadata

Assignees

No one assigned

    Labels

    notificationsEmail, SMS, and WhatsApp notificationsphase-7Phase 7: Notifications

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions