novapsis 1.0.0 → 1.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +95 -53
- package/dist/index.cjs +138 -12
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.mts +282 -22
- package/dist/index.d.ts +282 -22
- package/dist/index.mjs +138 -13
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
package/dist/index.d.ts
CHANGED
|
@@ -5,7 +5,7 @@
|
|
|
5
5
|
* Universal typed client for WhatsApp Business Cloud API, Hosted Onboarding,
|
|
6
6
|
* CRM, AI Agents and HMAC Webhook Verification.
|
|
7
7
|
*
|
|
8
|
-
* @version 1.
|
|
8
|
+
* @version 1.1.0
|
|
9
9
|
* @author Novapsis Technologies
|
|
10
10
|
* @license MIT
|
|
11
11
|
* ══════════════════════════════════════════════════════════════════════════════
|
|
@@ -107,6 +107,9 @@ interface SendTemplateOptions extends SendBaseOptions {
|
|
|
107
107
|
interface SendMessageResult {
|
|
108
108
|
message_id: string;
|
|
109
109
|
recipient: string;
|
|
110
|
+
connection_id?: string;
|
|
111
|
+
phone_number_id?: string;
|
|
112
|
+
business_phone_number?: string | null;
|
|
110
113
|
type: string;
|
|
111
114
|
status: string;
|
|
112
115
|
conversation_id: string | null;
|
|
@@ -116,27 +119,211 @@ interface WhatsAppConnection {
|
|
|
116
119
|
display_name: string;
|
|
117
120
|
phone_number: string | null;
|
|
118
121
|
phone_number_id: string;
|
|
122
|
+
waba_id?: string | null;
|
|
119
123
|
verified_name: string | null;
|
|
124
|
+
quality_rating?: string | null;
|
|
120
125
|
status: string;
|
|
121
126
|
webhook_subscribed: boolean;
|
|
127
|
+
created_at?: string;
|
|
122
128
|
}
|
|
123
129
|
interface WhatsAppTemplate {
|
|
124
130
|
id: string;
|
|
125
|
-
|
|
126
|
-
|
|
131
|
+
template_name?: string;
|
|
132
|
+
display_name?: string;
|
|
133
|
+
name?: string;
|
|
134
|
+
category: 'MARKETING' | 'UTILITY' | 'AUTHENTICATION' | string;
|
|
127
135
|
language: string;
|
|
128
|
-
status: string;
|
|
136
|
+
status: 'APPROVED' | 'PENDING' | 'REJECTED' | 'PAUSED' | string;
|
|
137
|
+
quality_rating?: string | null;
|
|
129
138
|
components: any[];
|
|
139
|
+
meta_template_id?: string | null;
|
|
140
|
+
rejection_reason?: string | null;
|
|
141
|
+
waba_id?: string | null;
|
|
142
|
+
created_at?: string;
|
|
143
|
+
updated_at?: string;
|
|
144
|
+
}
|
|
145
|
+
interface ListTemplatesOptions {
|
|
146
|
+
/** Filtrar por estado en Meta (ej: 'APPROVED', 'PENDING', 'REJECTED') */
|
|
147
|
+
status?: 'APPROVED' | 'PENDING' | 'REJECTED' | 'PAUSED' | string;
|
|
148
|
+
/** Filtrar por categoría oficial */
|
|
149
|
+
category?: 'MARKETING' | 'UTILITY' | 'AUTHENTICATION' | string;
|
|
150
|
+
}
|
|
151
|
+
interface CreateTemplateOptions {
|
|
152
|
+
/** Nombre técnico en Meta (solo minúsculas, números y guiones bajos, ej: 'confirmacion_pedido_v1') */
|
|
153
|
+
name?: string;
|
|
154
|
+
template_name?: string;
|
|
155
|
+
/** Nombre descriptivo para el panel */
|
|
156
|
+
displayName?: string;
|
|
157
|
+
display_name?: string;
|
|
158
|
+
/** Categoría oficial de Meta */
|
|
159
|
+
category: 'MARKETING' | 'UTILITY' | 'AUTHENTICATION';
|
|
160
|
+
/** Código de idioma (por defecto: 'es') */
|
|
161
|
+
language?: string;
|
|
162
|
+
/** Componentes según especificación de Meta Graph API (HEADER, BODY, BUTTONS, etc.) */
|
|
163
|
+
components?: any[];
|
|
164
|
+
/** Texto plano del cuerpo si no se envían componentes avanzados */
|
|
165
|
+
bodyText?: string;
|
|
166
|
+
/** ID de conexión de WhatsApp (opcional si la cuenta tiene una sola activa) */
|
|
167
|
+
connectionId?: string;
|
|
168
|
+
connection_id?: string;
|
|
169
|
+
/** TTL de entrega en segundos (opcional) */
|
|
170
|
+
messageSendTtlSeconds?: number;
|
|
171
|
+
}
|
|
172
|
+
interface OrganizationDetails {
|
|
173
|
+
id: string;
|
|
174
|
+
name: string;
|
|
175
|
+
timezone: string;
|
|
176
|
+
tier: string;
|
|
177
|
+
created_at: string;
|
|
178
|
+
updated_at: string;
|
|
179
|
+
}
|
|
180
|
+
interface UpdateOrganizationOptions {
|
|
181
|
+
/** Nombre de la empresa o aplicación (cambio de nombre / settings de la app) */
|
|
182
|
+
name?: string;
|
|
183
|
+
/** Zona horaria IANA (ej: 'Europe/Madrid', 'America/Bogota', 'America/Mexico_City') */
|
|
184
|
+
timezone?: string;
|
|
185
|
+
}
|
|
186
|
+
interface AgentDetails {
|
|
187
|
+
id: string;
|
|
188
|
+
name: string;
|
|
189
|
+
system_prompt: string;
|
|
190
|
+
model: string;
|
|
191
|
+
mode: 'agent' | 'rag' | 'both';
|
|
192
|
+
temperature: number;
|
|
193
|
+
is_active: boolean;
|
|
194
|
+
grouping_timeout_seconds: number;
|
|
195
|
+
created_at?: string;
|
|
196
|
+
updated_at?: string;
|
|
197
|
+
}
|
|
198
|
+
interface CreateAgentOptions {
|
|
199
|
+
/** Nombre del agente de IA (ej: 'Asistente Ventas') */
|
|
200
|
+
name: string;
|
|
201
|
+
/** Prompt de sistema e instrucciones de comportamiento */
|
|
202
|
+
systemPrompt: string;
|
|
203
|
+
/** Modelo de IA a utilizar (por defecto: 'gemini-2.5-flash') */
|
|
204
|
+
model?: string;
|
|
205
|
+
/** Modo de operación: 'agent', 'rag' o 'both' */
|
|
206
|
+
mode?: 'agent' | 'rag' | 'both';
|
|
207
|
+
/** Creatividad (temperatura 0.0 - 1.0) */
|
|
208
|
+
temperature?: number;
|
|
209
|
+
/** Si el agente está activo respondiendo chats */
|
|
210
|
+
isActive?: boolean;
|
|
211
|
+
/** Ventana de agrupación de mensajes en segundos */
|
|
212
|
+
groupingTimeoutSeconds?: number;
|
|
213
|
+
}
|
|
214
|
+
interface UpdateAgentOptions {
|
|
215
|
+
/** Nuevo nombre del agente (cambio de nombre del bot) */
|
|
216
|
+
name?: string;
|
|
217
|
+
/** Nuevo prompt de sistema */
|
|
218
|
+
systemPrompt?: string;
|
|
219
|
+
/** Modelo de IA */
|
|
220
|
+
model?: string;
|
|
221
|
+
/** Modo de operación */
|
|
222
|
+
mode?: 'agent' | 'rag' | 'both';
|
|
223
|
+
/** Creatividad */
|
|
224
|
+
temperature?: number;
|
|
225
|
+
/** Estado activo o inactivo */
|
|
226
|
+
isActive?: boolean;
|
|
227
|
+
/** Ventana de agrupación en segundos */
|
|
228
|
+
groupingTimeoutSeconds?: number;
|
|
229
|
+
}
|
|
230
|
+
interface AgentSchedule {
|
|
231
|
+
id: string;
|
|
232
|
+
agent_id: string;
|
|
233
|
+
name: string;
|
|
234
|
+
days: number[];
|
|
235
|
+
active_from: string;
|
|
236
|
+
active_until: string;
|
|
237
|
+
is_active: boolean;
|
|
238
|
+
created_at?: string;
|
|
239
|
+
updated_at?: string;
|
|
240
|
+
}
|
|
241
|
+
interface SetScheduleOptions {
|
|
242
|
+
/** Días activos: 1=Lunes, 2=Martes, 3=Miércoles, 4=Jueves, 5=Viernes, 6=Sábado, 7=Domingo */
|
|
243
|
+
days: number[];
|
|
244
|
+
/** Hora de apertura en formato HH:MM (ej: '09:00') */
|
|
245
|
+
activeFrom: string;
|
|
246
|
+
/** Hora de cierre en formato HH:MM (ej: '19:00') */
|
|
247
|
+
activeUntil: string;
|
|
248
|
+
/** Nombre de la franja horaria */
|
|
249
|
+
name?: string;
|
|
250
|
+
/** Si el horario está habilitado */
|
|
251
|
+
isActive?: boolean;
|
|
252
|
+
}
|
|
253
|
+
interface KnowledgeDocument {
|
|
254
|
+
id: string;
|
|
255
|
+
title: string;
|
|
256
|
+
description?: string | null;
|
|
257
|
+
file_type: string;
|
|
258
|
+
total_chunks?: number;
|
|
259
|
+
created_at: string;
|
|
260
|
+
updated_at?: string;
|
|
261
|
+
}
|
|
262
|
+
interface AddKnowledgeOptions {
|
|
263
|
+
/** Título o tema del documento (ej: 'Políticas de garantía y devoluciones') */
|
|
264
|
+
title: string;
|
|
265
|
+
/** Contenido en texto plano a vectorizar para RAG */
|
|
266
|
+
content: string;
|
|
267
|
+
/** Descripción contextual */
|
|
268
|
+
description?: string;
|
|
269
|
+
}
|
|
270
|
+
interface OnboardingFeatureBullet {
|
|
271
|
+
title: string;
|
|
272
|
+
description?: string;
|
|
130
273
|
}
|
|
131
274
|
interface CreateOnboardingSessionOptions {
|
|
132
|
-
/** Nombre
|
|
275
|
+
/** Nombre del cliente, empresa o sede (ej: 'Clínica Dental') */
|
|
133
276
|
clientName?: string;
|
|
134
|
-
/**
|
|
277
|
+
/** Nombre corporativo visible */
|
|
278
|
+
companyName?: string;
|
|
279
|
+
/** URL de retorno tras conectar exitosamente con WhatsApp */
|
|
135
280
|
redirectUrl?: string;
|
|
136
|
-
/** URL del logotipo
|
|
281
|
+
/** URL pública del logotipo corporativo para marca blanca (PNG, SVG, JPG) */
|
|
137
282
|
logoUrl?: string;
|
|
138
|
-
/** Color
|
|
283
|
+
/** Color de acento principal (ej: '#0ea5e9') */
|
|
139
284
|
brandColor?: string;
|
|
285
|
+
/** Color de fondo general de la pantalla (ej: '#0f172a' o '#ffffff') */
|
|
286
|
+
backgroundColor?: string;
|
|
287
|
+
/** Color de fondo de la tarjeta/modal (ej: '#1e293b' o '#ffffff') */
|
|
288
|
+
cardBackgroundColor?: string;
|
|
289
|
+
/** Color del borde de la tarjeta (ej: 'rgba(255,255,255,0.1)') */
|
|
290
|
+
cardBorderColor?: string;
|
|
291
|
+
/** Color de los títulos y textos principales (ej: '#ffffff' o '#0f172a') */
|
|
292
|
+
textColor?: string;
|
|
293
|
+
/** Color de los textos secundarios y descripciones (ej: '#94a3b8') */
|
|
294
|
+
textSecondaryColor?: string;
|
|
295
|
+
/** Color de fondo del botón de acción (por defecto usa brandColor o verde WhatsApp) */
|
|
296
|
+
buttonColor?: string;
|
|
297
|
+
/** Color del texto dentro del botón de acción */
|
|
298
|
+
buttonTextColor?: string;
|
|
299
|
+
/** Color de fondo de la píldora superior */
|
|
300
|
+
badgeColor?: string;
|
|
301
|
+
/** Color del texto de la píldora superior */
|
|
302
|
+
badgeTextColor?: string;
|
|
303
|
+
/** Título principal (por defecto: 'Conecta WhatsApp Business') */
|
|
304
|
+
title?: string;
|
|
305
|
+
/** Texto explicativo debajo del título */
|
|
306
|
+
description?: string;
|
|
307
|
+
/** Texto del botón principal (por defecto: 'Conectar con WhatsApp') */
|
|
308
|
+
buttonText?: string;
|
|
309
|
+
/** Texto de la píldora superior (por defecto: 'Vinculación Oficial', o '' para ocultar) */
|
|
310
|
+
badgeText?: string;
|
|
311
|
+
/** Texto legal o footer de la tarjeta */
|
|
312
|
+
footerText?: string;
|
|
313
|
+
/** Viñetas de beneficios o false para ocultar la caja */
|
|
314
|
+
features?: OnboardingFeatureBullet[] | boolean;
|
|
315
|
+
/** Título de la pantalla de éxito tras vincular */
|
|
316
|
+
successTitle?: string;
|
|
317
|
+
/** Descripción de la pantalla de éxito */
|
|
318
|
+
successDescription?: string;
|
|
319
|
+
/** Texto del botón en la pantalla de éxito */
|
|
320
|
+
successButtonText?: string;
|
|
321
|
+
/** Si es true, oculta el badge 'Meta Tech Provider Verified' del encabezado */
|
|
322
|
+
hideMetaBadge?: boolean;
|
|
323
|
+
/** Si es true, oculta el pie de página de copyright */
|
|
324
|
+
hideFooter?: boolean;
|
|
325
|
+
/** Horas de validez de la sesión antes de expirar (por defecto: 168 = 7 días) */
|
|
326
|
+
expiresInHours?: number;
|
|
140
327
|
/** Metadata personalizada para tracking en tu CRM */
|
|
141
328
|
metadata?: Record<string, any>;
|
|
142
329
|
}
|
|
@@ -149,6 +336,46 @@ interface OnboardingSession {
|
|
|
149
336
|
created_at: string;
|
|
150
337
|
}
|
|
151
338
|
type NovapsisWebhookEvent = 'whatsapp.message_received' | 'whatsapp.message_sent' | 'whatsapp.connected' | 'conversation.started' | 'lead.completed' | 'call.completed' | 'review.received' | '*';
|
|
339
|
+
interface WhatsAppMessageReceivedData {
|
|
340
|
+
conversation_id: string;
|
|
341
|
+
message_id: string;
|
|
342
|
+
external_message_id?: string | null;
|
|
343
|
+
platform: 'whatsapp' | string;
|
|
344
|
+
connection_id: string;
|
|
345
|
+
phone_number_id: string;
|
|
346
|
+
waba_id?: string | null;
|
|
347
|
+
business_phone_number: string | null;
|
|
348
|
+
business_name?: string | null;
|
|
349
|
+
connection_name?: string | null;
|
|
350
|
+
to: string | null;
|
|
351
|
+
from: string;
|
|
352
|
+
external_user_id: string;
|
|
353
|
+
external_user_name: string;
|
|
354
|
+
content: string;
|
|
355
|
+
media_type: 'image' | 'audio' | 'video' | 'document' | null;
|
|
356
|
+
media_url: string | null;
|
|
357
|
+
timestamp: string;
|
|
358
|
+
}
|
|
359
|
+
interface WhatsAppMessageSentData {
|
|
360
|
+
conversation_id: string;
|
|
361
|
+
message_id: string;
|
|
362
|
+
platform: 'whatsapp' | string;
|
|
363
|
+
connection_id: string;
|
|
364
|
+
phone_number_id: string;
|
|
365
|
+
waba_id?: string | null;
|
|
366
|
+
business_phone_number: string | null;
|
|
367
|
+
business_name?: string | null;
|
|
368
|
+
connection_name?: string | null;
|
|
369
|
+
from: string | null;
|
|
370
|
+
to: string;
|
|
371
|
+
external_user_id: string;
|
|
372
|
+
role: 'assistant';
|
|
373
|
+
sender_type: 'ai' | 'human';
|
|
374
|
+
content: string;
|
|
375
|
+
media_type?: string | null;
|
|
376
|
+
media_url?: string | null;
|
|
377
|
+
timestamp: string;
|
|
378
|
+
}
|
|
152
379
|
interface CreateWebhookSubscriptionOptions {
|
|
153
380
|
/** Nombre descriptivo de la suscripción (ej: 'CRM Sincronizador') */
|
|
154
381
|
name: string;
|
|
@@ -225,14 +452,14 @@ declare class WhatsAppService {
|
|
|
225
452
|
}): Promise<any>;
|
|
226
453
|
/** Obtiene la lista de líneas y números de WhatsApp conectados en la organización */
|
|
227
454
|
listConnections(): Promise<WhatsAppConnection[]>;
|
|
228
|
-
/**
|
|
455
|
+
/** Lista las plantillas oficiales de Meta con filtros opcionales de estado y categoría */
|
|
456
|
+
listTemplates(options?: ListTemplatesOptions): Promise<WhatsAppTemplate[]>;
|
|
457
|
+
/** Obtiene las plantillas oficiales de Meta aprobadas (alias directo de listTemplates) */
|
|
229
458
|
getTemplates(): Promise<WhatsAppTemplate[]>;
|
|
230
|
-
/** Crea una nueva plantilla para
|
|
231
|
-
createTemplate(options: {
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
bodyText: string;
|
|
235
|
-
}): Promise<any>;
|
|
459
|
+
/** Crea una nueva plantilla oficial de WhatsApp para someter a revisión y aprobación en Meta */
|
|
460
|
+
createTemplate(options: CreateTemplateOptions): Promise<{
|
|
461
|
+
template: WhatsAppTemplate;
|
|
462
|
+
}>;
|
|
236
463
|
/** Lista las campañas masivas de WhatsApp configuradas */
|
|
237
464
|
listCampaigns(): Promise<any[]>;
|
|
238
465
|
/** Ejecuta una campaña masiva */
|
|
@@ -279,13 +506,44 @@ declare class ContactsService {
|
|
|
279
506
|
/** Crea o actualiza un contacto por número de teléfono */
|
|
280
507
|
upsert(options: UpsertContactOptions): Promise<Contact>;
|
|
281
508
|
}
|
|
282
|
-
/** Servicio para
|
|
509
|
+
/** Servicio para gestión de la organización y configuración general (Marca / Settings) */
|
|
510
|
+
declare class OrganizationService {
|
|
511
|
+
private http;
|
|
512
|
+
constructor(http: HttpClient);
|
|
513
|
+
/** Obtiene la información y configuración de la organización actual */
|
|
514
|
+
get(): Promise<OrganizationDetails>;
|
|
515
|
+
/**
|
|
516
|
+
* Actualiza la configuración de la organización (cambio de nombre de la app/empresa, zona horaria)
|
|
517
|
+
*/
|
|
518
|
+
update(options: UpdateOrganizationOptions): Promise<OrganizationDetails>;
|
|
519
|
+
}
|
|
520
|
+
/** Servicio para interactuar y configurar Agentes de Inteligencia Artificial (Headless AI) */
|
|
283
521
|
declare class AIService {
|
|
284
522
|
private http;
|
|
285
523
|
constructor(http: HttpClient);
|
|
286
|
-
/** Lista los agentes de IA configurados
|
|
287
|
-
listAgents(): Promise<
|
|
288
|
-
/**
|
|
524
|
+
/** Lista los agentes de IA configurados en la organización */
|
|
525
|
+
listAgents(): Promise<AgentDetails[]>;
|
|
526
|
+
/** Obtiene la configuración completa de un agente por su ID */
|
|
527
|
+
getAgent(agentId: string): Promise<AgentDetails>;
|
|
528
|
+
/** Crea un nuevo agente de IA para la organización */
|
|
529
|
+
createAgent(options: CreateAgentOptions): Promise<AgentDetails>;
|
|
530
|
+
/** Actualiza nombre, prompt de sistema, modelo o configuración de un agente */
|
|
531
|
+
updateAgent(agentId: string, options: UpdateAgentOptions): Promise<AgentDetails>;
|
|
532
|
+
/** Consulta el horario de atención configurado para el agente y la zona horaria */
|
|
533
|
+
getSchedule(agentId: string): Promise<{
|
|
534
|
+
schedule: AgentSchedule | null;
|
|
535
|
+
timezone: string;
|
|
536
|
+
}>;
|
|
537
|
+
/** Configura o reemplaza el horario de atención activa del agente */
|
|
538
|
+
setSchedule(agentId: string, options: SetScheduleOptions): Promise<{
|
|
539
|
+
schedule: AgentSchedule;
|
|
540
|
+
timezone: string;
|
|
541
|
+
}>;
|
|
542
|
+
/** Lista los documentos de la base de conocimiento RAG asociados al agente */
|
|
543
|
+
listKnowledge(agentId: string): Promise<KnowledgeDocument[]>;
|
|
544
|
+
/** Ingesta y vectoriza nuevo conocimiento en texto plano directamente al agente */
|
|
545
|
+
addKnowledge(agentId: string, options: AddKnowledgeOptions): Promise<KnowledgeDocument>;
|
|
546
|
+
/** Ejecuta una consulta conversacional contra el agente y su base de conocimiento RAG */
|
|
289
547
|
execute(options: {
|
|
290
548
|
agentId: string;
|
|
291
549
|
message: string;
|
|
@@ -303,7 +561,7 @@ declare class AIService {
|
|
|
303
561
|
* import { Novapsis } from 'novapsis';
|
|
304
562
|
*
|
|
305
563
|
* const client = new Novapsis({
|
|
306
|
-
* apiKey: '
|
|
564
|
+
* apiKey: 'nvs_live_sample_abcdef1234567890',
|
|
307
565
|
* });
|
|
308
566
|
*
|
|
309
567
|
* // Enviar mensaje de texto
|
|
@@ -315,6 +573,8 @@ declare class AIService {
|
|
|
315
573
|
*/
|
|
316
574
|
declare class Novapsis {
|
|
317
575
|
private http;
|
|
576
|
+
/** Métodos para ajustes de la organización y cambio de nombre de la app */
|
|
577
|
+
readonly organization: OrganizationService;
|
|
318
578
|
/** Métodos para envíos y operaciones de WhatsApp */
|
|
319
579
|
readonly whatsapp: WhatsAppService;
|
|
320
580
|
/** Métodos para onboarding hosted y vinculación B2B */
|
|
@@ -323,11 +583,11 @@ declare class Novapsis {
|
|
|
323
583
|
readonly webhooks: WebhookService;
|
|
324
584
|
/** Métodos para contactos del CRM */
|
|
325
585
|
readonly contacts: ContactsService;
|
|
326
|
-
/** Métodos para Agentes de Inteligencia Artificial */
|
|
586
|
+
/** Métodos para Agentes de Inteligencia Artificial (prompts, RAG, horarios) */
|
|
327
587
|
readonly ai: AIService;
|
|
328
588
|
constructor(options: NovapsisClientOptions);
|
|
329
589
|
}
|
|
330
590
|
|
|
331
591
|
// @ts-ignore
|
|
332
592
|
export = Novapsis;
|
|
333
|
-
export { AIService, type APIResponse, type Contact, ContactsService, type CreateOnboardingSessionOptions, type CreateWebhookSubscriptionOptions, type InboundWebhookPayload, Novapsis, NovapsisAPIError, type NovapsisClientOptions, type NovapsisWebhookEvent, OnboardingService, type OnboardingSession, type SendAudioOptions, type SendBaseOptions, type SendContactCardOptions, type SendDocumentOptions, type SendImageOptions, type SendLocationOptions, type SendMessageResult, type SendTemplateOptions, type SendTextOptions, type SendVideoOptions, type UpsertContactOptions, WebhookService, type WebhookSubscription, type WhatsAppConnection, WhatsAppService, type WhatsAppTemplate };
|
|
593
|
+
export { AIService, type APIResponse, type AddKnowledgeOptions, type AgentDetails, type AgentSchedule, type Contact, ContactsService, type CreateAgentOptions, type CreateOnboardingSessionOptions, type CreateTemplateOptions, type CreateWebhookSubscriptionOptions, type InboundWebhookPayload, type KnowledgeDocument, type ListTemplatesOptions, Novapsis, NovapsisAPIError, type NovapsisClientOptions, type NovapsisWebhookEvent, type OnboardingFeatureBullet, OnboardingService, type OnboardingSession, type OrganizationDetails, OrganizationService, type SendAudioOptions, type SendBaseOptions, type SendContactCardOptions, type SendDocumentOptions, type SendImageOptions, type SendLocationOptions, type SendMessageResult, type SendTemplateOptions, type SendTextOptions, type SendVideoOptions, type SetScheduleOptions, type UpdateAgentOptions, type UpdateOrganizationOptions, type UpsertContactOptions, WebhookService, type WebhookSubscription, type WhatsAppConnection, type WhatsAppMessageReceivedData, type WhatsAppMessageSentData, WhatsAppService, type WhatsAppTemplate };
|
package/dist/index.mjs
CHANGED
|
@@ -40,7 +40,7 @@ var HttpClient = class {
|
|
|
40
40
|
headers: {
|
|
41
41
|
"Authorization": `Bearer ${this.apiKey}`,
|
|
42
42
|
"Content-Type": "application/json",
|
|
43
|
-
"User-Agent": "Novapsis-SDK-Node/1.
|
|
43
|
+
"User-Agent": "Novapsis-SDK-Node/1.1.0"
|
|
44
44
|
},
|
|
45
45
|
body: body ? JSON.stringify(body) : void 0,
|
|
46
46
|
signal: controller.signal
|
|
@@ -175,17 +175,33 @@ var WhatsAppService = class {
|
|
|
175
175
|
const res = await this.http.request("GET", "/whatsapp/connections");
|
|
176
176
|
return res.connections;
|
|
177
177
|
}
|
|
178
|
-
/**
|
|
179
|
-
async
|
|
180
|
-
const
|
|
178
|
+
/** Lista las plantillas oficiales de Meta con filtros opcionales de estado y categoría */
|
|
179
|
+
async listTemplates(options = {}) {
|
|
180
|
+
const query = {};
|
|
181
|
+
if (options.status) query.status = options.status;
|
|
182
|
+
if (options.category) query.category = options.category;
|
|
183
|
+
const res = await this.http.request("GET", "/whatsapp/templates", void 0, query);
|
|
181
184
|
return res.templates;
|
|
182
185
|
}
|
|
183
|
-
/**
|
|
186
|
+
/** Obtiene las plantillas oficiales de Meta aprobadas (alias directo de listTemplates) */
|
|
187
|
+
async getTemplates() {
|
|
188
|
+
return this.listTemplates();
|
|
189
|
+
}
|
|
190
|
+
/** Crea una nueva plantilla oficial de WhatsApp para someter a revisión y aprobación en Meta */
|
|
184
191
|
async createTemplate(options) {
|
|
192
|
+
const templateName = options.template_name || options.name;
|
|
193
|
+
if (!templateName) {
|
|
194
|
+
throw new NovapsisAPIError("Se requiere `name` o `template_name` para crear una plantilla.", "VALIDATION_ERROR", 400);
|
|
195
|
+
}
|
|
196
|
+
const components = options.components || (options.bodyText ? [{ type: "BODY", text: options.bodyText }] : []);
|
|
185
197
|
return this.http.request("POST", "/whatsapp/templates", {
|
|
186
|
-
|
|
198
|
+
template_name: templateName,
|
|
199
|
+
display_name: options.displayName || options.display_name,
|
|
187
200
|
category: options.category,
|
|
188
|
-
|
|
201
|
+
language: options.language || "es",
|
|
202
|
+
components,
|
|
203
|
+
connection_id: options.connectionId || options.connection_id,
|
|
204
|
+
message_send_ttl_seconds: options.messageSendTtlSeconds
|
|
189
205
|
});
|
|
190
206
|
}
|
|
191
207
|
/** Lista las campañas masivas de WhatsApp configuradas */
|
|
@@ -210,9 +226,31 @@ var OnboardingService = class {
|
|
|
210
226
|
async createSession(options = {}) {
|
|
211
227
|
return this.http.request("POST", "/onboarding/sessions", {
|
|
212
228
|
client_name: options.clientName,
|
|
229
|
+
company_name: options.companyName,
|
|
213
230
|
redirect_url: options.redirectUrl,
|
|
214
231
|
logo_url: options.logoUrl,
|
|
215
232
|
brand_color: options.brandColor,
|
|
233
|
+
background_color: options.backgroundColor,
|
|
234
|
+
card_background_color: options.cardBackgroundColor,
|
|
235
|
+
card_border_color: options.cardBorderColor,
|
|
236
|
+
text_color: options.textColor,
|
|
237
|
+
text_secondary_color: options.textSecondaryColor,
|
|
238
|
+
button_color: options.buttonColor,
|
|
239
|
+
button_text_color: options.buttonTextColor,
|
|
240
|
+
badge_color: options.badgeColor,
|
|
241
|
+
badge_text_color: options.badgeTextColor,
|
|
242
|
+
title: options.title,
|
|
243
|
+
description: options.description,
|
|
244
|
+
button_text: options.buttonText,
|
|
245
|
+
badge_text: options.badgeText,
|
|
246
|
+
footer_text: options.footerText,
|
|
247
|
+
features: options.features,
|
|
248
|
+
success_title: options.successTitle,
|
|
249
|
+
success_description: options.successDescription,
|
|
250
|
+
success_button_text: options.successButtonText,
|
|
251
|
+
hide_meta_badge: options.hideMetaBadge,
|
|
252
|
+
hide_footer: options.hideFooter,
|
|
253
|
+
expires_in_hours: options.expiresInHours,
|
|
216
254
|
metadata: options.metadata
|
|
217
255
|
});
|
|
218
256
|
}
|
|
@@ -257,8 +295,12 @@ var WebhookService = class {
|
|
|
257
295
|
verifySignature(rawBody, signatureHeader, secret) {
|
|
258
296
|
if (!signatureHeader || !secret || !rawBody) return false;
|
|
259
297
|
try {
|
|
298
|
+
const cleanSig = signatureHeader.startsWith("sha256=") ? signatureHeader.slice(7) : signatureHeader;
|
|
260
299
|
const computed = crypto.createHmac("sha256", secret).update(rawBody, "utf8").digest("hex");
|
|
261
|
-
|
|
300
|
+
const bufA = Buffer.from(computed, "hex");
|
|
301
|
+
const bufB = Buffer.from(cleanSig, "hex");
|
|
302
|
+
if (bufA.length !== bufB.length) return false;
|
|
303
|
+
return crypto.timingSafeEqual(bufA, bufB);
|
|
262
304
|
} catch {
|
|
263
305
|
return false;
|
|
264
306
|
}
|
|
@@ -279,17 +321,97 @@ var ContactsService = class {
|
|
|
279
321
|
return this.http.request("POST", "/contacts", options);
|
|
280
322
|
}
|
|
281
323
|
};
|
|
324
|
+
var OrganizationService = class {
|
|
325
|
+
constructor(http) {
|
|
326
|
+
this.http = http;
|
|
327
|
+
}
|
|
328
|
+
http;
|
|
329
|
+
/** Obtiene la información y configuración de la organización actual */
|
|
330
|
+
async get() {
|
|
331
|
+
const res = await this.http.request("GET", "/organization");
|
|
332
|
+
return res.organization;
|
|
333
|
+
}
|
|
334
|
+
/**
|
|
335
|
+
* Actualiza la configuración de la organización (cambio de nombre de la app/empresa, zona horaria)
|
|
336
|
+
*/
|
|
337
|
+
async update(options) {
|
|
338
|
+
const res = await this.http.request("PATCH", "/organization", {
|
|
339
|
+
name: options.name,
|
|
340
|
+
timezone: options.timezone
|
|
341
|
+
});
|
|
342
|
+
return res.organization;
|
|
343
|
+
}
|
|
344
|
+
};
|
|
282
345
|
var AIService = class {
|
|
283
346
|
constructor(http) {
|
|
284
347
|
this.http = http;
|
|
285
348
|
}
|
|
286
349
|
http;
|
|
287
|
-
/** Lista los agentes de IA configurados
|
|
350
|
+
/** Lista los agentes de IA configurados en la organización */
|
|
288
351
|
async listAgents() {
|
|
289
352
|
const res = await this.http.request("GET", "/ai/agents");
|
|
290
353
|
return res.agents;
|
|
291
354
|
}
|
|
292
|
-
/**
|
|
355
|
+
/** Obtiene la configuración completa de un agente por su ID */
|
|
356
|
+
async getAgent(agentId) {
|
|
357
|
+
const res = await this.http.request("GET", `/ai/agents/${agentId}`);
|
|
358
|
+
return res.agent;
|
|
359
|
+
}
|
|
360
|
+
/** Crea un nuevo agente de IA para la organización */
|
|
361
|
+
async createAgent(options) {
|
|
362
|
+
const res = await this.http.request("POST", "/ai/agents", {
|
|
363
|
+
name: options.name,
|
|
364
|
+
system_prompt: options.systemPrompt,
|
|
365
|
+
model: options.model,
|
|
366
|
+
mode: options.mode,
|
|
367
|
+
temperature: options.temperature,
|
|
368
|
+
is_active: options.isActive,
|
|
369
|
+
grouping_timeout_seconds: options.groupingTimeoutSeconds
|
|
370
|
+
});
|
|
371
|
+
return res.agent;
|
|
372
|
+
}
|
|
373
|
+
/** Actualiza nombre, prompt de sistema, modelo o configuración de un agente */
|
|
374
|
+
async updateAgent(agentId, options) {
|
|
375
|
+
const res = await this.http.request("PATCH", `/ai/agents/${agentId}`, {
|
|
376
|
+
name: options.name,
|
|
377
|
+
system_prompt: options.systemPrompt,
|
|
378
|
+
model: options.model,
|
|
379
|
+
mode: options.mode,
|
|
380
|
+
temperature: options.temperature,
|
|
381
|
+
is_active: options.isActive,
|
|
382
|
+
grouping_timeout_seconds: options.groupingTimeoutSeconds
|
|
383
|
+
});
|
|
384
|
+
return res.agent;
|
|
385
|
+
}
|
|
386
|
+
/** Consulta el horario de atención configurado para el agente y la zona horaria */
|
|
387
|
+
async getSchedule(agentId) {
|
|
388
|
+
return this.http.request("GET", `/ai/agents/${agentId}/schedule`);
|
|
389
|
+
}
|
|
390
|
+
/** Configura o reemplaza el horario de atención activa del agente */
|
|
391
|
+
async setSchedule(agentId, options) {
|
|
392
|
+
return this.http.request("PUT", `/ai/agents/${agentId}/schedule`, {
|
|
393
|
+
days: options.days,
|
|
394
|
+
active_from: options.activeFrom,
|
|
395
|
+
active_until: options.activeUntil,
|
|
396
|
+
name: options.name,
|
|
397
|
+
is_active: options.isActive
|
|
398
|
+
});
|
|
399
|
+
}
|
|
400
|
+
/** Lista los documentos de la base de conocimiento RAG asociados al agente */
|
|
401
|
+
async listKnowledge(agentId) {
|
|
402
|
+
const res = await this.http.request("GET", `/ai/agents/${agentId}/knowledge`);
|
|
403
|
+
return res.documents;
|
|
404
|
+
}
|
|
405
|
+
/** Ingesta y vectoriza nuevo conocimiento en texto plano directamente al agente */
|
|
406
|
+
async addKnowledge(agentId, options) {
|
|
407
|
+
const res = await this.http.request("POST", `/ai/agents/${agentId}/knowledge`, {
|
|
408
|
+
title: options.title,
|
|
409
|
+
content: options.content,
|
|
410
|
+
description: options.description
|
|
411
|
+
});
|
|
412
|
+
return res.document;
|
|
413
|
+
}
|
|
414
|
+
/** Ejecuta una consulta conversacional contra el agente y su base de conocimiento RAG */
|
|
293
415
|
async execute(options) {
|
|
294
416
|
return this.http.request("POST", `/ai/agents/${options.agentId}/execute`, {
|
|
295
417
|
message: options.message
|
|
@@ -298,6 +420,8 @@ var AIService = class {
|
|
|
298
420
|
};
|
|
299
421
|
var Novapsis = class {
|
|
300
422
|
http;
|
|
423
|
+
/** Métodos para ajustes de la organización y cambio de nombre de la app */
|
|
424
|
+
organization;
|
|
301
425
|
/** Métodos para envíos y operaciones de WhatsApp */
|
|
302
426
|
whatsapp;
|
|
303
427
|
/** Métodos para onboarding hosted y vinculación B2B */
|
|
@@ -306,13 +430,14 @@ var Novapsis = class {
|
|
|
306
430
|
webhooks;
|
|
307
431
|
/** Métodos para contactos del CRM */
|
|
308
432
|
contacts;
|
|
309
|
-
/** Métodos para Agentes de Inteligencia Artificial */
|
|
433
|
+
/** Métodos para Agentes de Inteligencia Artificial (prompts, RAG, horarios) */
|
|
310
434
|
ai;
|
|
311
435
|
constructor(options) {
|
|
312
436
|
if (!options.apiKey) {
|
|
313
437
|
throw new NovapsisAPIError("Se requiere una apiKey v\xE1lida para inicializar el cliente de Novapsis.", "CONFIG_ERROR", 400);
|
|
314
438
|
}
|
|
315
439
|
this.http = new HttpClient(options);
|
|
440
|
+
this.organization = new OrganizationService(this.http);
|
|
316
441
|
this.whatsapp = new WhatsAppService(this.http);
|
|
317
442
|
this.onboarding = new OnboardingService(this.http);
|
|
318
443
|
this.webhooks = new WebhookService(this.http);
|
|
@@ -328,12 +453,12 @@ var index_default = Novapsis;
|
|
|
328
453
|
* Universal typed client for WhatsApp Business Cloud API, Hosted Onboarding,
|
|
329
454
|
* CRM, AI Agents and HMAC Webhook Verification.
|
|
330
455
|
*
|
|
331
|
-
* @version 1.
|
|
456
|
+
* @version 1.1.0
|
|
332
457
|
* @author Novapsis Technologies
|
|
333
458
|
* @license MIT
|
|
334
459
|
* ══════════════════════════════════════════════════════════════════════════════
|
|
335
460
|
*/
|
|
336
461
|
|
|
337
|
-
export { AIService, ContactsService, Novapsis, NovapsisAPIError, OnboardingService, WebhookService, WhatsAppService, index_default as default };
|
|
462
|
+
export { AIService, ContactsService, Novapsis, NovapsisAPIError, OnboardingService, OrganizationService, WebhookService, WhatsAppService, index_default as default };
|
|
338
463
|
//# sourceMappingURL=index.mjs.map
|
|
339
464
|
//# sourceMappingURL=index.mjs.map
|