import Twilio from "twilio"; import config from "../config/config"; import { Environment } from "../const/environment"; import Logger from "wbb-logger"; const logger = new Logger("twilio.service.ts"); export default class TwilioService { private readonly accountSid: string; private readonly authToken: string; private readonly phoneNumber: string; private readonly clientName: string; private readonly twilio; constructor(accountSid, authToken) { this.accountSid = accountSid; this.authToken = authToken; this.twilio = Twilio(accountSid, authToken); } /** * @param body * @param from * @param to */ public sendSMS(body: string, from: string, to: string): void { if (config.environment === Environment.TEST) { return; } if (to.startsWith("0")) { // TODO this is hardcoded for uk numbers to = to.replace(/^0/, "+44"); } this.twilio.messages .create({ body, from, to, }) .catch((err) => logger.error(err)); } }