novapsis 1.0.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/LICENSE +9 -0
- package/README.md +211 -0
- package/dist/index.cjs +354 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.mts +331 -0
- package/dist/index.d.ts +333 -0
- package/dist/index.mjs +339 -0
- package/dist/index.mjs.map +1 -0
- package/package.json +55 -0
package/dist/index.d.mts
ADDED
|
@@ -0,0 +1,331 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* novapsis - Official TypeScript / JavaScript SDK
|
|
3
|
+
* ══════════════════════════════════════════════════════════════════════════════
|
|
4
|
+
* Official SDK for Novapsis SM.
|
|
5
|
+
* Universal typed client for WhatsApp Business Cloud API, Hosted Onboarding,
|
|
6
|
+
* CRM, AI Agents and HMAC Webhook Verification.
|
|
7
|
+
*
|
|
8
|
+
* @version 1.0.0
|
|
9
|
+
* @author Novapsis Technologies
|
|
10
|
+
* @license MIT
|
|
11
|
+
* ══════════════════════════════════════════════════════════════════════════════
|
|
12
|
+
*/
|
|
13
|
+
interface NovapsisClientOptions {
|
|
14
|
+
/** Clave de API de Novapsis (empieza por nvs_live_ o nvs_test_) */
|
|
15
|
+
apiKey: string;
|
|
16
|
+
/** URL base de la API (por defecto: https://app.novapsis.com) */
|
|
17
|
+
baseUrl?: string;
|
|
18
|
+
/** Timeout en milisegundos para peticiones HTTP (por defecto: 15000) */
|
|
19
|
+
timeoutMs?: number;
|
|
20
|
+
/** Número máximo de reintentos automáticos ante fallos de red transitorios (por defecto: 2) */
|
|
21
|
+
maxRetries?: number;
|
|
22
|
+
}
|
|
23
|
+
interface APIResponse<T = any> {
|
|
24
|
+
success: boolean;
|
|
25
|
+
data?: T;
|
|
26
|
+
error?: {
|
|
27
|
+
code: string;
|
|
28
|
+
message: string;
|
|
29
|
+
details?: any;
|
|
30
|
+
};
|
|
31
|
+
}
|
|
32
|
+
declare class NovapsisAPIError extends Error {
|
|
33
|
+
readonly code: string;
|
|
34
|
+
readonly status: number;
|
|
35
|
+
readonly details?: any;
|
|
36
|
+
constructor(message: string, code?: string, status?: number, details?: any);
|
|
37
|
+
}
|
|
38
|
+
interface SendBaseOptions {
|
|
39
|
+
/** Número destinatario con código de país, sin '+' ni espacios (ej: '34600112233') */
|
|
40
|
+
to: string;
|
|
41
|
+
/** UUID de la conexión o Phone Number ID de Meta desde el cual enviar. Si se omite, usa la línea principal. */
|
|
42
|
+
connectionId?: string;
|
|
43
|
+
}
|
|
44
|
+
interface SendTextOptions extends SendBaseOptions {
|
|
45
|
+
/** Cuerpo del mensaje de texto */
|
|
46
|
+
text: string;
|
|
47
|
+
/** Si es true, genera vista previa de los enlaces web incluidos en el texto */
|
|
48
|
+
previewUrl?: boolean;
|
|
49
|
+
}
|
|
50
|
+
interface SendImageOptions extends SendBaseOptions {
|
|
51
|
+
/** URL HTTPS pública de la imagen (JPG, PNG, WebP) */
|
|
52
|
+
imageUrl: string;
|
|
53
|
+
/** Pie de foto opcional */
|
|
54
|
+
caption?: string;
|
|
55
|
+
}
|
|
56
|
+
interface SendAudioOptions extends SendBaseOptions {
|
|
57
|
+
/** URL HTTPS pública del archivo de audio (MP3, AAC, OGG, M4A) */
|
|
58
|
+
audioUrl: string;
|
|
59
|
+
}
|
|
60
|
+
interface SendDocumentOptions extends SendBaseOptions {
|
|
61
|
+
/** URL HTTPS pública del documento o PDF */
|
|
62
|
+
documentUrl: string;
|
|
63
|
+
/** Nombre visible del archivo (ej: 'factura_2026.pdf') */
|
|
64
|
+
filename?: string;
|
|
65
|
+
/** Descripción o pie opcional */
|
|
66
|
+
caption?: string;
|
|
67
|
+
}
|
|
68
|
+
interface SendVideoOptions extends SendBaseOptions {
|
|
69
|
+
/** URL HTTPS pública del video (MP4, 3GP) */
|
|
70
|
+
videoUrl: string;
|
|
71
|
+
/** Pie de video opcional */
|
|
72
|
+
caption?: string;
|
|
73
|
+
}
|
|
74
|
+
interface SendLocationOptions extends SendBaseOptions {
|
|
75
|
+
/** Coordenada de latitud decimal (ej: 40.416775) */
|
|
76
|
+
latitude: number | string;
|
|
77
|
+
/** Coordenada de longitud decimal (ej: -3.703790) */
|
|
78
|
+
longitude: number | string;
|
|
79
|
+
/** Nombre del lugar o establecimiento (ej: 'Sede Central Madrid') */
|
|
80
|
+
name?: string;
|
|
81
|
+
/** Dirección postal completa */
|
|
82
|
+
address?: string;
|
|
83
|
+
}
|
|
84
|
+
interface SendContactCardOptions extends SendBaseOptions {
|
|
85
|
+
/** Nombre completo del contacto a compartir */
|
|
86
|
+
name: string;
|
|
87
|
+
/** Número de teléfono del contacto compartido */
|
|
88
|
+
phone: string;
|
|
89
|
+
}
|
|
90
|
+
interface SendTemplateOptions extends SendBaseOptions {
|
|
91
|
+
/** Nombre exacto de la plantilla aprobada en Meta */
|
|
92
|
+
templateName: string;
|
|
93
|
+
/** Código de idioma (por defecto: 'es') */
|
|
94
|
+
languageCode?: string;
|
|
95
|
+
/** Componentes y variables dinámicas de la plantilla */
|
|
96
|
+
components?: Array<{
|
|
97
|
+
type: 'header' | 'body' | 'button';
|
|
98
|
+
sub_type?: string;
|
|
99
|
+
index?: string | number;
|
|
100
|
+
parameters?: Array<{
|
|
101
|
+
type: 'text' | 'image' | 'document' | 'video' | 'currency' | 'date_time';
|
|
102
|
+
text?: string;
|
|
103
|
+
[key: string]: any;
|
|
104
|
+
}>;
|
|
105
|
+
}>;
|
|
106
|
+
}
|
|
107
|
+
interface SendMessageResult {
|
|
108
|
+
message_id: string;
|
|
109
|
+
recipient: string;
|
|
110
|
+
type: string;
|
|
111
|
+
status: string;
|
|
112
|
+
conversation_id: string | null;
|
|
113
|
+
}
|
|
114
|
+
interface WhatsAppConnection {
|
|
115
|
+
id: string;
|
|
116
|
+
display_name: string;
|
|
117
|
+
phone_number: string | null;
|
|
118
|
+
phone_number_id: string;
|
|
119
|
+
verified_name: string | null;
|
|
120
|
+
status: string;
|
|
121
|
+
webhook_subscribed: boolean;
|
|
122
|
+
}
|
|
123
|
+
interface WhatsAppTemplate {
|
|
124
|
+
id: string;
|
|
125
|
+
name: string;
|
|
126
|
+
category: string;
|
|
127
|
+
language: string;
|
|
128
|
+
status: string;
|
|
129
|
+
components: any[];
|
|
130
|
+
}
|
|
131
|
+
interface CreateOnboardingSessionOptions {
|
|
132
|
+
/** Nombre de la empresa, cliente o sede a mostrar en la pantalla de conexión */
|
|
133
|
+
clientName?: string;
|
|
134
|
+
/** URL de retorno a la que redirigir al usuario cuando vincule su WhatsApp */
|
|
135
|
+
redirectUrl?: string;
|
|
136
|
+
/** URL del logotipo de la empresa cliente para marca blanca */
|
|
137
|
+
logoUrl?: string;
|
|
138
|
+
/** Color hexadecimal corporativo para la interfaz de conexión (ej: '#0ea5e9') */
|
|
139
|
+
brandColor?: string;
|
|
140
|
+
/** Metadata personalizada para tracking en tu CRM */
|
|
141
|
+
metadata?: Record<string, any>;
|
|
142
|
+
}
|
|
143
|
+
interface OnboardingSession {
|
|
144
|
+
id: string;
|
|
145
|
+
session_id: string;
|
|
146
|
+
session_url: string;
|
|
147
|
+
status: 'started' | 'completed' | 'expired' | 'failed';
|
|
148
|
+
expires_at: string;
|
|
149
|
+
created_at: string;
|
|
150
|
+
}
|
|
151
|
+
type NovapsisWebhookEvent = 'whatsapp.message_received' | 'whatsapp.message_sent' | 'whatsapp.connected' | 'conversation.started' | 'lead.completed' | 'call.completed' | 'review.received' | '*';
|
|
152
|
+
interface CreateWebhookSubscriptionOptions {
|
|
153
|
+
/** Nombre descriptivo de la suscripción (ej: 'CRM Sincronizador') */
|
|
154
|
+
name: string;
|
|
155
|
+
/** URL HTTPS de tu backend que recibirá los eventos POST */
|
|
156
|
+
url: string;
|
|
157
|
+
/** Lista de eventos a escuchar */
|
|
158
|
+
events: NovapsisWebhookEvent[];
|
|
159
|
+
/** Secreto opcional para firma HMAC. Si se omite, Novapsis generará uno automáticamente. */
|
|
160
|
+
secret?: string;
|
|
161
|
+
}
|
|
162
|
+
interface WebhookSubscription {
|
|
163
|
+
id: string;
|
|
164
|
+
name: string;
|
|
165
|
+
url: string;
|
|
166
|
+
events: string[];
|
|
167
|
+
secret: string;
|
|
168
|
+
is_active: boolean;
|
|
169
|
+
created_at: string;
|
|
170
|
+
}
|
|
171
|
+
interface InboundWebhookPayload<T = any> {
|
|
172
|
+
event: NovapsisWebhookEvent;
|
|
173
|
+
timestamp: string;
|
|
174
|
+
organization_id: string;
|
|
175
|
+
data: T;
|
|
176
|
+
}
|
|
177
|
+
interface UpsertContactOptions {
|
|
178
|
+
phone: string;
|
|
179
|
+
name?: string;
|
|
180
|
+
email?: string;
|
|
181
|
+
tags?: string[];
|
|
182
|
+
metadata?: Record<string, any>;
|
|
183
|
+
}
|
|
184
|
+
interface Contact {
|
|
185
|
+
id: string;
|
|
186
|
+
phone: string;
|
|
187
|
+
name: string | null;
|
|
188
|
+
email: string | null;
|
|
189
|
+
tags: string[];
|
|
190
|
+
created_at: string;
|
|
191
|
+
}
|
|
192
|
+
declare class HttpClient {
|
|
193
|
+
private apiKey;
|
|
194
|
+
private baseUrl;
|
|
195
|
+
private timeoutMs;
|
|
196
|
+
private maxRetries;
|
|
197
|
+
constructor(options: NovapsisClientOptions);
|
|
198
|
+
request<T>(method: string, path: string, body?: any, query?: Record<string, string>): Promise<T>;
|
|
199
|
+
}
|
|
200
|
+
/** Servicio para envíos y gestión de WhatsApp Cloud API */
|
|
201
|
+
declare class WhatsAppService {
|
|
202
|
+
private http;
|
|
203
|
+
constructor(http: HttpClient);
|
|
204
|
+
/** Envía un mensaje de texto plano */
|
|
205
|
+
sendText(options: SendTextOptions): Promise<SendMessageResult>;
|
|
206
|
+
/** Envía una imagen o fotografía */
|
|
207
|
+
sendImage(options: SendImageOptions): Promise<SendMessageResult>;
|
|
208
|
+
/** Envía un archivo de audio o nota de voz */
|
|
209
|
+
sendAudio(options: SendAudioOptions): Promise<SendMessageResult>;
|
|
210
|
+
/** Envía un documento (PDF, Word, Excel, etc.) con nombre de archivo personalizado */
|
|
211
|
+
sendDocument(options: SendDocumentOptions): Promise<SendMessageResult>;
|
|
212
|
+
/** Envía un video */
|
|
213
|
+
sendVideo(options: SendVideoOptions): Promise<SendMessageResult>;
|
|
214
|
+
/** Envía una ubicación con coordenadas y dirección en el mapa */
|
|
215
|
+
sendLocation(options: SendLocationOptions): Promise<SendMessageResult>;
|
|
216
|
+
/** Envía una tarjeta de contacto (vCard) interactiva */
|
|
217
|
+
sendContact(options: SendContactCardOptions): Promise<SendMessageResult>;
|
|
218
|
+
/** Envía una plantilla oficial aprobada por Meta con variables dinámicas */
|
|
219
|
+
sendTemplate(options: SendTemplateOptions): Promise<SendMessageResult>;
|
|
220
|
+
/** Marca un mensaje o chat como leído */
|
|
221
|
+
markAsRead(options: {
|
|
222
|
+
to: string;
|
|
223
|
+
connectionId?: string;
|
|
224
|
+
messageId?: string;
|
|
225
|
+
}): Promise<any>;
|
|
226
|
+
/** Obtiene la lista de líneas y números de WhatsApp conectados en la organización */
|
|
227
|
+
listConnections(): Promise<WhatsAppConnection[]>;
|
|
228
|
+
/** Obtiene las plantillas oficiales de Meta aprobadas */
|
|
229
|
+
getTemplates(): Promise<WhatsAppTemplate[]>;
|
|
230
|
+
/** Crea una nueva plantilla para enviar a revisión a Meta */
|
|
231
|
+
createTemplate(options: {
|
|
232
|
+
name: string;
|
|
233
|
+
category: 'MARKETING' | 'UTILITY' | 'AUTHENTICATION';
|
|
234
|
+
bodyText: string;
|
|
235
|
+
}): Promise<any>;
|
|
236
|
+
/** Lista las campañas masivas de WhatsApp configuradas */
|
|
237
|
+
listCampaigns(): Promise<any[]>;
|
|
238
|
+
/** Ejecuta una campaña masiva */
|
|
239
|
+
executeCampaign(campaignId: string): Promise<any>;
|
|
240
|
+
}
|
|
241
|
+
/** Servicio para onboarding y conexión de WhatsApp de clientes B2B (Marca Blanca) */
|
|
242
|
+
declare class OnboardingService {
|
|
243
|
+
private http;
|
|
244
|
+
constructor(http: HttpClient);
|
|
245
|
+
/**
|
|
246
|
+
* Crea una sesión de conexión hosted para que un cliente o sede vincule su WhatsApp.
|
|
247
|
+
* Devuelve `session_url` que puedes abrir en un modal o popup en tu CRM.
|
|
248
|
+
*/
|
|
249
|
+
createSession(options?: CreateOnboardingSessionOptions): Promise<OnboardingSession>;
|
|
250
|
+
/** Consulta el estado de una sesión de onboarding por su ID */
|
|
251
|
+
getSessionStatus(sessionId: string): Promise<OnboardingSession>;
|
|
252
|
+
}
|
|
253
|
+
/** Servicio para gestionar Webhooks salientes en tiempo real */
|
|
254
|
+
declare class WebhookService {
|
|
255
|
+
private http;
|
|
256
|
+
constructor(http: HttpClient);
|
|
257
|
+
/** Suscribe una URL de tu backend para recibir eventos en tiempo real */
|
|
258
|
+
subscribe(options: CreateWebhookSubscriptionOptions): Promise<WebhookSubscription>;
|
|
259
|
+
/** Lista todas las suscripciones de webhooks activas */
|
|
260
|
+
list(): Promise<WebhookSubscription[]>;
|
|
261
|
+
/** Elimina una suscripción de webhook */
|
|
262
|
+
delete(webhookId: string): Promise<boolean>;
|
|
263
|
+
/**
|
|
264
|
+
* Valida la firma criptográfica HMAC SHA-256 de un webhook recibido de Novapsis SM.
|
|
265
|
+
* Evita ataques de suplantación garantizando que la petición proviene de Novapsis.
|
|
266
|
+
*
|
|
267
|
+
* @param rawBody - El cuerpo crudo recibido en el request (string sin parsear)
|
|
268
|
+
* @param signatureHeader - El header 'X-Novapsis-Signature'
|
|
269
|
+
* @param secret - Tu secreto de webhook de Novapsis
|
|
270
|
+
*/
|
|
271
|
+
verifySignature(rawBody: string, signatureHeader: string | null | undefined, secret: string): boolean;
|
|
272
|
+
}
|
|
273
|
+
/** Servicio para gestionar Contactos del CRM */
|
|
274
|
+
declare class ContactsService {
|
|
275
|
+
private http;
|
|
276
|
+
constructor(http: HttpClient);
|
|
277
|
+
/** Lista contactos del CRM */
|
|
278
|
+
list(): Promise<Contact[]>;
|
|
279
|
+
/** Crea o actualiza un contacto por número de teléfono */
|
|
280
|
+
upsert(options: UpsertContactOptions): Promise<Contact>;
|
|
281
|
+
}
|
|
282
|
+
/** Servicio para interactuar con Agentes de Inteligencia Artificial */
|
|
283
|
+
declare class AIService {
|
|
284
|
+
private http;
|
|
285
|
+
constructor(http: HttpClient);
|
|
286
|
+
/** Lista los agentes de IA configurados con sus modelos */
|
|
287
|
+
listAgents(): Promise<any[]>;
|
|
288
|
+
/** Ejecuta una consulta contra un agente de IA con su base de conocimiento RAG */
|
|
289
|
+
execute(options: {
|
|
290
|
+
agentId: string;
|
|
291
|
+
message: string;
|
|
292
|
+
}): Promise<{
|
|
293
|
+
response: string;
|
|
294
|
+
tokens_used?: number;
|
|
295
|
+
}>;
|
|
296
|
+
}
|
|
297
|
+
/**
|
|
298
|
+
* Cliente oficial de Novapsis SM.
|
|
299
|
+
* Punto de entrada principal para interactuar con todos los servicios.
|
|
300
|
+
*
|
|
301
|
+
* @example
|
|
302
|
+
* ```typescript
|
|
303
|
+
* import { Novapsis } from 'novapsis';
|
|
304
|
+
*
|
|
305
|
+
* const client = new Novapsis({
|
|
306
|
+
* apiKey: 'nvs_live_OfnAAb6sEGztGcdbR5IKnhFpPrDJSTq7',
|
|
307
|
+
* });
|
|
308
|
+
*
|
|
309
|
+
* // Enviar mensaje de texto
|
|
310
|
+
* await client.whatsapp.sendText({
|
|
311
|
+
* to: '34600112233',
|
|
312
|
+
* text: '¡Hola desde Novapsis SDK!'
|
|
313
|
+
* });
|
|
314
|
+
* ```
|
|
315
|
+
*/
|
|
316
|
+
declare class Novapsis {
|
|
317
|
+
private http;
|
|
318
|
+
/** Métodos para envíos y operaciones de WhatsApp */
|
|
319
|
+
readonly whatsapp: WhatsAppService;
|
|
320
|
+
/** Métodos para onboarding hosted y vinculación B2B */
|
|
321
|
+
readonly onboarding: OnboardingService;
|
|
322
|
+
/** Métodos para suscripción y validación de Webhooks */
|
|
323
|
+
readonly webhooks: WebhookService;
|
|
324
|
+
/** Métodos para contactos del CRM */
|
|
325
|
+
readonly contacts: ContactsService;
|
|
326
|
+
/** Métodos para Agentes de Inteligencia Artificial */
|
|
327
|
+
readonly ai: AIService;
|
|
328
|
+
constructor(options: NovapsisClientOptions);
|
|
329
|
+
}
|
|
330
|
+
|
|
331
|
+
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, Novapsis as default };
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,333 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* novapsis - Official TypeScript / JavaScript SDK
|
|
3
|
+
* ══════════════════════════════════════════════════════════════════════════════
|
|
4
|
+
* Official SDK for Novapsis SM.
|
|
5
|
+
* Universal typed client for WhatsApp Business Cloud API, Hosted Onboarding,
|
|
6
|
+
* CRM, AI Agents and HMAC Webhook Verification.
|
|
7
|
+
*
|
|
8
|
+
* @version 1.0.0
|
|
9
|
+
* @author Novapsis Technologies
|
|
10
|
+
* @license MIT
|
|
11
|
+
* ══════════════════════════════════════════════════════════════════════════════
|
|
12
|
+
*/
|
|
13
|
+
interface NovapsisClientOptions {
|
|
14
|
+
/** Clave de API de Novapsis (empieza por nvs_live_ o nvs_test_) */
|
|
15
|
+
apiKey: string;
|
|
16
|
+
/** URL base de la API (por defecto: https://app.novapsis.com) */
|
|
17
|
+
baseUrl?: string;
|
|
18
|
+
/** Timeout en milisegundos para peticiones HTTP (por defecto: 15000) */
|
|
19
|
+
timeoutMs?: number;
|
|
20
|
+
/** Número máximo de reintentos automáticos ante fallos de red transitorios (por defecto: 2) */
|
|
21
|
+
maxRetries?: number;
|
|
22
|
+
}
|
|
23
|
+
interface APIResponse<T = any> {
|
|
24
|
+
success: boolean;
|
|
25
|
+
data?: T;
|
|
26
|
+
error?: {
|
|
27
|
+
code: string;
|
|
28
|
+
message: string;
|
|
29
|
+
details?: any;
|
|
30
|
+
};
|
|
31
|
+
}
|
|
32
|
+
declare class NovapsisAPIError extends Error {
|
|
33
|
+
readonly code: string;
|
|
34
|
+
readonly status: number;
|
|
35
|
+
readonly details?: any;
|
|
36
|
+
constructor(message: string, code?: string, status?: number, details?: any);
|
|
37
|
+
}
|
|
38
|
+
interface SendBaseOptions {
|
|
39
|
+
/** Número destinatario con código de país, sin '+' ni espacios (ej: '34600112233') */
|
|
40
|
+
to: string;
|
|
41
|
+
/** UUID de la conexión o Phone Number ID de Meta desde el cual enviar. Si se omite, usa la línea principal. */
|
|
42
|
+
connectionId?: string;
|
|
43
|
+
}
|
|
44
|
+
interface SendTextOptions extends SendBaseOptions {
|
|
45
|
+
/** Cuerpo del mensaje de texto */
|
|
46
|
+
text: string;
|
|
47
|
+
/** Si es true, genera vista previa de los enlaces web incluidos en el texto */
|
|
48
|
+
previewUrl?: boolean;
|
|
49
|
+
}
|
|
50
|
+
interface SendImageOptions extends SendBaseOptions {
|
|
51
|
+
/** URL HTTPS pública de la imagen (JPG, PNG, WebP) */
|
|
52
|
+
imageUrl: string;
|
|
53
|
+
/** Pie de foto opcional */
|
|
54
|
+
caption?: string;
|
|
55
|
+
}
|
|
56
|
+
interface SendAudioOptions extends SendBaseOptions {
|
|
57
|
+
/** URL HTTPS pública del archivo de audio (MP3, AAC, OGG, M4A) */
|
|
58
|
+
audioUrl: string;
|
|
59
|
+
}
|
|
60
|
+
interface SendDocumentOptions extends SendBaseOptions {
|
|
61
|
+
/** URL HTTPS pública del documento o PDF */
|
|
62
|
+
documentUrl: string;
|
|
63
|
+
/** Nombre visible del archivo (ej: 'factura_2026.pdf') */
|
|
64
|
+
filename?: string;
|
|
65
|
+
/** Descripción o pie opcional */
|
|
66
|
+
caption?: string;
|
|
67
|
+
}
|
|
68
|
+
interface SendVideoOptions extends SendBaseOptions {
|
|
69
|
+
/** URL HTTPS pública del video (MP4, 3GP) */
|
|
70
|
+
videoUrl: string;
|
|
71
|
+
/** Pie de video opcional */
|
|
72
|
+
caption?: string;
|
|
73
|
+
}
|
|
74
|
+
interface SendLocationOptions extends SendBaseOptions {
|
|
75
|
+
/** Coordenada de latitud decimal (ej: 40.416775) */
|
|
76
|
+
latitude: number | string;
|
|
77
|
+
/** Coordenada de longitud decimal (ej: -3.703790) */
|
|
78
|
+
longitude: number | string;
|
|
79
|
+
/** Nombre del lugar o establecimiento (ej: 'Sede Central Madrid') */
|
|
80
|
+
name?: string;
|
|
81
|
+
/** Dirección postal completa */
|
|
82
|
+
address?: string;
|
|
83
|
+
}
|
|
84
|
+
interface SendContactCardOptions extends SendBaseOptions {
|
|
85
|
+
/** Nombre completo del contacto a compartir */
|
|
86
|
+
name: string;
|
|
87
|
+
/** Número de teléfono del contacto compartido */
|
|
88
|
+
phone: string;
|
|
89
|
+
}
|
|
90
|
+
interface SendTemplateOptions extends SendBaseOptions {
|
|
91
|
+
/** Nombre exacto de la plantilla aprobada en Meta */
|
|
92
|
+
templateName: string;
|
|
93
|
+
/** Código de idioma (por defecto: 'es') */
|
|
94
|
+
languageCode?: string;
|
|
95
|
+
/** Componentes y variables dinámicas de la plantilla */
|
|
96
|
+
components?: Array<{
|
|
97
|
+
type: 'header' | 'body' | 'button';
|
|
98
|
+
sub_type?: string;
|
|
99
|
+
index?: string | number;
|
|
100
|
+
parameters?: Array<{
|
|
101
|
+
type: 'text' | 'image' | 'document' | 'video' | 'currency' | 'date_time';
|
|
102
|
+
text?: string;
|
|
103
|
+
[key: string]: any;
|
|
104
|
+
}>;
|
|
105
|
+
}>;
|
|
106
|
+
}
|
|
107
|
+
interface SendMessageResult {
|
|
108
|
+
message_id: string;
|
|
109
|
+
recipient: string;
|
|
110
|
+
type: string;
|
|
111
|
+
status: string;
|
|
112
|
+
conversation_id: string | null;
|
|
113
|
+
}
|
|
114
|
+
interface WhatsAppConnection {
|
|
115
|
+
id: string;
|
|
116
|
+
display_name: string;
|
|
117
|
+
phone_number: string | null;
|
|
118
|
+
phone_number_id: string;
|
|
119
|
+
verified_name: string | null;
|
|
120
|
+
status: string;
|
|
121
|
+
webhook_subscribed: boolean;
|
|
122
|
+
}
|
|
123
|
+
interface WhatsAppTemplate {
|
|
124
|
+
id: string;
|
|
125
|
+
name: string;
|
|
126
|
+
category: string;
|
|
127
|
+
language: string;
|
|
128
|
+
status: string;
|
|
129
|
+
components: any[];
|
|
130
|
+
}
|
|
131
|
+
interface CreateOnboardingSessionOptions {
|
|
132
|
+
/** Nombre de la empresa, cliente o sede a mostrar en la pantalla de conexión */
|
|
133
|
+
clientName?: string;
|
|
134
|
+
/** URL de retorno a la que redirigir al usuario cuando vincule su WhatsApp */
|
|
135
|
+
redirectUrl?: string;
|
|
136
|
+
/** URL del logotipo de la empresa cliente para marca blanca */
|
|
137
|
+
logoUrl?: string;
|
|
138
|
+
/** Color hexadecimal corporativo para la interfaz de conexión (ej: '#0ea5e9') */
|
|
139
|
+
brandColor?: string;
|
|
140
|
+
/** Metadata personalizada para tracking en tu CRM */
|
|
141
|
+
metadata?: Record<string, any>;
|
|
142
|
+
}
|
|
143
|
+
interface OnboardingSession {
|
|
144
|
+
id: string;
|
|
145
|
+
session_id: string;
|
|
146
|
+
session_url: string;
|
|
147
|
+
status: 'started' | 'completed' | 'expired' | 'failed';
|
|
148
|
+
expires_at: string;
|
|
149
|
+
created_at: string;
|
|
150
|
+
}
|
|
151
|
+
type NovapsisWebhookEvent = 'whatsapp.message_received' | 'whatsapp.message_sent' | 'whatsapp.connected' | 'conversation.started' | 'lead.completed' | 'call.completed' | 'review.received' | '*';
|
|
152
|
+
interface CreateWebhookSubscriptionOptions {
|
|
153
|
+
/** Nombre descriptivo de la suscripción (ej: 'CRM Sincronizador') */
|
|
154
|
+
name: string;
|
|
155
|
+
/** URL HTTPS de tu backend que recibirá los eventos POST */
|
|
156
|
+
url: string;
|
|
157
|
+
/** Lista de eventos a escuchar */
|
|
158
|
+
events: NovapsisWebhookEvent[];
|
|
159
|
+
/** Secreto opcional para firma HMAC. Si se omite, Novapsis generará uno automáticamente. */
|
|
160
|
+
secret?: string;
|
|
161
|
+
}
|
|
162
|
+
interface WebhookSubscription {
|
|
163
|
+
id: string;
|
|
164
|
+
name: string;
|
|
165
|
+
url: string;
|
|
166
|
+
events: string[];
|
|
167
|
+
secret: string;
|
|
168
|
+
is_active: boolean;
|
|
169
|
+
created_at: string;
|
|
170
|
+
}
|
|
171
|
+
interface InboundWebhookPayload<T = any> {
|
|
172
|
+
event: NovapsisWebhookEvent;
|
|
173
|
+
timestamp: string;
|
|
174
|
+
organization_id: string;
|
|
175
|
+
data: T;
|
|
176
|
+
}
|
|
177
|
+
interface UpsertContactOptions {
|
|
178
|
+
phone: string;
|
|
179
|
+
name?: string;
|
|
180
|
+
email?: string;
|
|
181
|
+
tags?: string[];
|
|
182
|
+
metadata?: Record<string, any>;
|
|
183
|
+
}
|
|
184
|
+
interface Contact {
|
|
185
|
+
id: string;
|
|
186
|
+
phone: string;
|
|
187
|
+
name: string | null;
|
|
188
|
+
email: string | null;
|
|
189
|
+
tags: string[];
|
|
190
|
+
created_at: string;
|
|
191
|
+
}
|
|
192
|
+
declare class HttpClient {
|
|
193
|
+
private apiKey;
|
|
194
|
+
private baseUrl;
|
|
195
|
+
private timeoutMs;
|
|
196
|
+
private maxRetries;
|
|
197
|
+
constructor(options: NovapsisClientOptions);
|
|
198
|
+
request<T>(method: string, path: string, body?: any, query?: Record<string, string>): Promise<T>;
|
|
199
|
+
}
|
|
200
|
+
/** Servicio para envíos y gestión de WhatsApp Cloud API */
|
|
201
|
+
declare class WhatsAppService {
|
|
202
|
+
private http;
|
|
203
|
+
constructor(http: HttpClient);
|
|
204
|
+
/** Envía un mensaje de texto plano */
|
|
205
|
+
sendText(options: SendTextOptions): Promise<SendMessageResult>;
|
|
206
|
+
/** Envía una imagen o fotografía */
|
|
207
|
+
sendImage(options: SendImageOptions): Promise<SendMessageResult>;
|
|
208
|
+
/** Envía un archivo de audio o nota de voz */
|
|
209
|
+
sendAudio(options: SendAudioOptions): Promise<SendMessageResult>;
|
|
210
|
+
/** Envía un documento (PDF, Word, Excel, etc.) con nombre de archivo personalizado */
|
|
211
|
+
sendDocument(options: SendDocumentOptions): Promise<SendMessageResult>;
|
|
212
|
+
/** Envía un video */
|
|
213
|
+
sendVideo(options: SendVideoOptions): Promise<SendMessageResult>;
|
|
214
|
+
/** Envía una ubicación con coordenadas y dirección en el mapa */
|
|
215
|
+
sendLocation(options: SendLocationOptions): Promise<SendMessageResult>;
|
|
216
|
+
/** Envía una tarjeta de contacto (vCard) interactiva */
|
|
217
|
+
sendContact(options: SendContactCardOptions): Promise<SendMessageResult>;
|
|
218
|
+
/** Envía una plantilla oficial aprobada por Meta con variables dinámicas */
|
|
219
|
+
sendTemplate(options: SendTemplateOptions): Promise<SendMessageResult>;
|
|
220
|
+
/** Marca un mensaje o chat como leído */
|
|
221
|
+
markAsRead(options: {
|
|
222
|
+
to: string;
|
|
223
|
+
connectionId?: string;
|
|
224
|
+
messageId?: string;
|
|
225
|
+
}): Promise<any>;
|
|
226
|
+
/** Obtiene la lista de líneas y números de WhatsApp conectados en la organización */
|
|
227
|
+
listConnections(): Promise<WhatsAppConnection[]>;
|
|
228
|
+
/** Obtiene las plantillas oficiales de Meta aprobadas */
|
|
229
|
+
getTemplates(): Promise<WhatsAppTemplate[]>;
|
|
230
|
+
/** Crea una nueva plantilla para enviar a revisión a Meta */
|
|
231
|
+
createTemplate(options: {
|
|
232
|
+
name: string;
|
|
233
|
+
category: 'MARKETING' | 'UTILITY' | 'AUTHENTICATION';
|
|
234
|
+
bodyText: string;
|
|
235
|
+
}): Promise<any>;
|
|
236
|
+
/** Lista las campañas masivas de WhatsApp configuradas */
|
|
237
|
+
listCampaigns(): Promise<any[]>;
|
|
238
|
+
/** Ejecuta una campaña masiva */
|
|
239
|
+
executeCampaign(campaignId: string): Promise<any>;
|
|
240
|
+
}
|
|
241
|
+
/** Servicio para onboarding y conexión de WhatsApp de clientes B2B (Marca Blanca) */
|
|
242
|
+
declare class OnboardingService {
|
|
243
|
+
private http;
|
|
244
|
+
constructor(http: HttpClient);
|
|
245
|
+
/**
|
|
246
|
+
* Crea una sesión de conexión hosted para que un cliente o sede vincule su WhatsApp.
|
|
247
|
+
* Devuelve `session_url` que puedes abrir en un modal o popup en tu CRM.
|
|
248
|
+
*/
|
|
249
|
+
createSession(options?: CreateOnboardingSessionOptions): Promise<OnboardingSession>;
|
|
250
|
+
/** Consulta el estado de una sesión de onboarding por su ID */
|
|
251
|
+
getSessionStatus(sessionId: string): Promise<OnboardingSession>;
|
|
252
|
+
}
|
|
253
|
+
/** Servicio para gestionar Webhooks salientes en tiempo real */
|
|
254
|
+
declare class WebhookService {
|
|
255
|
+
private http;
|
|
256
|
+
constructor(http: HttpClient);
|
|
257
|
+
/** Suscribe una URL de tu backend para recibir eventos en tiempo real */
|
|
258
|
+
subscribe(options: CreateWebhookSubscriptionOptions): Promise<WebhookSubscription>;
|
|
259
|
+
/** Lista todas las suscripciones de webhooks activas */
|
|
260
|
+
list(): Promise<WebhookSubscription[]>;
|
|
261
|
+
/** Elimina una suscripción de webhook */
|
|
262
|
+
delete(webhookId: string): Promise<boolean>;
|
|
263
|
+
/**
|
|
264
|
+
* Valida la firma criptográfica HMAC SHA-256 de un webhook recibido de Novapsis SM.
|
|
265
|
+
* Evita ataques de suplantación garantizando que la petición proviene de Novapsis.
|
|
266
|
+
*
|
|
267
|
+
* @param rawBody - El cuerpo crudo recibido en el request (string sin parsear)
|
|
268
|
+
* @param signatureHeader - El header 'X-Novapsis-Signature'
|
|
269
|
+
* @param secret - Tu secreto de webhook de Novapsis
|
|
270
|
+
*/
|
|
271
|
+
verifySignature(rawBody: string, signatureHeader: string | null | undefined, secret: string): boolean;
|
|
272
|
+
}
|
|
273
|
+
/** Servicio para gestionar Contactos del CRM */
|
|
274
|
+
declare class ContactsService {
|
|
275
|
+
private http;
|
|
276
|
+
constructor(http: HttpClient);
|
|
277
|
+
/** Lista contactos del CRM */
|
|
278
|
+
list(): Promise<Contact[]>;
|
|
279
|
+
/** Crea o actualiza un contacto por número de teléfono */
|
|
280
|
+
upsert(options: UpsertContactOptions): Promise<Contact>;
|
|
281
|
+
}
|
|
282
|
+
/** Servicio para interactuar con Agentes de Inteligencia Artificial */
|
|
283
|
+
declare class AIService {
|
|
284
|
+
private http;
|
|
285
|
+
constructor(http: HttpClient);
|
|
286
|
+
/** Lista los agentes de IA configurados con sus modelos */
|
|
287
|
+
listAgents(): Promise<any[]>;
|
|
288
|
+
/** Ejecuta una consulta contra un agente de IA con su base de conocimiento RAG */
|
|
289
|
+
execute(options: {
|
|
290
|
+
agentId: string;
|
|
291
|
+
message: string;
|
|
292
|
+
}): Promise<{
|
|
293
|
+
response: string;
|
|
294
|
+
tokens_used?: number;
|
|
295
|
+
}>;
|
|
296
|
+
}
|
|
297
|
+
/**
|
|
298
|
+
* Cliente oficial de Novapsis SM.
|
|
299
|
+
* Punto de entrada principal para interactuar con todos los servicios.
|
|
300
|
+
*
|
|
301
|
+
* @example
|
|
302
|
+
* ```typescript
|
|
303
|
+
* import { Novapsis } from 'novapsis';
|
|
304
|
+
*
|
|
305
|
+
* const client = new Novapsis({
|
|
306
|
+
* apiKey: 'nvs_live_OfnAAb6sEGztGcdbR5IKnhFpPrDJSTq7',
|
|
307
|
+
* });
|
|
308
|
+
*
|
|
309
|
+
* // Enviar mensaje de texto
|
|
310
|
+
* await client.whatsapp.sendText({
|
|
311
|
+
* to: '34600112233',
|
|
312
|
+
* text: '¡Hola desde Novapsis SDK!'
|
|
313
|
+
* });
|
|
314
|
+
* ```
|
|
315
|
+
*/
|
|
316
|
+
declare class Novapsis {
|
|
317
|
+
private http;
|
|
318
|
+
/** Métodos para envíos y operaciones de WhatsApp */
|
|
319
|
+
readonly whatsapp: WhatsAppService;
|
|
320
|
+
/** Métodos para onboarding hosted y vinculación B2B */
|
|
321
|
+
readonly onboarding: OnboardingService;
|
|
322
|
+
/** Métodos para suscripción y validación de Webhooks */
|
|
323
|
+
readonly webhooks: WebhookService;
|
|
324
|
+
/** Métodos para contactos del CRM */
|
|
325
|
+
readonly contacts: ContactsService;
|
|
326
|
+
/** Métodos para Agentes de Inteligencia Artificial */
|
|
327
|
+
readonly ai: AIService;
|
|
328
|
+
constructor(options: NovapsisClientOptions);
|
|
329
|
+
}
|
|
330
|
+
|
|
331
|
+
// @ts-ignore
|
|
332
|
+
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 };
|