Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 6 additions & 6 deletions CLIENT_README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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({
Expand Down Expand Up @@ -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')
Expand Down Expand Up @@ -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 = {
Expand Down Expand Up @@ -1011,15 +1011,15 @@ import {
type MediaUploadResponse,

// Y muchos más...
} from 'whatsapp-cloud-api-types/client'
} from 'whatsapp-cloud-api-types'
```

## Ejemplos Completos

### 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!,
Expand Down Expand Up @@ -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.
**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.
2 changes: 1 addition & 1 deletion src/client/services/phone-numbers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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}`
}

/**
Expand Down
23 changes: 18 additions & 5 deletions src/client/services/templates.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
*
Expand All @@ -230,10 +238,11 @@ export class TemplatesService extends BaseService {
async create(
template: z.input<typeof CreateTemplateSchema>,
): Promise<TemplateResponse> {
const wabaId = this.requireWabaId()
const validatedTemplate = CreateTemplateSchema.parse(template)

const response = await this.request<TemplateResponse>(
`${this.config.wabaId}/message_templates`,
`${wabaId}/message_templates`,
{
method: 'POST',
body: JSON.stringify(validatedTemplate),
Expand All @@ -259,6 +268,7 @@ export class TemplatesService extends BaseService {
limit?: number
after?: string
}): Promise<TemplateListResponse> {
const wabaId = this.requireWabaId()
const params = new URLSearchParams()

if (options?.limit) {
Expand All @@ -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<TemplateListResponse>(path, {
method: 'GET',
Expand Down Expand Up @@ -315,14 +325,15 @@ export class TemplatesService extends BaseService {
name: string,
options?: { hsm_id?: string },
): Promise<TemplateDeleteResponse> {
const wabaId = this.requireWabaId()
const params = new URLSearchParams({ name })

if (options?.hsm_id) {
params.append('hsm_id', options.hsm_id)
}

const response = await this.request<TemplateDeleteResponse>(
`${this.config.wabaId}/message_templates?${params.toString()}`,
`${wabaId}/message_templates?${params.toString()}`,
{
method: 'DELETE',
},
Expand Down Expand Up @@ -371,10 +382,11 @@ export class TemplatesService extends BaseService {
* ```
*/
async getByName(name: string): Promise<TemplateListResponse> {
const wabaId = this.requireWabaId()
const params = new URLSearchParams({ name })

const response = await this.request<TemplateListResponse>(
`${this.config.wabaId}/message_templates?${params.toString()}`,
`${wabaId}/message_templates?${params.toString()}`,
{
method: 'GET',
},
Expand All @@ -399,6 +411,7 @@ export class TemplatesService extends BaseService {
status: 'PENDING' | 'APPROVED' | 'REJECTED' | 'PAUSED' | 'DISABLED',
options?: { limit?: number; after?: string },
): Promise<TemplateListResponse> {
const wabaId = this.requireWabaId()
const params = new URLSearchParams({ status })

if (options?.limit) {
Expand All @@ -410,7 +423,7 @@ export class TemplatesService extends BaseService {
}

const response = await this.request<TemplateListResponse>(
`${this.config.wabaId}/message_templates?${params.toString()}`,
`${wabaId}/message_templates?${params.toString()}`,
{
method: 'GET',
},
Expand Down
2 changes: 1 addition & 1 deletion src/client/services/waba.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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}`
}

/**
Expand Down
2 changes: 1 addition & 1 deletion src/client/services/webhooks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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}`
}

/**
Expand Down