@in.pulse-crm/sdk 2.14.7 → 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.
@@ -46,6 +46,143 @@ export interface PaginatedContactsResponse {
46
46
  };
47
47
  }
48
48
 
49
+ export type CustomerInteractionLevel =
50
+ | "sem_interacao"
51
+ | "pouca_interacao"
52
+ | "interacao_media"
53
+ | "interacao_alta";
54
+
55
+ export type CustomerPurchaseLevel =
56
+ | "sem_compras"
57
+ | "poucas_compras"
58
+ | "compras_medias"
59
+ | "muitas_compras";
60
+
61
+ export type CustomerAgeLevel =
62
+ | "sem_data_cadastro"
63
+ | "cliente_novo"
64
+ | "ate_6_meses"
65
+ | "ate_12_meses"
66
+ | "mais_de_12_meses";
67
+
68
+ export type CustomerPurchaseInterestLevel =
69
+ | "nao_analisado"
70
+ | "baixo_interesse"
71
+ | "interesse_moderado"
72
+ | "alto_interesse"
73
+ | "pronto_para_compra";
74
+
75
+ export interface CustomerProfileManualOverrides {
76
+ profileLevel: CustomerProfileSummaryLevel | null;
77
+ purchaseInterestLevel: CustomerPurchaseInterestLevel | null;
78
+ updatedAt: string;
79
+ updatedByUserId: number;
80
+ updatedByName: string;
81
+ }
82
+
83
+ export interface UpdateCustomerProfileManualOverridesInput {
84
+ profileLevel?: CustomerProfileSummaryLevel | null;
85
+ purchaseInterestLevel?: CustomerPurchaseInterestLevel | null;
86
+ }
87
+
88
+ export interface CustomerPurchaseInterestPayload {
89
+ level: CustomerPurchaseInterestLevel;
90
+ label: string;
91
+ color: string;
92
+ reasons: string[];
93
+ source: "placeholder_rules" | "manual_override";
94
+ }
95
+
96
+ export type CustomerProfileSummaryLevel =
97
+ | "potencial_de_compra"
98
+ | "consolidado"
99
+ | "precisa_mais_interacao"
100
+ | "em_observacao";
101
+
102
+ export interface CustomerInteractionTagMetrics {
103
+ windowDays: number;
104
+ contactCount: number;
105
+ chatCount90d: number;
106
+ messageCount90d: number;
107
+ recentActiveDays90d: number;
108
+ lastInteractionAt: string | null;
109
+ allTimeMessageCount: number;
110
+ allTimeChatCount: number;
111
+ activeContactCount: number;
112
+ reasons: string[];
113
+ }
114
+
115
+ export interface CustomerPurchaseTagMetrics {
116
+ windowMonths: number;
117
+ allTimePurchaseCount: number;
118
+ purchaseCount12m: number;
119
+ totalPurchaseValue12m: number;
120
+ lastPurchaseAt: string | null;
121
+ daysSinceLastPurchase: number | null;
122
+ reasons: string[];
123
+ }
124
+
125
+ export interface CustomerAgeTagMetrics {
126
+ newCustomerWindowDays: number;
127
+ registeredAt: string | null;
128
+ customerAgeDays: number | null;
129
+ customerAgeMonths: number | null;
130
+ reasons: string[];
131
+ }
132
+
133
+ export type CustomerProfileTagMetadata =
134
+ | CustomerInteractionTagMetrics
135
+ | CustomerPurchaseTagMetrics
136
+ | CustomerAgeTagMetrics;
137
+
138
+ export interface CustomerProfileTagPayload<TMetadata = CustomerProfileTagMetadata> {
139
+ id: number;
140
+ instance: string;
141
+ customerId: number;
142
+ tagType: string;
143
+ tagValue: string;
144
+ label: string;
145
+ color: string;
146
+ calculatedAt: string;
147
+ metadata: TMetadata | null;
148
+ }
149
+
150
+ export interface CustomerProfileSummaryPayload {
151
+ instance: string;
152
+ customerId: number;
153
+ profileLevel: CustomerProfileSummaryLevel;
154
+ label: string;
155
+ color: string;
156
+ profileSource: "automatic" | "manual_override";
157
+ reasons: string[];
158
+ purchaseInterest: CustomerPurchaseInterestPayload;
159
+ manualOverrides: CustomerProfileManualOverrides | null;
160
+ tags: {
161
+ interaction: CustomerProfileTagPayload<CustomerInteractionTagMetrics>;
162
+ purchase: CustomerProfileTagPayload<CustomerPurchaseTagMetrics>;
163
+ age: CustomerProfileTagPayload<CustomerAgeTagMetrics>;
164
+ };
165
+ }
166
+
167
+ export interface CustomerProfileSummaryFilters {
168
+ profileLevel?: CustomerProfileSummaryLevel;
169
+ interactionLevel?: CustomerInteractionLevel;
170
+ purchaseLevel?: CustomerPurchaseLevel;
171
+ ageLevel?: CustomerAgeLevel;
172
+ purchaseInterestLevel?: CustomerPurchaseInterestLevel;
173
+ state?: string;
174
+ city?: string;
175
+ activeCustomer?: "SIM" | "NAO";
176
+ searchTerm?: string;
177
+ segmentIds?: number[];
178
+ campaignIds?: number[];
179
+ operatorIds?: number[];
180
+ }
181
+
182
+ export interface CustomerProfileSummaryBatchRequest {
183
+ customerIds: number[];
184
+ }
185
+
49
186
  export interface WppMessage {
50
187
  id: number;
51
188
  instance: string;
@@ -71,6 +208,7 @@ export interface WppMessage {
71
208
  wwebjsIdStanza: string | null;
72
209
  sentAt: Date;
73
210
  userId: number | null;
211
+ agentId: number | null;
74
212
  billingCategory: string | null;
75
213
  clientId: number | null;
76
214
  }
@@ -89,6 +227,7 @@ export interface WppChat {
89
227
  userName?: string;
90
228
  walletId?: number;
91
229
  botId?: number;
230
+ agentId?: number | null;
92
231
  resultId?: number;
93
232
  sectorId?: number;
94
233
  type: WppChatType;
@@ -191,6 +330,86 @@ export interface CreateScheduleDTO {
191
330
  sectorId: number;
192
331
  }
193
332
 
333
+ export type UnifiedScheduleChannel = "WHATSAPP" | "TELEFONIA";
334
+
335
+ export type UnifiedScheduleRepurchaseStatus = "green" | "yellow" | "red" | "neutral";
336
+
337
+ export interface UnifiedScheduleRepurchaseMetrics {
338
+ averageRepurchaseDays: number | null;
339
+ daysSinceLastPurchase: number | null;
340
+ nextRepurchaseDate: string | null;
341
+ proximityRatio: number | null;
342
+ semaphoreStatus: UnifiedScheduleRepurchaseStatus;
343
+ overdueDays: number | null;
344
+ }
345
+
346
+ export interface UnifiedScheduleCampaignFilterOption {
347
+ id: string;
348
+ label: string;
349
+ }
350
+
351
+ export interface UnifiedScheduleFilterMetadata {
352
+ customerCampaigns: UnifiedScheduleCampaignFilterOption[];
353
+ }
354
+
355
+ export interface UnifiedSchedulePagination {
356
+ current: number;
357
+ perPage: number;
358
+ totalRows: number;
359
+ totalPages: number;
360
+ hasNext: boolean;
361
+ hasPrev: boolean;
362
+ }
363
+
364
+ export interface UnifiedScheduleFilters extends CustomerProfileSummaryFilters {
365
+ page?: string;
366
+ perPage?: string;
367
+ channels?: string;
368
+ customerCampaignIds?: string;
369
+ repurchaseStatuses?: string;
370
+ userId?: string;
371
+ sectorId?: string;
372
+ }
373
+
374
+ export interface UnifiedSchedule {
375
+ id: string;
376
+ channel: UnifiedScheduleChannel;
377
+ scheduleId: number;
378
+ scheduleAt: string;
379
+ scheduledBy: number | null;
380
+ scheduledFor: number | null;
381
+ description: string | null;
382
+ contactName: string | null;
383
+ contactPhone: string | null;
384
+ customerId: number | null;
385
+ customerName: string | null;
386
+ customerFantasyName: string | null;
387
+ customerCampaignId: number | null;
388
+ customerCampaignName: string | null;
389
+ customerOriginId: number | null;
390
+ customerOriginDescription: string | null;
391
+ telephonyCampaignId: number | null;
392
+ telephonyCampaignName: string | null;
393
+ profileSummary: CustomerProfileSummaryPayload | null;
394
+ repurchase: UnifiedScheduleRepurchaseMetrics | null;
395
+ meta: {
396
+ wppContactId?: number;
397
+ wppChatId?: number | null;
398
+ telephonyRecordId?: number;
399
+ };
400
+ }
401
+
402
+ export interface UnifiedSchedulesResponse {
403
+ message: string;
404
+ data: UnifiedSchedule[];
405
+ page: {
406
+ current: number;
407
+ totalRows: number;
408
+ };
409
+ pagination: UnifiedSchedulePagination;
410
+ filters: UnifiedScheduleFilterMetadata;
411
+ }
412
+
194
413
  export interface WppSchedule {
195
414
  id: number;
196
415
  instance: string;
@@ -6,17 +6,25 @@ import {
6
6
  AppNotification,
7
7
  AutomaticResponseRule,
8
8
  AutomaticResponseRuleDTO,
9
+ CustomerProfileManualOverrides,
10
+ CustomerProfileSummaryBatchRequest,
11
+ CustomerProfileSummaryFilters,
12
+ CustomerProfileSummaryPayload,
9
13
  CreateScheduleDTO,
10
14
  ForwardMessagesData,
11
15
  PaginatedContactsResponse,
12
16
  PaginatedNotificationsResponse,
13
17
  SendFileMessageData,
14
18
  SendMessageData,
19
+ UnifiedSchedule,
20
+ UnifiedScheduleFilters,
21
+ UnifiedSchedulesResponse,
15
22
  WppChatsAndMessages,
16
23
  WppChatWithDetailsAndMessages,
17
24
  WppContact,
18
25
  WppMessage,
19
26
  WppSchedule,
27
+ UpdateCustomerProfileManualOverridesInput,
20
28
  WppWallet,
21
29
  } from "./types/whatsapp.types";
22
30
 
@@ -155,6 +163,57 @@ export default class WhatsappClient extends ApiClient {
155
163
  return res.data;
156
164
  }
157
165
 
166
+ public async getCustomerProfileSummary(customerId: number) {
167
+ const { data: res } = await this.ax.get<DataResponse<CustomerProfileSummaryPayload>>(
168
+ `/api/whatsapp/customers/${customerId}/profile-tags/summary`,
169
+ );
170
+ return res.data;
171
+ }
172
+
173
+ public async getCustomerProfileManualOverrides(customerId: number) {
174
+ const { data: res } = await this.ax.get<DataResponse<CustomerProfileManualOverrides | null>>(
175
+ `/api/whatsapp/customers/${customerId}/profile-tags/manual-overrides`,
176
+ );
177
+ return res.data;
178
+ }
179
+
180
+ public async updateCustomerProfileManualOverrides(
181
+ customerId: number,
182
+ data: UpdateCustomerProfileManualOverridesInput,
183
+ ) {
184
+ const { data: res } = await this.ax.put<DataResponse<CustomerProfileSummaryPayload>>(
185
+ `/api/whatsapp/customers/${customerId}/profile-tags/manual-overrides`,
186
+ data,
187
+ );
188
+ return res.data;
189
+ }
190
+
191
+ public async getCustomerProfileSummaries(data: CustomerProfileSummaryBatchRequest) {
192
+ const { data: res } = await this.ax.post<DataResponse<CustomerProfileSummaryPayload[]>>(
193
+ `/api/whatsapp/customers/profile-tags/summary/batch`,
194
+ data,
195
+ );
196
+ return res.data;
197
+ }
198
+
199
+ public async findCustomerIdsByProfileFilters(filters: CustomerProfileSummaryFilters) {
200
+ const params = new URLSearchParams();
201
+
202
+ if (filters.profileLevel) params.append("profileLevel", filters.profileLevel);
203
+ if (filters.interactionLevel) params.append("interactionLevel", filters.interactionLevel);
204
+ if (filters.purchaseLevel) params.append("purchaseLevel", filters.purchaseLevel);
205
+ if (filters.ageLevel) params.append("ageLevel", filters.ageLevel);
206
+ if (filters.purchaseInterestLevel) params.append("purchaseInterestLevel", filters.purchaseInterestLevel);
207
+
208
+ const queryString = params.toString();
209
+ const url = queryString
210
+ ? `/api/whatsapp/customers/profile-tags/customer-ids?${queryString}`
211
+ : `/api/whatsapp/customers/profile-tags/customer-ids`;
212
+
213
+ const { data: res } = await this.ax.get<DataResponse<number[]>>(url);
214
+ return res.data;
215
+ }
216
+
158
217
  public async getContactsWithCustomer(filters?: {
159
218
  name?: string;
160
219
  phone?: string;
@@ -353,6 +412,26 @@ export default class WhatsappClient extends ApiClient {
353
412
  return response.data;
354
413
  }
355
414
 
415
+ public async getUnifiedSchedules(filters?: UnifiedScheduleFilters) {
416
+ let baseUrl = `/api/whatsapp/schedules/unified`;
417
+ const params = new URLSearchParams(
418
+ Object.entries(filters ?? {}).reduce<Record<string, string>>((acc, [key, value]) => {
419
+ if (value !== undefined && value !== null) {
420
+ acc[key] = String(value);
421
+ }
422
+
423
+ return acc;
424
+ }, {}),
425
+ );
426
+
427
+ if (params.toString()) {
428
+ baseUrl += `?${params.toString()}`;
429
+ }
430
+
431
+ const response = await this.ax.get<UnifiedSchedulesResponse>(baseUrl);
432
+ return response.data;
433
+ }
434
+
356
435
  /**
357
436
  * Cria um novo agendamento.
358
437
  * @param scheduleData - Os dados do agendamento, keys de wppSchedule.