UNPKG

magfa-api

Version:

Magfa SMS API client for JS/TS/ESM/Node.js

152 lines (151 loc) 8.16 kB
/** * The Magfa API Class * @author Shahab Movahhedi * @see {@link https://shmovahhedi.com Shahab Movahhedi's Website} * @see {@link https://github.com/movahhedi/magfa-api magfa-api's Repository} * @license MIT */ export declare class Magfa { readonly apiUrl = "https://sms.magfa.com/api/http/sms/v2"; private username; private domain; private password; private from; private authHeader; constructor(username: string, password: string, domain: string, from: string); /** * Make an API request to the Magfa API * @private * @param {string} urlSuffix - The URL suffix for the API endpoint * @param {("GET"|"POST")} [method="GET"] - The HTTP method to use for the request * @param {object|null} [data=null] - The data to send with the request * @returns {Promise} The response from the API */ private Api; Send({ recipients, messages, encodings, uids, udhs, }: { recipients: string | string[]; messages: string | string[]; encodings?: Encoding | Encoding[]; uids?: number[]; udhs?: string[]; }): Promise<ISendResponseWithCount>; Statuses(mids: number[]): Promise<IMagfaResponse_Statuses>; Mid(uid: number): Promise<IMagfaResponse_Mid>; Balance(): Promise<IMagfaResponse_Balance>; ReceivedMessages(count?: number): Promise<IMagfaResponse_ReceivedMessages>; } export declare class MagfaError extends Error { status: keyof typeof magfaErrors | undefined; constructor(statusParam: number | undefined, messageParam?: string); } type IStatusCode = 0 | keyof typeof magfaErrors; interface IMagfaResponse_Base { status: IStatusCode; } interface IMagfaResponse_Balance extends IMagfaResponse_Base { balance: number | null; } interface IMagfaResponse_Send extends IMagfaResponse_Base { messages: ISentMessage[]; } interface IMagfaResponse_Statuses extends IMagfaResponse_Base { dlrs: { /** شناسه یکتای پیامک */ mid: number; /** وضعیت */ status: number; /** `yyyy-mm-dd hh:mm:ss` */ date: string; }[]; } interface IMagfaResponse_ReceivedMessages extends IMagfaResponse_Base { messages: { /** پیام */ body: string; /** فرستنده */ senderNumber: string; /** گیرنده */ recipientNumber: string; /** `yyyy-mm-dd hh:mm:ss` */ date: string; }[]; } interface IMagfaResponse_Mid extends IMagfaResponse_Base { mid: number | undefined; } interface ISendResponseWithCount extends IMagfaResponse_Send { count: { success: number; fail: number; }; } interface ISentMessage { /** نشانگر وضعیت درخواست. مقدار صفر به معنای انجام بدون خطای درخواست و هر عدد غیر از صفر کد خطای مربوطه است. */ status: IStatusCode; /** شناسه یکتای پیامک */ id: number; /** شناسه‌ی یکتای کاربر */ userId: number; /** تعداد بخش‌های پیامک */ parts: number; /** تعرفه */ tariff: number; /** `DEFAULT` for English (ASCII), `UCS2` for Persian */ alphabet: "DEFAULT" | "UCS2"; /** گیرنده */ recipient: string; } export declare const enum Encoding { /** تشخیص خودکار زبان پیامک (پیش فرض) */ Auto = 0, /** فارسی */ Persian = 2, /** 8bit */ EightBit = 5, /** Binary */ Binary = 6 } export declare function GetStatusText(status: number): any; export declare const magfaErrors: { readonly 1: "شماره گیرنده نادرست است"; readonly 2: "شماره فرستنده نادرست است"; readonly 3: "پارامتر encoding نامعتبر است. (بررسی صحت و هم‌خوانی متن پیامک با encoding انتخابی)"; readonly 4: "پارامتر mclass نامعتبر است"; readonly 6: "پارامتر UDH نامعتبر است"; readonly 13: "محتویات پیامک (ترکیب UDH و متن) خالی است. (بررسی دوباره‌ی متن پیامک و پارامتر UDH)"; readonly 14: "مانده اعتبار ریالی مورد نیاز برای ارسال پیامک کافی نیست"; readonly 15: "سرور در هنگام ارسال پیام مشغول برطرف نمودن ایراد داخلی بوده است. (ارسال مجدد درخواست)"; readonly 16: "حساب غیرفعال است. (تماس با واحد فروش سیستم‌های ارتباطی)"; readonly 17: "حساب منقضی شده است. (تماس با واحد فروش سیستم‌های ارتباطی)"; readonly 18: "نام کاربری و یا کلمه عبور نامعتبر است. (بررسی مجدد نام کاربری و کلمه عبور)"; readonly 19: "درخواست معتبر نیست. (ترکیب نام کاربری، رمز عبور و دامنه اشتباه است. تماس با واحد فروش برای دریافت کلمه عبور جدید)"; readonly 20: "شماره فرستنده به حساب تعلق ندارد"; readonly 22: "این سرویس برای حساب فعال نشده است"; readonly 23: "در حال حاضر امکان پردازش درخواست جدید وجود ندارد، لطفا دوباره سعی کنید. (ارسال مجدد درخواست)"; readonly 24: "شناسه پیامک معتبر نیست. (ممکن است شناسه پیامک اشتباه و یا متعلق به پیامکی باشد که بیش از یک روز از ارسال آن گذشته)"; readonly 25: "نام متد درخواستی معتبر نیست. (بررسی نگارش نام متد با توجه به بخش متدها در این راهنما)"; readonly 27: "شماره گیرنده در لیست سیاه اپراتور قرار دارد. (ارسال پیامک‌های تبلیغاتی برای این شماره امکان‌پذیر نیست)"; readonly 28: "شماره گیرنده، بر اساس پیش‌شماره در حال حاضر در مگفا مسدود است"; readonly 29: "آدرس IP مبدا، اجازه دسترسی به این سرویس را ندارد"; readonly 30: "تعداد بخش‌های پیامک بیش از حد مجاز استاندارد (۲۶۵ عدد) است"; readonly 31: "داده‌های موردنیاز برای ارسال کافی نیستند. (اصلاح HTTP Request)"; readonly 101: "طول آرایه پارامتر messageBodies با طول آرایه گیرندگان تطابق ندارد"; readonly 102: "طول آرایه پارامتر messageClass با طول آرایه گیرندگان تطابق ندارد"; readonly 103: "طول آرایه پارامتر senderNumbers با طول آرایه گیرندگان تطابق ندارد"; readonly 104: "طول آرایه پارامتر udhs با طول آرایه گیرندگان تطابق ندارد"; readonly 105: "طول آرایه پارامتر priorities با طول آرایه گیرندگان تطابق ندارد"; readonly 106: "آرایه‌ی گیرندگان خالی است"; readonly 107: "طول آرایه پارامتر گیرندگان بیشتر از طول مجاز است"; readonly 108: "آرایه‌ی فرستندگان خالی است"; readonly 109: "طول آرایه پارامتر encoding با طول آرایه گیرندگان تطابق ندارد"; readonly 110: "طول آرایه پارامتر checkingMessageIds با طول آرایه گیرندگان تطابق ندارد"; }; export declare const messageStatuses: { readonly [-1]: "شناسه موجود نیست (شناسه نادرست یا گذشت بیش از ۲۴ ساعت از ارسال پیامک)"; readonly 0: "وضعیتی دریافت نشده"; readonly 1: "رسیده به گوشی"; readonly 2: "نرسیده به گوشی"; readonly 8: "رسیده به مخابرات"; readonly 16: "نرسیده به مخابرات"; }; export default Magfa;