UNPKG

node-easysms

Version:

EasySMS is an SMS sender for Node.js

80 lines (79 loc) 2.44 kB
import { AxiosInstance } from "axios"; import { Config } from "./Config"; import { Gateway } from "./Gateway"; import { Message } from "./Message"; import { Messenger } from "./Messenger"; import { PhoneNumber } from "./PhoneNumber"; /** * EasySms */ export declare class EasySms { protected config: Config; protected customCreators: CustomGatewayCreators; protected createdGateways: CreatedGateways; protected supportGateways: SupportGateways; protected messenger: Messenger; protected httpClient: AxiosInstance; constructor(config: EasySmsConfig); /** * 获取请求客户端 * @returns */ getHttpClient(): AxiosInstance; /** * 设置请求客户端 * @param instance * @returns */ setHttpClient(instance: AxiosInstance): this; /** * 设置配置 * @param config * @returns */ setConfig(config: EasySmsConfig): this; /** * 设置发送器 * @param messenger * @returns */ setMessenger(messenger: Messenger): this; /** * 获取发送器 * @returns */ getMessenger(): Messenger; /** * 扩展自定义网关 * @param name * @param func * @returns */ extend(name: string, func: GatewayCreator | GatewayConstructable): this; /** * 获取网关实例 * @param name 网关标识 * @returns */ gateway(name: string): Gateway; /** * 获取或设置网关策略,并返回可执行方法 * @param strategy * @returns */ strategy(strategy?: 'order' | 'random' | MessengerStrategyClosure): (gateways: string[]) => string[]; /** * 发送短信 * @param to 电话 * @param message 消息 * @param gateways 网关标识列表,默认去 default.gateways 配置 * @returns */ send(to: string | PhoneNumber, message: string | MessageProperty | Message, gateways?: string[]): Promise<MessengerResult[]>; protected createGateway(name: string): Gateway<GatewayConfig>; protected buildGateway(className: GatewayConstructable, config: GatewayConfig): Gateway; protected callCustomCreator(name: string, config: GatewayConfig): Gateway; protected formatPhoneNumber(number: string | PhoneNumber): PhoneNumber; protected formatMessage(message: string | MessageProperty | Message): Message; protected formatGateways(gateways: string[]): string[]; }