UNPKG

simple-sms-sender

Version:

Simple SMS sender to multiple recipients using Twilio

75 lines (70 loc) 2.49 kB
import { MessageInstance } from 'twilio/lib/rest/api/v2010/account/message.js'; declare type GenericLogger = { error: (...args: unknown[]) => void; info: (...args: unknown[]) => void; }; export { GenericLogger } export { GenericLogger as GenericLogger_alias_1 } declare type Message = { body: string; recipients: string[]; scheduledTime?: string; }; export { Message } export { Message as Message_alias_1 } /** * Represents a service for sending SMS messages using Twilio. */ declare class SmsSender { /** Twilio Account SID */ private accountSid; /** Twilio client instance */ private client; /** Sender's phone number */ private fromNumber; /** Logger for logging messages and errors */ private logger; /** Twilio SID */ private sid; /** Twilio secret */ private secret; /** * Creates an instance of SmsSender. * @param accountSid - Twilio Account SID. * @param fromNumber - Sender's phone number. * @param logger - Logger for logging messages and errors. * @param sid - Twilio SID. * @param secret - Twilio secret. */ constructor({ accountSid, fromNumber, logger, sid, secret }: { accountSid: string; fromNumber: string; logger: GenericLogger; sid: string; secret: string; }); /** * Sends an SMS message to a list of recipients. * @param body - The content of the SMS message. * @param recipients - Array of recipient phone numbers. * @param scheduledTime - Optional ISO 8601 formatted date/time to schedule the message. * @throws Will throw an error if the body or recipients are empty. * @returns A promise that resolves to an array of sent message objects. */ sendSms({ body, recipients, scheduledTime }: Message): Promise<(MessageInstance | undefined)[]>; /** * Sends multiple SMS messages. * @param messages - Array of messages to send. * @returns A promise that resolves to an array of sent message objects. */ sendMultipleSms(messages: Message[]): Promise<(MessageInstance | undefined)[][]>; /** * Validates the scheduled time format and ensures it's in the future. * @param scheduledTime - ISO 8601 formatted date/time string. * @throws Will throw an error if the format is invalid or time is in the past. */ private validateScheduledTime; } export { SmsSender } export { SmsSender as SmsSender_alias_1 } export { }