@in.pulse-crm/sdk 2.14.8 → 2.15.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.
@@ -0,0 +1,378 @@
1
+ import type {
2
+ CustomerAgeLevel,
3
+ CustomerInteractionLevel,
4
+ CustomerProfileSummaryLevel,
5
+ CustomerPurchaseInterestLevel,
6
+ CustomerPurchaseLevel,
7
+ WppContactWithCustomer,
8
+ } from "./whatsapp.types";
9
+
10
+ export interface SuggestResponseRequest {
11
+ chatId: number;
12
+ }
13
+
14
+ export interface SuggestResponseResponse {
15
+ suggestions: string[];
16
+ }
17
+
18
+ export interface SummarizeChatRequest {
19
+ chatId: number;
20
+ }
21
+
22
+ export interface SummarizeChatResponse {
23
+ summary: string;
24
+ }
25
+
26
+ export interface AnalyzeCustomerRequest {
27
+ customerId: number;
28
+ }
29
+
30
+ export interface AnalyzeCustomerResponse {
31
+ analysis: string;
32
+ }
33
+
34
+ export type SupervisorAiSessionStatus = "ACTIVE" | "ARCHIVED";
35
+
36
+ export type SupervisorAiMessageRole = "USER" | "ASSISTANT";
37
+
38
+ export type SupervisorAiReportFormat = "csv" | "pdf" | "txt";
39
+
40
+ export interface SupervisorAiContextInput {
41
+ chatId?: number;
42
+ customerId?: number;
43
+ dateFrom?: string;
44
+ dateTo?: string;
45
+ operatorIds?: number[];
46
+ sectorIds?: number[];
47
+ includeMetrics?: boolean;
48
+ }
49
+
50
+ export interface SupervisorAiSource {
51
+ type: "action" | "chat" | "contact" | "customer" | "metrics" | "session" | "sql";
52
+ label: string;
53
+ entityId?: number;
54
+ metadata?: Record<string, unknown>;
55
+ }
56
+
57
+ export interface SupervisorAiReportPreview {
58
+ title: string;
59
+ summary: string;
60
+ columns: string[];
61
+ rows: Array<Record<string, string | number | boolean | null>>;
62
+ availableFormats: SupervisorAiReportFormat[];
63
+ }
64
+
65
+ export interface SupervisorAiMessageMetadata {
66
+ context?: SupervisorAiContextInput;
67
+ sources?: SupervisorAiSource[];
68
+ reportPreview?: SupervisorAiReportPreview | null;
69
+ }
70
+
71
+ export interface SupervisorAiSession {
72
+ id: number;
73
+ instance: string;
74
+ userId: number;
75
+ title: string;
76
+ status: SupervisorAiSessionStatus;
77
+ createdAt: string;
78
+ updatedAt: string;
79
+ lastMessageAt: string | null;
80
+ }
81
+
82
+ export interface SupervisorAiMessage {
83
+ id: number;
84
+ sessionId: number;
85
+ role: SupervisorAiMessageRole;
86
+ content: string;
87
+ metadata: SupervisorAiMessageMetadata | null;
88
+ createdAt: string;
89
+ }
90
+
91
+ export interface CreateSupervisorAiSessionRequest {
92
+ title?: string;
93
+ }
94
+
95
+ export interface SupervisorAiFileContext {
96
+ name: string;
97
+ content: string;
98
+ }
99
+
100
+ export interface SendSupervisorAiMessageRequest {
101
+ message: string;
102
+ context?: SupervisorAiContextInput;
103
+ model?: string;
104
+ fileContext?: SupervisorAiFileContext[];
105
+ }
106
+
107
+ export interface SendSupervisorAiMessageResponse {
108
+ session: SupervisorAiSession;
109
+ userMessage: SupervisorAiMessage;
110
+ assistantMessage: SupervisorAiMessage;
111
+ sources: SupervisorAiSource[];
112
+ reportPreview: SupervisorAiReportPreview | null;
113
+ }
114
+
115
+ export interface SupervisorAiSessionDetail {
116
+ session: SupervisorAiSession;
117
+ messages: SupervisorAiMessage[];
118
+ }
119
+
120
+ export interface AiFeatureModels {
121
+ suggest_response?: string;
122
+ summarize_chat?: string;
123
+ analyze_customer?: string;
124
+ supervisor_chat?: string;
125
+ }
126
+
127
+ export interface AiTenantConfig {
128
+ instance: string;
129
+ model: string;
130
+ temperature: number;
131
+ maxTokens: number;
132
+ enabled: boolean;
133
+ monthlyBudgetUsd?: number | null;
134
+ availableModels?: string[] | null;
135
+ featureModels?: AiFeatureModels | null;
136
+ operatorBudgets?: Record<string, number> | null;
137
+ }
138
+
139
+ export interface AiFeatureUsageStat {
140
+ feature: string;
141
+ callCount: number;
142
+ inputTokens: number;
143
+ outputTokens: number;
144
+ estimatedCostUsd: number;
145
+ }
146
+
147
+ export interface AiOperatorUsageStat {
148
+ operatorId: number;
149
+ callCount: number;
150
+ inputTokens: number;
151
+ outputTokens: number;
152
+ estimatedCostUsd: number;
153
+ }
154
+
155
+ export interface AiUsageSummary {
156
+ period: string;
157
+ totalInputTokens: number;
158
+ totalOutputTokens: number;
159
+ estimatedCostUsd: number;
160
+ byFeature: AiFeatureUsageStat[];
161
+ byOperator: AiOperatorUsageStat[];
162
+ }
163
+
164
+ export interface AiAgentConfig {
165
+ instance: string;
166
+ enabled: boolean;
167
+ model: string;
168
+ systemPrompt: string;
169
+ maxMessagesPerChat: number;
170
+ conditions: unknown;
171
+ }
172
+
173
+ // ─── AI Agents (full CRUD) ────────────────────────────────────────────────────
174
+
175
+ export type AiAgentTriggerType = "MESSAGE_DURING_HOURS" | "RESPONSE_TIMEOUT" | "KEYWORD" | "ALWAYS";
176
+
177
+ export type AiAgentProactiveFrequency = "DAILY" | "WEEKDAYS" | "CUSTOM_DAYS";
178
+
179
+ export type AiAgentProactiveEntryMessageMode = "AI_TEXT" | "WABA_TEMPLATE";
180
+
181
+ export type AiAgentActionType =
182
+ | "REPLY"
183
+ | "SEND_TEMPLATE"
184
+ | "SEND_FILE"
185
+ | "ESCALATE"
186
+ | "CLOSE_CHAT"
187
+ | "UPDATE_CRM"
188
+ | "SCHEDULE"
189
+ | "IGNORED";
190
+
191
+ export type AiAgentChatSessionStatus = "ACTIVE" | "PAUSED" | "FINISHED";
192
+
193
+ export interface AiAgentTrigger {
194
+ id: number;
195
+ agentId: number;
196
+ type: AiAgentTriggerType;
197
+ config: Record<string, unknown>;
198
+ }
199
+
200
+ export interface AiAgentAudienceDefinition {
201
+ id: number;
202
+ agentId: number;
203
+ filtersJson: Record<string, unknown>;
204
+ manualIncludeJson: Record<string, unknown>;
205
+ manualExcludeJson: Record<string, unknown>;
206
+ }
207
+
208
+ export interface AiAgentKnowledgeEntry {
209
+ id: number;
210
+ agentId: number;
211
+ title: string;
212
+ content: string;
213
+ fileId: number | null;
214
+ fileName: string | null;
215
+ fileType: string | null;
216
+ fileSize: number | null;
217
+ order: number;
218
+ }
219
+
220
+ export interface AiAgentProactiveSchedule {
221
+ frequency: AiAgentProactiveFrequency;
222
+ timezone: string;
223
+ startTime: string;
224
+ daysOfWeek: number[];
225
+ }
226
+
227
+ export interface AiAgentProactiveConfig {
228
+ enabled: boolean;
229
+ schedule: AiAgentProactiveSchedule;
230
+ batchSize: number;
231
+ entryMessageMode: AiAgentProactiveEntryMessageMode;
232
+ skipContactsWithOpenChat: boolean;
233
+ }
234
+
235
+ export interface AiAgent {
236
+ id: number;
237
+ instance: string;
238
+ name: string;
239
+ description: string | null;
240
+ enabled: boolean;
241
+ systemPrompt: string;
242
+ model: string;
243
+ temperature: number;
244
+ maxTokens: number;
245
+ maxTurnsPerChat: number;
246
+ cooldownSeconds: number;
247
+ allowedActions: AiAgentActionType[];
248
+ proactiveConfig: AiAgentProactiveConfig | null;
249
+ templateName: string | null;
250
+ templateLanguage: string | null;
251
+ templateVariableMapping: Record<string, string> | null;
252
+ escalateToWalletId: number | null;
253
+ escalateToUserId: number | null;
254
+ escalateToUserIds: number[];
255
+ createdAt: string;
256
+ updatedAt: string;
257
+ triggers: AiAgentTrigger[];
258
+ audience: AiAgentAudienceDefinition | null;
259
+ knowledgeEntries: AiAgentKnowledgeEntry[];
260
+ }
261
+
262
+ export interface AiAgentChatSession {
263
+ id: number;
264
+ agentId: number;
265
+ chatId: number;
266
+ instance: string;
267
+ status: AiAgentChatSessionStatus;
268
+ turnCount: number;
269
+ startedAt: string;
270
+ finishedAt: string | null;
271
+ lastRepliedAt: string | null;
272
+ }
273
+
274
+ export interface AiAgentActionLog {
275
+ id: number;
276
+ agentId: number;
277
+ sessionId: number | null;
278
+ chatId: number;
279
+ instance: string;
280
+ actionType: AiAgentActionType;
281
+ success: boolean;
282
+ errorMessage: string | null;
283
+ payload: Record<string, unknown> | null;
284
+ createdAt: string;
285
+ }
286
+
287
+ export interface AiAgentAudienceFilters {
288
+ profileLevel?: CustomerProfileSummaryLevel;
289
+ interactionLevel?: CustomerInteractionLevel;
290
+ purchaseLevel?: CustomerPurchaseLevel;
291
+ ageLevel?: CustomerAgeLevel;
292
+ purchaseInterestLevel?: CustomerPurchaseInterestLevel;
293
+ state?: string;
294
+ city?: string;
295
+ activeCustomer?: "SIM" | "NAO";
296
+ searchTerm?: string;
297
+ segmentIds?: number[];
298
+ campaignIds?: number[];
299
+ operatorIds?: number[];
300
+ }
301
+
302
+ export interface AiAgentManualList {
303
+ contactIds?: number[];
304
+ phones?: string[];
305
+ customerIds?: number[];
306
+ }
307
+
308
+ export interface AiAgentAudienceInput {
309
+ filters?: AiAgentAudienceFilters;
310
+ manualInclude?: AiAgentManualList;
311
+ manualExclude?: AiAgentManualList;
312
+ }
313
+
314
+ export interface AiAgentTriggerInput {
315
+ type: AiAgentTriggerType;
316
+ config?: {
317
+ timeoutMinutes?: number;
318
+ keywords?: string[];
319
+ startTime?: string;
320
+ endTime?: string;
321
+ timezone?: string;
322
+ };
323
+ }
324
+
325
+ export interface AiAgentKnowledgeEntryInput {
326
+ title: string;
327
+ content: string;
328
+ fileId?: number;
329
+ fileName?: string;
330
+ fileType?: string;
331
+ fileSize?: number;
332
+ order?: number;
333
+ }
334
+
335
+ export interface CreateAiAgentInput {
336
+ name: string;
337
+ description?: string;
338
+ enabled?: boolean;
339
+ systemPrompt: string;
340
+ model?: string;
341
+ temperature?: number;
342
+ maxTokens?: number;
343
+ maxTurnsPerChat?: number;
344
+ allowedActions: AiAgentActionType[];
345
+ proactiveConfig?: AiAgentProactiveConfig | null;
346
+ templateName?: string;
347
+ templateLanguage?: string;
348
+ templateVariableMapping?: Record<string, string>;
349
+ escalateToWalletId?: number;
350
+ escalateToUserId?: number;
351
+ escalateToUserIds?: number[];
352
+ triggers?: AiAgentTriggerInput[];
353
+ knowledgeEntries?: AiAgentKnowledgeEntryInput[];
354
+ audience?: AiAgentAudienceInput;
355
+ }
356
+
357
+ export type UpdateAiAgentInput = Partial<CreateAiAgentInput>;
358
+
359
+ export interface AiAgentActionLogFilters {
360
+ agentId?: number;
361
+ chatId?: number;
362
+ actionType?: string;
363
+ success?: boolean;
364
+ dateFrom?: Date;
365
+ dateTo?: Date;
366
+ page?: number;
367
+ perPage?: number;
368
+ }
369
+
370
+ export interface PaginatedActionLogs {
371
+ data: AiAgentActionLog[];
372
+ page: { totalRows: number; current: number };
373
+ }
374
+
375
+ export interface AiAgentAudiencePreview {
376
+ data: WppContactWithCustomer[];
377
+ page: { totalRows: number; current: number };
378
+ }
@@ -76,3 +76,183 @@ export interface CreateCustomerDTO {
76
76
  SETOR?: number | null;
77
77
  }
78
78
  export type UpdateCustomerDTO = Partial<CreateCustomerDTO>;
79
+
80
+ export interface CustomerLookupOption {
81
+ CODIGO: number;
82
+ NOME: string | null;
83
+ }
84
+
85
+ export interface CustomerContactDetail {
86
+ CODIGO: string;
87
+ NOME: string;
88
+ CARGO: number | null;
89
+ EMAIL: string | null;
90
+ AREA_DIRETO: string | null;
91
+ AREA_CEL: string | null;
92
+ AREA_RESI: string | null;
93
+ FONE_DIRETO: string | null;
94
+ CELULAR: string | null;
95
+ FONE_RESIDENCIAL: string | null;
96
+ ANIVERSARIO: string | null;
97
+ TIME_FUTEBOL: string | null;
98
+ SEXO: "M" | "F" | null;
99
+ FILHOS: number;
100
+ CLIENTE: number | null;
101
+ TRATAMENTO: string | null;
102
+ }
103
+
104
+ export interface CustomerPurchaseItemDetail {
105
+ purchaseCode: number;
106
+ productCode: string | null;
107
+ description: string | null;
108
+ quantity: number | null;
109
+ unit: string | null;
110
+ unitValue: number | null;
111
+ discount: number | null;
112
+ }
113
+
114
+ export interface CustomerPurchaseDetail {
115
+ CODIGO: number;
116
+ CLIENTE: number;
117
+ DATA: string;
118
+ VALOR: number;
119
+ DESCRICAO: string | null;
120
+ FORMA_PGTO: string | null;
121
+ OPERADOR: number | null;
122
+ FATURADO: "S" | "N" | null;
123
+ TIPO: string | null;
124
+ SITUACAO: "F" | "C" | null;
125
+ CLIENTEATIVO: number | null;
126
+ items: CustomerPurchaseItemDetail[];
127
+ }
128
+
129
+ export interface CustomerScheduleDetail {
130
+ CODIGO: number;
131
+ CLIENTE: number;
132
+ CAMPANHA: number;
133
+ DT_RESULTADO: string;
134
+ DT_AGENDAMENTO: string;
135
+ RESULTADO: number;
136
+ CONCLUIDO: "SIM" | "NAO" | null;
137
+ FONE1: string;
138
+ FONE2: string;
139
+ FONE3: string;
140
+ ORDEM: number;
141
+ OPERADOR: number;
142
+ OPERADOR_LIGACAO: number;
143
+ DATA_HORA_LIG: string;
144
+ DATA_HORA_FIM: string;
145
+ TELEFONE_LIGADO: string;
146
+ AGENDA: number;
147
+ DESC_FONE1: string | null;
148
+ DESC_FONE2: string | null;
149
+ DESC_FONE3: string | null;
150
+ FIDELIZA: "S" | "N" | null;
151
+ MANUAL: "S" | "N" | null;
152
+ }
153
+
154
+ export interface CustomerTelephonySchedule extends CustomerScheduleDetail {
155
+ CAMPANHA_NOME: string | null;
156
+ OPERADOR_NOME: string | null;
157
+ OPERADOR_LIGACAO_NOME: string | null;
158
+ CLIENTE_RAZAO: string | null;
159
+ CLIENTE_FANTASIA: string | null;
160
+ }
161
+
162
+ export interface FinishTelephonyScheduleDTO {
163
+ resultId: number;
164
+ scheduleDate?: string;
165
+ startedAt?: string;
166
+ finishedAt?: string;
167
+ dialedPhone?: string;
168
+ }
169
+
170
+ export interface CustomerCallHistoryDetail {
171
+ CODIGO: number;
172
+ OPERADOR: number;
173
+ CLIENTE: number;
174
+ RESULTADO: number;
175
+ EXCEDEU: "SIM" | "NAO" | null;
176
+ TEMPO_EXCEDIDO: string;
177
+ FONE_RECEPTIVO: string;
178
+ LIGACAO_RECEBIDA: string;
179
+ LIGACAO_FINALIZADA: string;
180
+ TIPO_ACAO: string;
181
+ OBS: string | null;
182
+ }
183
+
184
+ export interface CustomerFullDetail {
185
+ customer: Customer;
186
+ campaign: {
187
+ fullName: string | null;
188
+ firstName: string | null;
189
+ };
190
+ wallet: {
191
+ fullName: string | null;
192
+ firstName: string | null;
193
+ };
194
+ address: {
195
+ END_RUA: string | null;
196
+ CIDADE: string | null;
197
+ BAIRRO: string | null;
198
+ ESTADO: string | null;
199
+ CEP: string | null;
200
+ COMPLEMENTO: string | null;
201
+ };
202
+ origin: {
203
+ group: { code: number | null; description: string | null };
204
+ origin: { code: number | null; description: string | null };
205
+ media: { code: number | null; name: string | null };
206
+ operator: { code: number | null; name: string | null };
207
+ segment: { code: number | null; name: string | null };
208
+ emails: {
209
+ EMAIL: string | null;
210
+ EMAIL2: string | null;
211
+ CONTATO_MAIL: string | null;
212
+ };
213
+ WEBSITE: string | null;
214
+ NR_FUNCIONARIOS: number | null;
215
+ customName: string | null;
216
+ };
217
+ contacts: CustomerContactDetail[];
218
+ observations: {
219
+ OBS_ADMIN: string | null;
220
+ OBS_OPERADOR: string | null;
221
+ };
222
+ callHistory: CustomerCallHistoryDetail[];
223
+ phones: {
224
+ AREA1: number | null;
225
+ FONE1: string | null;
226
+ DESC_FONE1: string | null;
227
+ AREA2: number | null;
228
+ FONE2: string | null;
229
+ DESC_FONE2: string | null;
230
+ AREA3: number | null;
231
+ FONE3: string | null;
232
+ DESC_FONE3: string | null;
233
+ AREAFAX: number | null;
234
+ FAX: string | null;
235
+ DESCFAX: string | null;
236
+ campaignPhones: Array<{
237
+ area: number | null;
238
+ phone: string | null;
239
+ description: string | null;
240
+ }>;
241
+ };
242
+ purchases: CustomerPurchaseDetail[];
243
+ schedules: CustomerScheduleDetail[];
244
+ metadata: {
245
+ editableTabs: {
246
+ main: boolean;
247
+ address: boolean;
248
+ contacts: boolean;
249
+ observations: boolean;
250
+ phones: boolean;
251
+ };
252
+ purchaseItems: {
253
+ mapped: boolean;
254
+ tableName: string | null;
255
+ };
256
+ customNameFieldMapped: boolean;
257
+ };
258
+ }
@@ -1,3 +1,4 @@
1
+ export * from "./ai.types";
1
2
  export * from "./auth.types";
2
3
  export * from "./customers.types";
3
4
  export * from "./files.types";
@@ -21,6 +21,15 @@ export interface PaginatedResponse<T> {
21
21
  };
22
22
  }
23
23
 
24
+ export interface FlexiblePaginatedResponse<T> {
25
+ message: string;
26
+ data: Array<T>;
27
+ page: {
28
+ current: number;
29
+ totalRows: number;
30
+ };
31
+ }
32
+
24
33
  export interface QueryResponse<T> {
25
34
  result: T;
26
35
  }
@@ -4,6 +4,7 @@ import {
4
4
  SocketServerInternalChatRoom,
5
5
  SocketServerReportsRoom,
6
6
  SocketServerRoom,
7
+ SocketServerUserRoom,
7
8
  } from "./socket-rooms.types";
8
9
  import { MessageResponse } from "./response.types";
9
10
  import { WppMessage, WppMessageStatus } from "./whatsapp.types";
@@ -32,6 +33,7 @@ export enum SocketEventType {
32
33
  InternalMessageEdit = "internal_message_edit",
33
34
  InternalMessageDelete = "internal_message_delete",
34
35
  InternalMessageStatus = "internal_message_status",
36
+ TelephonyCallReceived = "telephony_call_received",
35
37
  }
36
38
 
37
39
  export interface EmitSocketEventFn {
@@ -125,6 +127,11 @@ export interface EmitSocketEventFn {
125
127
  room: SocketServerRoom,
126
128
  data: InternalChatFinishedEventData,
127
129
  ): Promise<MessageResponse>;
130
+ (
131
+ type: SocketEventType.TelephonyCallReceived,
132
+ room: SocketServerUserRoom,
133
+ data: TelephonyCallReceivedEventData,
134
+ ): Promise<MessageResponse>;
128
135
  }
129
136
 
130
137
  export interface ListenSocketEventFn {
@@ -200,6 +207,10 @@ export interface ListenSocketEventFn {
200
207
  type: SocketEventType.WppMessageDelete,
201
208
  callback: (data: WppMessageDeleteEventData) => void,
202
209
  ): void;
210
+ (
211
+ type: SocketEventType.TelephonyCallReceived,
212
+ callback: (data: TelephonyCallReceivedEventData) => void,
213
+ ): void;
203
214
  }
204
215
 
205
216
  export interface UnlistenSocketEventFn {
@@ -306,3 +317,14 @@ export type ReportStatusEventData = {
306
317
  progress: number;
307
318
  }
308
319
  );
320
+
321
+ export interface TelephonyCallReceivedEventData {
322
+ uniqueid: string;
323
+ callerNumber: string;
324
+ callerName: string | null;
325
+ ramal: string;
326
+ operatorId: number | null;
327
+ instance: string;
328
+ receivedAt: string;
329
+ receptiveCallId: number | null;
330
+ }