@iletimerkezi/iletimerkezi-node
Version:
İleti Merkezi Node.js SDK
86 lines • 2.75 kB
JavaScript
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.SmsService = void 0;
const SmsResponse_1 = require("../responses/SmsResponse");
class SmsService {
constructor(httpClient, apiKey, apiHash, defaultSender) {
this.httpClient = httpClient;
this.apiKey = apiKey;
this.apiHash = apiHash;
this.defaultSender = defaultSender;
this.sendDateTime = '';
this.iys = 1;
this.iysList = 'BIREYSEL';
}
schedule(sendDateTime) {
this.sendDateTime = sendDateTime;
return this;
}
enableIysConsent() {
this.iys = 1;
return this;
}
disableIysConsent() {
this.iys = 0;
return this;
}
setIysList(iysList) {
this.iysList = iysList;
return this;
}
async send(recipients, message, sender) {
const payload = {
request: {
authentication: {
key: this.apiKey,
hash: this.apiHash
},
order: {
sender: sender || this.defaultSender,
sendDateTime: this.sendDateTime,
iys: this.iys,
iysList: this.iysList,
message: this.buildMessages(recipients, message)
}
}
};
const response = await this.httpClient.post('send-sms/json', payload);
return new SmsResponse_1.SmsResponse(response.getBody(), response.getStatusCode());
}
buildMessages(recipients, message) {
// Tek numara ve mesaj durumu
if (typeof recipients === 'string') {
return {
text: message,
receipents: {
number: [recipients]
}
};
}
// Numara array'i ve tek mesaj durumu
if (Array.isArray(recipients) && message !== undefined) {
return {
text: message,
receipents: {
number: recipients
}
};
}
// Her numaraya farklı mesaj gönderme durumu
if (!Array.isArray(recipients) && typeof recipients === 'object' && message === undefined) {
const messages = [];
for (const [number, text] of Object.entries(recipients)) {
messages.push({
text: text,
receipents: {
number: [number]
}
});
}
return messages;
}
throw new Error('Invalid recipients or message format.');
}
}
exports.SmsService = SmsService;
//# sourceMappingURL=SmsService.js.map