در زیر نحوه استفاده از متد PTPSms آورده شده است. برای اطلاع از عملکرد این متد و ورودی ها و خروجی های آن می توانید به بخش معرفی متدها PTPSms رجوع کنید.

شما می توانید با استفاده از کلاس پیشنهادی زیر و متدهای PtpSmsDictionary و یا  PtpSms  در برنامه خود عملیات ارسال پیام تک به تک را انجام دهید.

 - تابع PtpSmsDictionary برای دریافت تلفن ها و متن پیام ارسالی به هر تلفن  از شما یک دیکشنری دریافت می کند. در این دیکشنری کلید شماره تلفن و value متن پیام ارسالی به آن تلفن است.

- تابع PtpSms یک List از string  به عنوان لیست شماره تلفن ها و یک List از string  به عنوان متن های ارسالی از شما دریافت می کند و نظیر به نظیر پیام ها را به تلفن ها ارسال می کند.

{{:: 'controllers.documentation.chooseFramework' | translate }}
npm install --save niksms.library.javascript
import { ApiV1, LibOperationResultStatus, StringDictionary } from 'niksms'; export default class NikSmsApiV1Client{ private service: ApiV1 constructor(username: string, password: string, culture: string = "fa"){ this.service = new ApiV1(username, password, culture); } public async PtpSms( senderNumber: string, numbers: string[], messages: string[], sendOn?: Date | null, sendType?: number | null, yourMessageIds?: string[] ): Promise<string> { const result = await this.service.PtpSmsAsList(senderNumber, numbers, messages, sendOn, sendType, yourMessageIds); switch (result.Status) { case LibOperationResultStatus.Success: return result.Data; case LibOperationResultStatus.InvalidModel: throw new Error("Some required inputs are misssing..."); case LibOperationResultStatus.UnAuthorized: throw new Error("Some thing is wrong with your account (call support!)"); case LibOperationResultStatus.Failed: throw new Error("Ooops its our fault!"); default: throw new Error("You sould not be here... :D"); } } public async PtpSmsDictionary( senderNumber: string, recipients: StringDictionary<string>, sendOn?: Date | null, sendType?: number | null, yourMessageIds?: string[] ): Promise<string> { const result = await this.service.PtpSmsAsDictionary(senderNumber, recipients, sendOn, sendType, yourMessageIds); switch (result.Status) { case LibOperationResultStatus.Success: return result.Data; case LibOperationResultStatus.InvalidModel: throw new Error("Some required inputs are misssing..."); case LibOperationResultStatus.UnAuthorized: throw new Error("Some thing is wrong with your account (call support!)"); case LibOperationResultStatus.Failed: throw new Error("Ooops its our fault!"); default: throw new Error("You sould not be here... :D"); } } }