plazbot
Version:
Official Plazbot SDK for creating AI agents for WhatsApp, portals, and developers.
72 lines (71 loc) • 2.48 kB
JavaScript
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.Contact = void 0;
const http_1 = require("./http");
class Contact extends http_1.PlazbotHttp {
constructor(options) {
super(options);
}
async getContacts() {
const response = await this.http.get('/api/contact', {
params: { workspaceId: this.workspaceId },
});
this.throwIfError(response, 'Error retrieving contacts');
return response.data;
}
async getContact(id) {
if (!id) {
throw new Error("Contact ID is required.");
}
const response = await this.http.get(`/api/contact/${id}`, {
params: { workspaceId: this.workspaceId },
});
this.throwIfError(response, 'Error retrieving contact');
return response.data;
}
async searchByPhone(phone) {
const response = await this.http.get('/api/contact/searchByCellphone', {
params: { workspaceId: this.workspaceId, cellphone: phone },
});
this.throwIfError(response, 'Error searching contact by phone');
return response.data;
}
async searchByEmail(email) {
const response = await this.http.get('/api/contact/searchByEmail', {
params: { workspaceId: this.workspaceId, email },
});
this.throwIfError(response, 'Error searching contact by email');
return response.data;
}
async createContact(data) {
const body = {
workspaceId: this.workspaceId,
...data,
};
const response = await this.http.post('/api/contact', body);
this.throwIfError(response, 'Error creating contact');
return response.data;
}
async updateContact(data) {
if (!data.id) {
throw new Error("Contact ID is required to update.");
}
const body = {
workspaceId: this.workspaceId,
...data,
};
const response = await this.http.put('/api/contact', body);
this.throwIfError(response, 'Error updating contact');
return response.data;
}
async deleteContacts(ids) {
const body = {
workspaceId: this.workspaceId,
ids,
};
const response = await this.http.post('/api/contact/delete-batch', body);
this.throwIfError(response, 'Error deleting contacts');
return response.data;
}
}
exports.Contact = Contact;