verimor-api-sdk
Version:
A NodeJS SDK for the Verimor API
79 lines • 3.41 kB
JavaScript
;
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
return new (P || (P = Promise))(function (resolve, reject) {
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
step((generator = generator.apply(thisArg, _arguments || [])).next());
});
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.SmsApi = void 0;
const base_api_1 = require("./base-api");
const error_response_1 = require("../models/error-response");
const sms_utils_1 = require("../utils/sms-utils");
/**
* SmsApi class provides methods to interact with the SMS API.
*/
class SmsApi extends base_api_1.BaseApi {
/**
* Creates an instance of SmsApi.
* @param username - The API username.
* @param password - The API password.
* @param proxyConfig - Optional proxy configuration.
*/
constructor(username, password, proxyConfig) {
super(username, password, proxyConfig);
}
/**
* Sends SMS messages (single or multiple).
* @param smsRequest - The SMS request payload.
* @returns Promise resolving to SmsResponse.
* @throws ErrorResponse if the API call fails.
*/
sendSms(smsRequest) {
var _a;
return __awaiter(this, void 0, void 0, function* () {
try {
// Include credentials in the request body
const data = this.withCredentials(smsRequest);
const response = yield this.apiClient.post('/send.json', data);
return response.data;
}
catch (error) {
throw new error_response_1.ErrorResponse(((_a = error.response) === null || _a === void 0 ? void 0 : _a.data) || error.message);
}
});
}
/**
* Cancels a scheduled SMS campaign.
* @param campaignId - The ID of the campaign to cancel.
* @returns Promise resolving to a success message.
* @throws ErrorResponse if the API call fails.
*/
cancelScheduledMessage(campaignId) {
var _a;
return __awaiter(this, void 0, void 0, function* () {
try {
// Include credentials in the request body
const data = this.withCredentials({});
const response = yield this.apiClient.post(`/cancel/${campaignId}`, data);
return response.data;
}
catch (error) {
throw new error_response_1.ErrorResponse(((_a = error.response) === null || _a === void 0 ? void 0 : _a.data) || error.message);
}
});
}
/**
* Calculates the number of SMS credits required for the given message.
* @param message - The message content.
* @returns The number of SMS credits required.
*/
calculateSmsCredits(message) {
return sms_utils_1.SmsUtils.calculateSmsCredits(message);
}
}
exports.SmsApi = SmsApi;
//# sourceMappingURL=sms-api.js.map