UNPKG

mnotify-ts-sdk

Version:

Modern, zero-dependency TypeScript SDK for mNotify BMS API - Type-safe SMS, contacts, and account management with Railway-Oriented Programming

133 lines (132 loc) 4.53 kB
import type { HttpClient } from "../client/HttpClient"; import type { Result } from "../types/Result"; import { MNotifyError } from "../errors/MNotifyError"; /** * Response type for SMS send operations */ export interface SendSMSResponse { status: string; code: string; message: string; summary: { _id: string; message_id: string; type: string; total_sent: number; contacts: number; total_rejected: number; numbers_sent: string[]; credit_used: number; credit_left: number; }; } /** * Delivery report type for SMS status checks */ export interface SmsDeliveryReport { status: string; report: Array<{ _id: number; recipient: string; message: string; sender: string; status: string; date_sent: string; campaign_id?: string; retries: number; }>; } /** * Options for sending SMS messages * @property {string|string[]} recipient - Single number or array of numbers * @property {string} sender - Registered sender ID * @property {string} message - Content to send (160 chars max) * @property {boolean} [is_schedule=false] - Flag for scheduled messages * @property {string} [schedule_date] - ISO date for scheduled sends */ export interface SendSMSOptions { recipient: string | string[]; sender: string; message: string; is_schedule?: boolean; schedule_date?: string; } /** * Service for managing SMS operations with mNotify BMS API */ export declare class SMSService { private readonly client; /** * Creates an instance of SMSService * @param {HttpClient} client - Configured API client instance */ constructor(client: HttpClient); private annotate; /** * Sends bulk SMS messages to one or more recipients (railway-oriented programming) * @param {SendSMSOptions} options - SMS configuration * @returns {Promise<Result<SendSMSResponse, MNotifyError>>} Result containing send report or error * * @example * ```typescript * const result = await smsService.sendQuickBulkSMSSafe({ * recipient: ['233200000000', '233244444444'], * sender: 'MyApp', * message: 'Hello from mNotify!' * }); * * if (result.isOk()) { * console.log('SMS sent:', result.value); * } else { * console.error('Failed to send SMS:', result.error); * } * ``` */ sendQuickBulkSMSSafe(options: SendSMSOptions): Promise<Result<SendSMSResponse, MNotifyError>>; /** * Sends bulk SMS messages to one or more recipients (throws on error - legacy API) * @param {SendSMSOptions} options - SMS configuration * @returns {Promise<SendSMSResponse>} Detailed send report * @throws {MNotifyError} On API failure or validation errors * * @example * ```typescript * await smsService.sendQuickBulkSMS({ * recipient: ['233200000000', '233244444444'], * sender: 'MyApp', * message: 'Hello from mNotify!' * }); * ``` */ sendQuickBulkSMS(options: SendSMSOptions): Promise<SendSMSResponse>; /** * Retrieves delivery status for a sent SMS campaign (railway-oriented programming) * @param {string} campaignId - ID from send response * @param {string} [status='null'] - Optional status filter * @returns {Promise<Result<SmsDeliveryReport, MNotifyError>>} Result containing delivery report or error * * @example * ```typescript * const result = await smsService.getSMSStatusSafe('campaign_123'); * result.match({ * ok: (report) => console.log('Status:', report.status), * err: (error) => console.error('Error:', error.message) * }); * ``` */ getSMSStatusSafe(campaignId: string, status?: string): Promise<Result<SmsDeliveryReport, MNotifyError>>; /** * Retrieves delivery status for a sent SMS campaign (throws on error - legacy API) * @param {string} campaignId - ID from send response * @param {string} [status='null'] - Optional status filter * @returns {Promise<SmsDeliveryReport>} Detailed delivery report * @throws {MNotifyError} On API failure or invalid campaign ID * * @example * ```typescript * const report = await smsService.getSMSStatus('campaign_123'); * console.log(report.status); // 'delivered', 'failed', etc. * ``` */ getSMSStatus(campaignId: string, status?: string): Promise<SmsDeliveryReport>; }