diff --git a/CLIENT_README.md b/CLIENT_README.md index 1f5247f..f727d54 100644 --- a/CLIENT_README.md +++ b/CLIENT_README.md @@ -31,7 +31,7 @@ bun add whatsapp-cloud-api-types ## Inicio Rápido ```typescript -import { WhatsAppCloudAPI } from 'whatsapp-cloud-api-types/client' +import { WhatsAppCloudAPI } from 'whatsapp-cloud-api-types' // Inicializar el cliente const client = new WhatsAppCloudAPI({ @@ -907,7 +907,7 @@ await client.webhooks.unsubscribe('waba-id') El cliente utiliza la clase personalizada `WhatsAppApiError` para errores de API. ```typescript -import { WhatsAppApiError } from 'whatsapp-cloud-api-types/client' +import { WhatsAppApiError } from 'whatsapp-cloud-api-types' try { await client.messages.sendText('numero-invalido', 'Hola') @@ -948,7 +948,7 @@ import type { BusinessProfile, PhoneNumber, WABA, -} from 'whatsapp-cloud-api-types/client' +} from 'whatsapp-cloud-api-types' // Los tipos están completamente tipados con TypeScript const message: TextMessage = { @@ -1011,7 +1011,7 @@ import { type MediaUploadResponse, // Y muchos más... -} from 'whatsapp-cloud-api-types/client' +} from 'whatsapp-cloud-api-types' ``` ## Ejemplos Completos @@ -1019,7 +1019,7 @@ import { ### Bot de Atención al Cliente ```typescript -import { WhatsAppCloudAPI } from 'whatsapp-cloud-api-types/client' +import { WhatsAppCloudAPI } from 'whatsapp-cloud-api-types' const client = new WhatsAppCloudAPI({ accessToken: process.env.WHATSAPP_ACCESS_TOKEN!, @@ -1153,4 +1153,4 @@ async function checkPhoneNumberHealth(phoneNumberId: string) { --- -**Nota**: Este cliente requiere configuración previa en Meta Business Suite y tokens de acceso válidos. Consulta la [documentación oficial de WhatsApp Business Platform](https://developers.facebook.com/docs/whatsapp) para más detalles sobre configuración inicial. \ No newline at end of file +**Nota**: Este cliente requiere configuración previa en Meta Business Suite y tokens de acceso válidos. Consulta la [documentación oficial de WhatsApp Business Platform](https://developers.facebook.com/docs/whatsapp) para más detalles sobre configuración inicial. diff --git a/src/client/services/phone-numbers.ts b/src/client/services/phone-numbers.ts index 8ada5c9..956af8b 100644 --- a/src/client/services/phone-numbers.ts +++ b/src/client/services/phone-numbers.ts @@ -189,7 +189,7 @@ export class PhoneNumbersService { constructor(config: WhatsAppConfig) { this.config = config - this.baseUrl = `https://graph.facebook.com/${config.version}` + this.baseUrl = `${config.baseUrl}/${config.version}` } /** diff --git a/src/client/services/templates.ts b/src/client/services/templates.ts index 5a33d6f..7a22dc6 100644 --- a/src/client/services/templates.ts +++ b/src/client/services/templates.ts @@ -206,6 +206,14 @@ export type TemplateDeleteResponse = z.infer< * ``` */ export class TemplatesService extends BaseService { + private requireWabaId(): string { + if (!this.config.wabaId) { + throw new Error('wabaId is required for template operations') + } + + return this.config.wabaId + } + /** * Create a new message template * @@ -230,10 +238,11 @@ export class TemplatesService extends BaseService { async create( template: z.input, ): Promise { + const wabaId = this.requireWabaId() const validatedTemplate = CreateTemplateSchema.parse(template) const response = await this.request( - `${this.config.wabaId}/message_templates`, + `${wabaId}/message_templates`, { method: 'POST', body: JSON.stringify(validatedTemplate), @@ -259,6 +268,7 @@ export class TemplatesService extends BaseService { limit?: number after?: string }): Promise { + const wabaId = this.requireWabaId() const params = new URLSearchParams() if (options?.limit) { @@ -270,7 +280,7 @@ export class TemplatesService extends BaseService { } const queryString = params.toString() - const path = `${this.config.wabaId}/message_templates${queryString ? `?${queryString}` : ''}` + const path = `${wabaId}/message_templates${queryString ? `?${queryString}` : ''}` const response = await this.request(path, { method: 'GET', @@ -315,6 +325,7 @@ export class TemplatesService extends BaseService { name: string, options?: { hsm_id?: string }, ): Promise { + const wabaId = this.requireWabaId() const params = new URLSearchParams({ name }) if (options?.hsm_id) { @@ -322,7 +333,7 @@ export class TemplatesService extends BaseService { } const response = await this.request( - `${this.config.wabaId}/message_templates?${params.toString()}`, + `${wabaId}/message_templates?${params.toString()}`, { method: 'DELETE', }, @@ -371,10 +382,11 @@ export class TemplatesService extends BaseService { * ``` */ async getByName(name: string): Promise { + const wabaId = this.requireWabaId() const params = new URLSearchParams({ name }) const response = await this.request( - `${this.config.wabaId}/message_templates?${params.toString()}`, + `${wabaId}/message_templates?${params.toString()}`, { method: 'GET', }, @@ -399,6 +411,7 @@ export class TemplatesService extends BaseService { status: 'PENDING' | 'APPROVED' | 'REJECTED' | 'PAUSED' | 'DISABLED', options?: { limit?: number; after?: string }, ): Promise { + const wabaId = this.requireWabaId() const params = new URLSearchParams({ status }) if (options?.limit) { @@ -410,7 +423,7 @@ export class TemplatesService extends BaseService { } const response = await this.request( - `${this.config.wabaId}/message_templates?${params.toString()}`, + `${wabaId}/message_templates?${params.toString()}`, { method: 'GET', }, diff --git a/src/client/services/waba.ts b/src/client/services/waba.ts index e7af5f3..36b9d08 100644 --- a/src/client/services/waba.ts +++ b/src/client/services/waba.ts @@ -108,7 +108,7 @@ export class WABAService { constructor(config: WhatsAppConfig) { this.config = config - this.baseUrl = `https://graph.facebook.com/${config.version}` + this.baseUrl = `${config.baseUrl}/${config.version}` } /** diff --git a/src/client/services/webhooks.ts b/src/client/services/webhooks.ts index 5a12fd8..d30abe3 100644 --- a/src/client/services/webhooks.ts +++ b/src/client/services/webhooks.ts @@ -92,7 +92,7 @@ export class WebhooksService { constructor(config: WhatsAppConfig) { this.config = config - this.baseUrl = `https://graph.facebook.com/${config.version}` + this.baseUrl = `${config.baseUrl}/${config.version}` } /**