@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.
@@ -0,0 +1,285 @@
1
+ import ApiClient from "./api-client";
2
+ import type { DataResponse, FlexiblePaginatedResponse, PaginatedResponse } from "./types/response.types";
3
+ import type {
4
+ AiAgentConfig,
5
+ AiTenantConfig,
6
+ AnalyzeCustomerRequest,
7
+ AnalyzeCustomerResponse,
8
+ CreateSupervisorAiSessionRequest,
9
+ SuggestResponseRequest,
10
+ SuggestResponseResponse,
11
+ SupervisorAiSession,
12
+ SupervisorAiSessionDetail,
13
+ SummarizeChatRequest,
14
+ SummarizeChatResponse,
15
+ AiAgent,
16
+ AiAgentChatSession,
17
+ AiAgentActionLog,
18
+ CreateAiAgentInput,
19
+ UpdateAiAgentInput,
20
+ AiAgentAudienceInput,
21
+ AiAgentKnowledgeEntryInput,
22
+ AiAgentActionLogFilters,
23
+ PaginatedActionLogs,
24
+ AiAgentAudiencePreview,
25
+ SendSupervisorAiMessageRequest,
26
+ SendSupervisorAiMessageResponse,
27
+ AiUsageSummary,
28
+ } from "./types/ai.types";
29
+ import type { WppContactWithCustomer } from "./types/whatsapp.types";
30
+
31
+ export default class AiClient extends ApiClient {
32
+ private authHeader(token: string) {
33
+ return { Authorization: `Bearer ${token}` };
34
+ }
35
+
36
+ async suggestResponse(data: SuggestResponseRequest, token: string): Promise<SuggestResponseResponse> {
37
+ const { data: res } = await this.ax.post<DataResponse<SuggestResponseResponse>>(
38
+ "/api/ai/completions/suggest-response",
39
+ data,
40
+ { headers: this.authHeader(token) },
41
+ );
42
+ return res.data;
43
+ }
44
+
45
+ async summarizeChat(data: SummarizeChatRequest, token: string): Promise<SummarizeChatResponse> {
46
+ const { data: res } = await this.ax.post<DataResponse<SummarizeChatResponse>>(
47
+ "/api/ai/completions/summarize-chat",
48
+ data,
49
+ { headers: this.authHeader(token) },
50
+ );
51
+ return res.data;
52
+ }
53
+
54
+ async analyzeCustomer(data: AnalyzeCustomerRequest, token: string): Promise<AnalyzeCustomerResponse> {
55
+ const { data: res } = await this.ax.post<DataResponse<AnalyzeCustomerResponse>>(
56
+ "/api/ai/completions/analyze-customer",
57
+ data,
58
+ { headers: this.authHeader(token) },
59
+ );
60
+ return res.data;
61
+ }
62
+
63
+ async listSupervisorSessions(token: string, status?: "ACTIVE" | "ARCHIVED"): Promise<SupervisorAiSession[]> {
64
+ const query = status ? `?status=${status}` : "";
65
+ const { data: res } = await this.ax.get<DataResponse<SupervisorAiSession[]>>(
66
+ `/api/ai/supervisor-chat/sessions${query}`,
67
+ { headers: this.authHeader(token) },
68
+ );
69
+ return res.data;
70
+ }
71
+
72
+ async createSupervisorSession(
73
+ data: CreateSupervisorAiSessionRequest | undefined,
74
+ token: string,
75
+ ): Promise<SupervisorAiSession> {
76
+ const { data: res } = await this.ax.post<DataResponse<SupervisorAiSession>>(
77
+ "/api/ai/supervisor-chat/sessions",
78
+ data,
79
+ { headers: this.authHeader(token) },
80
+ );
81
+ return res.data;
82
+ }
83
+
84
+ async patchSupervisorSessionStatus(
85
+ sessionId: number,
86
+ status: "ACTIVE" | "ARCHIVED",
87
+ token: string,
88
+ ): Promise<SupervisorAiSession> {
89
+ const { data: res } = await this.ax.patch<DataResponse<SupervisorAiSession>>(
90
+ `/api/ai/supervisor-chat/sessions/${sessionId}`,
91
+ { status },
92
+ { headers: this.authHeader(token) },
93
+ );
94
+ return res.data;
95
+ }
96
+
97
+ async getSupervisorSession(sessionId: number, token: string): Promise<SupervisorAiSessionDetail> {
98
+ const { data: res } = await this.ax.get<DataResponse<SupervisorAiSessionDetail>>(
99
+ `/api/ai/supervisor-chat/sessions/${sessionId}`,
100
+ { headers: this.authHeader(token) },
101
+ );
102
+ return res.data;
103
+ }
104
+
105
+ async sendSupervisorMessage(
106
+ sessionId: number,
107
+ data: SendSupervisorAiMessageRequest,
108
+ token: string,
109
+ ): Promise<SendSupervisorAiMessageResponse> {
110
+ const { data: res } = await this.ax.post<DataResponse<SendSupervisorAiMessageResponse>>(
111
+ `/api/ai/supervisor-chat/sessions/${sessionId}/messages`,
112
+ data,
113
+ { headers: this.authHeader(token) },
114
+ );
115
+ return res.data;
116
+ }
117
+
118
+ async getTenantConfig(instance: string, token: string): Promise<AiTenantConfig> {
119
+ const { data: res } = await this.ax.get<DataResponse<AiTenantConfig>>(
120
+ `/api/ai/tenant-config/${instance}`,
121
+ { headers: this.authHeader(token) },
122
+ );
123
+ return res.data;
124
+ }
125
+
126
+ async upsertTenantConfig(
127
+ instance: string,
128
+ data: Partial<AiTenantConfig>,
129
+ token: string,
130
+ ): Promise<AiTenantConfig> {
131
+ const { data: res } = await this.ax.put<DataResponse<AiTenantConfig>>(
132
+ `/api/ai/tenant-config/${instance}`,
133
+ data,
134
+ { headers: this.authHeader(token) },
135
+ );
136
+ return res.data;
137
+ }
138
+
139
+ async getAgentConfig(instance: string, token: string): Promise<AiAgentConfig | null> {
140
+ const { data: res } = await this.ax.get<DataResponse<AiAgentConfig | null>>(
141
+ `/api/ai/agent-config/${instance}`,
142
+ { headers: this.authHeader(token) },
143
+ );
144
+ return res.data;
145
+ }
146
+
147
+ async upsertAgentConfig(
148
+ instance: string,
149
+ data: Partial<AiAgentConfig>,
150
+ token: string,
151
+ ): Promise<AiAgentConfig> {
152
+ const { data: res } = await this.ax.put<DataResponse<AiAgentConfig>>(
153
+ `/api/ai/agent-config/${instance}`,
154
+ data,
155
+ { headers: this.authHeader(token) },
156
+ );
157
+ return res.data;
158
+ }
159
+
160
+ // ─── AI Agents CRUD ───────────────────────────────────────────────────────
161
+
162
+ async listAgents(token: string): Promise<AiAgent[]> {
163
+ const { data: res } = await this.ax.get<DataResponse<AiAgent[]>>(
164
+ "/api/ai/agents",
165
+ { headers: this.authHeader(token) },
166
+ );
167
+ return res.data;
168
+ }
169
+
170
+ async getAgent(agentId: number, token: string): Promise<AiAgent> {
171
+ const { data: res } = await this.ax.get<DataResponse<AiAgent>>(
172
+ `/api/ai/agents/${agentId}`,
173
+ { headers: this.authHeader(token) },
174
+ );
175
+ return res.data;
176
+ }
177
+
178
+ async createAgent(data: CreateAiAgentInput, token: string): Promise<AiAgent> {
179
+ const { data: res } = await this.ax.post<DataResponse<AiAgent>>(
180
+ "/api/ai/agents",
181
+ data,
182
+ { headers: this.authHeader(token) },
183
+ );
184
+ return res.data;
185
+ }
186
+
187
+ async updateAgent(agentId: number, data: UpdateAiAgentInput, token: string): Promise<AiAgent> {
188
+ const { data: res } = await this.ax.patch<DataResponse<AiAgent>>(
189
+ `/api/ai/agents/${agentId}`,
190
+ data,
191
+ { headers: this.authHeader(token) },
192
+ );
193
+ return res.data;
194
+ }
195
+
196
+ async deleteAgent(agentId: number, token: string): Promise<void> {
197
+ await this.ax.delete(`/api/ai/agents/${agentId}`, { headers: this.authHeader(token) });
198
+ }
199
+
200
+ async upsertAgentAudience(agentId: number, data: AiAgentAudienceInput, token: string): Promise<AiAgent> {
201
+ const { data: res } = await this.ax.put<DataResponse<AiAgent>>(
202
+ `/api/ai/agents/${agentId}/audience`,
203
+ data,
204
+ { headers: this.authHeader(token) },
205
+ );
206
+ return res.data;
207
+ }
208
+
209
+ async previewAgentAudience(
210
+ agentId: number,
211
+ filters: { page?: number; perPage?: number } | undefined,
212
+ token: string,
213
+ ): Promise<AiAgentAudiencePreview> {
214
+ const { data: res } = await this.ax.post<FlexiblePaginatedResponse<WppContactWithCustomer>>(
215
+ `/api/ai/agents/${agentId}/audience/preview`,
216
+ undefined,
217
+ {
218
+ params: filters,
219
+ headers: this.authHeader(token),
220
+ },
221
+ );
222
+
223
+ return { data: res.data, page: res.page };
224
+ }
225
+
226
+ async addAgentKnowledgeEntry(
227
+ agentId: number,
228
+ data: AiAgentKnowledgeEntryInput,
229
+ token: string,
230
+ ): Promise<AiAgent> {
231
+ const { data: res } = await this.ax.post<DataResponse<AiAgent>>(
232
+ `/api/ai/agents/${agentId}/knowledge`,
233
+ data,
234
+ { headers: this.authHeader(token) },
235
+ );
236
+ return res.data;
237
+ }
238
+
239
+ async updateAgentKnowledgeEntry(
240
+ agentId: number,
241
+ entryId: number,
242
+ data: Partial<AiAgentKnowledgeEntryInput>,
243
+ token: string,
244
+ ): Promise<AiAgent> {
245
+ const { data: res } = await this.ax.patch<DataResponse<AiAgent>>(
246
+ `/api/ai/agents/${agentId}/knowledge/${entryId}`,
247
+ data,
248
+ { headers: this.authHeader(token) },
249
+ );
250
+ return res.data;
251
+ }
252
+
253
+ async deleteAgentKnowledgeEntry(agentId: number, entryId: number, token: string): Promise<void> {
254
+ await this.ax.delete(`/api/ai/agents/${agentId}/knowledge/${entryId}`, {
255
+ headers: this.authHeader(token),
256
+ });
257
+ }
258
+
259
+ async listAgentActionLogs(filters: AiAgentActionLogFilters, token: string): Promise<PaginatedActionLogs> {
260
+ const { data: res } = await this.ax.get<DataResponse<PaginatedActionLogs>>(
261
+ "/api/ai/agents/logs",
262
+ {
263
+ params: filters,
264
+ headers: this.authHeader(token),
265
+ },
266
+ );
267
+ return res.data;
268
+ }
269
+
270
+ async listActiveSessions(token: string): Promise<AiAgentChatSession[]> {
271
+ const { data: res } = await this.ax.get<DataResponse<AiAgentChatSession[]>>(
272
+ "/api/ai/agents/sessions/active",
273
+ { headers: this.authHeader(token) },
274
+ );
275
+ return res.data;
276
+ }
277
+
278
+ async getUsageSummary(period: string, token: string): Promise<AiUsageSummary> {
279
+ const { data: res } = await this.ax.get<DataResponse<AiUsageSummary>>(
280
+ `/api/ai/usage?period=${encodeURIComponent(period)}`,
281
+ { headers: this.authHeader(token) },
282
+ );
283
+ return res.data;
284
+ }
285
+ }
@@ -1,8 +1,12 @@
1
1
  import ApiClient from "./api-client";
2
- import { PaginatedResponse, RequestFilters } from "./types";
2
+ import { DataResponse, MessageResponse, PaginatedResponse, RequestFilters } from "./types";
3
3
  import {
4
4
  CreateCustomerDTO,
5
5
  Customer,
6
+ CustomerFullDetail,
7
+ CustomerLookupOption,
8
+ FinishTelephonyScheduleDTO,
9
+ CustomerTelephonySchedule,
6
10
  UpdateCustomerDTO,
7
11
  } from "./types/customers.types";
8
12
 
@@ -30,6 +34,19 @@ class CustomersClient extends ApiClient {
30
34
  return response.data;
31
35
  }
32
36
 
37
+ /**
38
+ * Obtém os detalhes completos do cliente para o modal CRM.
39
+ * @param customerId - O ID do cliente a ser obtido.
40
+ * @returns Uma Promise que resolve para os detalhes agregados do cliente.
41
+ */
42
+ public async getCustomerFullDetail(customerId: number) {
43
+ const response = await this.ax.get<{ message: string; data: CustomerFullDetail }>(
44
+ `/api/customers/${customerId}/full`,
45
+ );
46
+
47
+ return response.data;
48
+ }
49
+
33
50
  /**
34
51
  * Atualiza um cliente existente.
35
52
  * @param customerId - O ID do cliente a ser atualizado.
@@ -65,6 +82,58 @@ class CustomersClient extends ApiClient {
65
82
  return response.data;
66
83
  }
67
84
 
85
+ public async getCampaigns() {
86
+ const response = await this.ax.get<DataResponse<CustomerLookupOption[]>>(
87
+ `/api/customers/campaigns`,
88
+ );
89
+
90
+ return response.data.data;
91
+ }
92
+
93
+ public async getSegments() {
94
+ const response = await this.ax.get<DataResponse<CustomerLookupOption[]>>(
95
+ `/api/customers/segments`,
96
+ );
97
+
98
+ return response.data.data;
99
+ }
100
+
101
+ public async getOperators() {
102
+ const response = await this.ax.get<DataResponse<CustomerLookupOption[]>>(
103
+ `/api/customers/operators`,
104
+ );
105
+
106
+ return response.data.data;
107
+ }
108
+
109
+ public async getTelephonySchedules(
110
+ filters?: RequestFilters<CustomerTelephonySchedule>,
111
+ ) {
112
+ let baseUrl = `/api/customers/schedules/telephony`;
113
+
114
+ if (filters) {
115
+ const params = new URLSearchParams(filters);
116
+ baseUrl += `?${params.toString()}`;
117
+ }
118
+
119
+ const response =
120
+ await this.ax.get<PaginatedResponse<CustomerTelephonySchedule>>(baseUrl);
121
+
122
+ return response.data;
123
+ }
124
+
125
+ public async finishTelephonySchedule(
126
+ scheduleId: number,
127
+ data: FinishTelephonyScheduleDTO,
128
+ ) {
129
+ const response = await this.ax.patch<MessageResponse>(
130
+ `/api/customers/schedules/telephony/${scheduleId}/finish`,
131
+ data,
132
+ );
133
+
134
+ return response.data;
135
+ }
136
+
68
137
  /**
69
138
  * Define o token de autenticação para as requisições.
70
139
  * @param token - O token de autenticação a ser definido.
package/src/index.ts CHANGED
@@ -1,4 +1,5 @@
1
1
  export * from "./types";
2
+ export { default as AiClient } from "./ai.client";
2
3
  export { default as AuthClient } from "./auth.client";
3
4
  export { default as CustomersClient } from "./customers.client";
4
5
  export { default as FilesClient } from "./files.client";