plazbot
Version:
Official Plazbot SDK for creating AI agents for WhatsApp, portals, and developers.
40 lines (39 loc) • 1.44 kB
JavaScript
;
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.PlazbotHttp = void 0;
const axios_1 = __importDefault(require("axios"));
class PlazbotHttp {
constructor(options) {
if (!options.workspaceId) {
throw new Error("workspaceId is required.");
}
if (!options.apiKey) {
throw new Error("apiKey is required.");
}
this.workspaceId = options.workspaceId;
this.apiKey = options.apiKey;
const zone = options.zone ?? "LA";
if (zone !== "EU" && zone !== "LA") {
throw new Error("Invalid zone. Must be 'EU' or 'LA'.");
}
this.baseUrl = options.customUrl
?? (zone === "EU" ? "https://apieu.plazbot.com" : "https://api.plazbot.com");
this.http = axios_1.default.create({
baseURL: this.baseUrl,
headers: {
'Content-Type': 'application/json',
'Authorization': `Bearer ${this.apiKey}`,
'x-workspace-id': this.workspaceId,
},
});
}
throwIfError(response, context) {
if (response.status < 200 || response.status >= 300) {
throw new Error(`${context}: ${response.statusText}`);
}
}
}
exports.PlazbotHttp = PlazbotHttp;