UNPKG

mnotify-ts-sdk

Version:

Third-Party TypeScript SDK for mNotify BMS API

218 lines (217 loc) 7.11 kB
import type { MNotifyClient } from "../client/MNotifyClient"; import { z } from "zod"; /** * Schema for validating SMS send responses * @property {string} status - 'success' or 'error' * @property {string} code - Response status code * @property {string} message - Human-readable response message * @property {object} summary - Detailed send summary * @property {string} summary._id - Internal campaign ID * @property {string} summary.message_id - Public message identifier * @property {string} summary.type - Message type * @property {number} summary.total_sent - Total messages successfully sent * @property {number} summary.contacts - Number of contacts targeted * @property {number} summary.total_rejected - Number of failed deliveries * @property {string[]} summary.numbers_sent - Array of numbers that received the message * @property {number} summary.credit_used - Credits consumed * @property {number} summary.credit_left - Remaining account balance */ export declare const SendSMSResponseSchema: z.ZodObject<{ status: z.ZodEnum<["success", "error"]>; code: z.ZodString; message: z.ZodString; summary: z.ZodObject<{ _id: z.ZodString; message_id: z.ZodString; type: z.ZodString; total_sent: z.ZodNumber; contacts: z.ZodNumber; total_rejected: z.ZodNumber; numbers_sent: z.ZodArray<z.ZodString, "many">; credit_used: z.ZodNumber; credit_left: z.ZodNumber; }, "strip", z.ZodTypeAny, { type: string; _id: string; message_id: string; total_sent: number; contacts: number; total_rejected: number; numbers_sent: string[]; credit_used: number; credit_left: number; }, { type: string; _id: string; message_id: string; total_sent: number; contacts: number; total_rejected: number; numbers_sent: string[]; credit_used: number; credit_left: number; }>; }, "strip", z.ZodTypeAny, { status: "success" | "error"; code: string; message: string; summary: { type: string; _id: string; message_id: string; total_sent: number; contacts: number; total_rejected: number; numbers_sent: string[]; credit_used: number; credit_left: number; }; }, { status: "success" | "error"; code: string; message: string; summary: { type: string; _id: string; message_id: string; total_sent: number; contacts: number; total_rejected: number; numbers_sent: string[]; credit_used: number; credit_left: number; }; }>; /** * Schema for validating SMS delivery reports * @property {string} status - 'success' or 'error' * @property {object[]} report - Array of delivery status objects * @property {number} report._id - Internal report ID * @property {string} report.recipient - Recipient phone number * @property {string} report.message - Message content * @property {string} report.sender - Sender ID * @property {string} report.status - Delivery status * @property {string} report.date_sent - ISO timestamp of send attempt * @property {string} [report.campaign_id] - Optional campaign identifier * @property {number} report.retries - Number of delivery attempts */ declare const SmsDeliveryReportSchema: z.ZodObject<{ status: z.ZodEnum<["success", "error"]>; report: z.ZodArray<z.ZodObject<{ _id: z.ZodNumber; recipient: z.ZodString; message: z.ZodString; sender: z.ZodString; status: z.ZodString; date_sent: z.ZodString; campaign_id: z.ZodOptional<z.ZodString>; retries: z.ZodNumber; }, "strip", z.ZodTypeAny, { status: string; message: string; _id: number; recipient: string; sender: string; date_sent: string; retries: number; campaign_id?: string | undefined; }, { status: string; message: string; _id: number; recipient: string; sender: string; date_sent: string; retries: number; campaign_id?: string | undefined; }>, "many">; }, "strip", z.ZodTypeAny, { status: "success" | "error"; report: { status: string; message: string; _id: number; recipient: string; sender: string; date_sent: string; retries: number; campaign_id?: string | undefined; }[]; }, { status: "success" | "error"; report: { status: string; message: string; _id: number; recipient: string; sender: string; date_sent: string; retries: number; campaign_id?: string | undefined; }[]; }>; /** * Response type for SMS send operations */ export type SendSMSResponse = z.infer<typeof SendSMSResponseSchema>; /** * Delivery report type for SMS status checks */ export type SmsDeliveryReport = z.infer<typeof SmsDeliveryReportSchema>; /** * 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 type 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 {MNotifyClient} client - Configured API client instance */ constructor(client: MNotifyClient); /** * Sends bulk SMS messages to one or more recipients * @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 * @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>; } export {};