plazbot-cli 0.2.12 → 0.2.16
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.
|
@@ -25,12 +25,14 @@ const CHANNEL_CHOICES = [
|
|
|
25
25
|
{ name: 'WhatsApp Business', value: 'whatsapp_business' },
|
|
26
26
|
{ name: 'Instagram', value: 'instagram' },
|
|
27
27
|
{ name: 'Messenger', value: 'facebook' },
|
|
28
|
+
{ name: 'Telegram', value: 'telegram' },
|
|
28
29
|
];
|
|
29
30
|
const CHANNEL_AGENT_MAP = {
|
|
30
31
|
whatsapp: 'whatsapp',
|
|
31
32
|
whatsapp_business: 'whatsapp',
|
|
32
33
|
instagram: 'instagram',
|
|
33
|
-
facebook: '
|
|
34
|
+
facebook: 'messenger',
|
|
35
|
+
telegram: 'telegram',
|
|
34
36
|
};
|
|
35
37
|
function getIntegrationLabel(ig) {
|
|
36
38
|
if (ig.type === 'whatsapp') {
|
|
@@ -40,6 +42,9 @@ function getIntegrationLabel(ig) {
|
|
|
40
42
|
}
|
|
41
43
|
return ig.aliasName || ig.srcName || ig.id;
|
|
42
44
|
}
|
|
45
|
+
function getIntegrationKey(ig) {
|
|
46
|
+
return ig.aliasName || ig.srcName || ig.id;
|
|
47
|
+
}
|
|
43
48
|
async function fetchWorkspaceIntegrations(baseUrl, workspaceId, headers) {
|
|
44
49
|
try {
|
|
45
50
|
const wkRes = await axios_1.default.get(`${baseUrl}/api/workspace/${workspaceId}`, { headers });
|
|
@@ -50,6 +55,15 @@ async function fetchWorkspaceIntegrations(baseUrl, workspaceId, headers) {
|
|
|
50
55
|
return [];
|
|
51
56
|
}
|
|
52
57
|
}
|
|
58
|
+
async function activateIntegration(baseUrl, workspaceId, integrationId, headers) {
|
|
59
|
+
try {
|
|
60
|
+
const res = await axios_1.default.post(`${baseUrl}/api/workspace/${workspaceId}/integrations/${integrationId}/activate`, { isActive: true }, { headers });
|
|
61
|
+
return res.data?.success === true;
|
|
62
|
+
}
|
|
63
|
+
catch {
|
|
64
|
+
return false;
|
|
65
|
+
}
|
|
66
|
+
}
|
|
53
67
|
async function connectChannelFlow(ctx) {
|
|
54
68
|
const channels = [];
|
|
55
69
|
const baseUrl = getBaseUrl(ctx.zone, ctx.dev);
|
|
@@ -92,9 +106,20 @@ async function connectChannelFlow(ctx) {
|
|
|
92
106
|
// Selecciono una existente
|
|
93
107
|
selectedIntegration = existing.find((ig) => ig.id === selected);
|
|
94
108
|
const label = getIntegrationLabel(selectedIntegration);
|
|
109
|
+
// Activar la integracion si no esta activa
|
|
110
|
+
if (!selectedIntegration.isActive) {
|
|
111
|
+
const actSpinner = (0, ora_1.default)({ text: chalk_1.default.gray('Activando integracion...'), spinner: 'dots', color: 'green' }).start();
|
|
112
|
+
const activated = await activateIntegration(baseUrl, ctx.workspaceId, selectedIntegration.id, headers);
|
|
113
|
+
if (activated) {
|
|
114
|
+
actSpinner.succeed(chalk_1.default.hex('#4ade80')('Integracion activada correctamente.'));
|
|
115
|
+
}
|
|
116
|
+
else {
|
|
117
|
+
actSpinner.warn(chalk_1.default.hex('#FFA726')('No se pudo activar la integracion. Puedes activarla manualmente desde la plataforma.'));
|
|
118
|
+
}
|
|
119
|
+
}
|
|
95
120
|
channels.push({
|
|
96
121
|
channel: CHANNEL_AGENT_MAP[channelType],
|
|
97
|
-
key: selectedIntegration
|
|
122
|
+
key: getIntegrationKey(selectedIntegration),
|
|
98
123
|
multianswer: false,
|
|
99
124
|
});
|
|
100
125
|
console.log(chalk_1.default.hex('#4ade80')(` Canal asociado: ${label}`));
|
|
@@ -178,9 +203,18 @@ async function connectChannelFlow(ctx) {
|
|
|
178
203
|
if (detected) {
|
|
179
204
|
const detectedName = getIntegrationLabel(detected);
|
|
180
205
|
pollSpinner.succeed(chalk_1.default.hex('#4ade80')(`Conexion detectada: ${detectedName}`));
|
|
206
|
+
// Activar la integracion detectada
|
|
207
|
+
const actSpinner = (0, ora_1.default)({ text: chalk_1.default.gray('Activando integracion...'), spinner: 'dots', color: 'green' }).start();
|
|
208
|
+
const activated = await activateIntegration(baseUrl, ctx.workspaceId, detected.id, headers);
|
|
209
|
+
if (activated) {
|
|
210
|
+
actSpinner.succeed(chalk_1.default.hex('#4ade80')('Integracion activada correctamente.'));
|
|
211
|
+
}
|
|
212
|
+
else {
|
|
213
|
+
actSpinner.warn(chalk_1.default.hex('#FFA726')('No se pudo activar la integracion. Puedes activarla manualmente desde la plataforma.'));
|
|
214
|
+
}
|
|
181
215
|
channels.push({
|
|
182
216
|
channel: CHANNEL_AGENT_MAP[channelType],
|
|
183
|
-
key: detected
|
|
217
|
+
key: getIntegrationKey(detected),
|
|
184
218
|
multianswer: false,
|
|
185
219
|
});
|
|
186
220
|
console.log(chalk_1.default.hex('#4ade80')(' Canal asociado correctamente.'));
|
|
@@ -199,6 +233,15 @@ async function connectChannelFlow(ctx) {
|
|
|
199
233
|
const { key } = await inquirer_1.default.prompt([
|
|
200
234
|
{ type: 'input', name: 'key', message: `ID/numero del canal ${channelLabel}:`, validate: (v) => v.length > 0 || 'Requerido' },
|
|
201
235
|
]);
|
|
236
|
+
// Activar la integracion ingresada manualmente
|
|
237
|
+
const actSpinner = (0, ora_1.default)({ text: chalk_1.default.gray('Activando integracion...'), spinner: 'dots', color: 'green' }).start();
|
|
238
|
+
const activated = await activateIntegration(baseUrl, ctx.workspaceId, key, headers);
|
|
239
|
+
if (activated) {
|
|
240
|
+
actSpinner.succeed(chalk_1.default.hex('#4ade80')('Integracion activada correctamente.'));
|
|
241
|
+
}
|
|
242
|
+
else {
|
|
243
|
+
actSpinner.warn(chalk_1.default.hex('#FFA726')('No se pudo activar la integracion. Puedes activarla manualmente desde la plataforma.'));
|
|
244
|
+
}
|
|
202
245
|
channels.push({ channel: CHANNEL_AGENT_MAP[channelType], key, multianswer: false });
|
|
203
246
|
}
|
|
204
247
|
}
|
package/package.json
CHANGED
|
@@ -113,13 +113,15 @@ const CHANNEL_CHOICES = [
|
|
|
113
113
|
{ name: 'WhatsApp Business', value: 'whatsapp_business' },
|
|
114
114
|
{ name: 'Instagram', value: 'instagram' },
|
|
115
115
|
{ name: 'Messenger', value: 'facebook' },
|
|
116
|
+
{ name: 'Telegram', value: 'telegram' },
|
|
116
117
|
];
|
|
117
118
|
|
|
118
119
|
const CHANNEL_AGENT_MAP: Record<string, string> = {
|
|
119
120
|
whatsapp: 'whatsapp',
|
|
120
121
|
whatsapp_business: 'whatsapp',
|
|
121
122
|
instagram: 'instagram',
|
|
122
|
-
facebook: '
|
|
123
|
+
facebook: 'messenger',
|
|
124
|
+
telegram: 'telegram',
|
|
123
125
|
};
|
|
124
126
|
|
|
125
127
|
function getIntegrationLabel(ig: any): string {
|
|
@@ -131,6 +133,10 @@ function getIntegrationLabel(ig: any): string {
|
|
|
131
133
|
return ig.aliasName || ig.srcName || ig.id;
|
|
132
134
|
}
|
|
133
135
|
|
|
136
|
+
function getIntegrationKey(ig: any): string {
|
|
137
|
+
return ig.aliasName || ig.srcName || ig.id;
|
|
138
|
+
}
|
|
139
|
+
|
|
134
140
|
async function fetchWorkspaceIntegrations(baseUrl: string, workspaceId: string, headers: any): Promise<any[]> {
|
|
135
141
|
try {
|
|
136
142
|
const wkRes = await axios.get(`${baseUrl}/api/workspace/${workspaceId}`, { headers });
|
|
@@ -141,6 +147,19 @@ async function fetchWorkspaceIntegrations(baseUrl: string, workspaceId: string,
|
|
|
141
147
|
}
|
|
142
148
|
}
|
|
143
149
|
|
|
150
|
+
async function activateIntegration(baseUrl: string, workspaceId: string, integrationId: string, headers: any): Promise<boolean> {
|
|
151
|
+
try {
|
|
152
|
+
const res = await axios.post(
|
|
153
|
+
`${baseUrl}/api/workspace/${workspaceId}/integrations/${integrationId}/activate`,
|
|
154
|
+
{ isActive: true },
|
|
155
|
+
{ headers }
|
|
156
|
+
);
|
|
157
|
+
return res.data?.success === true;
|
|
158
|
+
} catch {
|
|
159
|
+
return false;
|
|
160
|
+
}
|
|
161
|
+
}
|
|
162
|
+
|
|
144
163
|
async function connectChannelFlow(ctx: WizardContext): Promise<AgentChannel[]> {
|
|
145
164
|
const channels: AgentChannel[] = [];
|
|
146
165
|
const baseUrl = getBaseUrl(ctx.zone, ctx.dev);
|
|
@@ -190,9 +209,21 @@ async function connectChannelFlow(ctx: WizardContext): Promise<AgentChannel[]> {
|
|
|
190
209
|
// Selecciono una existente
|
|
191
210
|
selectedIntegration = existing.find((ig: any) => ig.id === selected);
|
|
192
211
|
const label = getIntegrationLabel(selectedIntegration);
|
|
212
|
+
|
|
213
|
+
// Activar la integracion si no esta activa
|
|
214
|
+
if (!selectedIntegration.isActive) {
|
|
215
|
+
const actSpinner = ora({ text: chalk.gray('Activando integracion...'), spinner: 'dots', color: 'green' }).start();
|
|
216
|
+
const activated = await activateIntegration(baseUrl, ctx.workspaceId, selectedIntegration.id, headers);
|
|
217
|
+
if (activated) {
|
|
218
|
+
actSpinner.succeed(chalk.hex('#4ade80')('Integracion activada correctamente.'));
|
|
219
|
+
} else {
|
|
220
|
+
actSpinner.warn(chalk.hex('#FFA726')('No se pudo activar la integracion. Puedes activarla manualmente desde la plataforma.'));
|
|
221
|
+
}
|
|
222
|
+
}
|
|
223
|
+
|
|
193
224
|
channels.push({
|
|
194
225
|
channel: CHANNEL_AGENT_MAP[channelType],
|
|
195
|
-
key: selectedIntegration
|
|
226
|
+
key: getIntegrationKey(selectedIntegration),
|
|
196
227
|
multianswer: false,
|
|
197
228
|
});
|
|
198
229
|
console.log(chalk.hex('#4ade80')(` Canal asociado: ${label}`));
|
|
@@ -281,9 +312,19 @@ async function connectChannelFlow(ctx: WizardContext): Promise<AgentChannel[]> {
|
|
|
281
312
|
if (detected) {
|
|
282
313
|
const detectedName = getIntegrationLabel(detected);
|
|
283
314
|
pollSpinner.succeed(chalk.hex('#4ade80')(`Conexion detectada: ${detectedName}`));
|
|
315
|
+
|
|
316
|
+
// Activar la integracion detectada
|
|
317
|
+
const actSpinner = ora({ text: chalk.gray('Activando integracion...'), spinner: 'dots', color: 'green' }).start();
|
|
318
|
+
const activated = await activateIntegration(baseUrl, ctx.workspaceId, detected.id, headers);
|
|
319
|
+
if (activated) {
|
|
320
|
+
actSpinner.succeed(chalk.hex('#4ade80')('Integracion activada correctamente.'));
|
|
321
|
+
} else {
|
|
322
|
+
actSpinner.warn(chalk.hex('#FFA726')('No se pudo activar la integracion. Puedes activarla manualmente desde la plataforma.'));
|
|
323
|
+
}
|
|
324
|
+
|
|
284
325
|
channels.push({
|
|
285
326
|
channel: CHANNEL_AGENT_MAP[channelType],
|
|
286
|
-
key: detected
|
|
327
|
+
key: getIntegrationKey(detected),
|
|
287
328
|
multianswer: false,
|
|
288
329
|
});
|
|
289
330
|
console.log(chalk.hex('#4ade80')(' Canal asociado correctamente.'));
|
|
@@ -301,6 +342,16 @@ async function connectChannelFlow(ctx: WizardContext): Promise<AgentChannel[]> {
|
|
|
301
342
|
const { key } = await (inquirer as any).prompt([
|
|
302
343
|
{ type: 'input', name: 'key', message: `ID/numero del canal ${channelLabel}:`, validate: (v: string) => v.length > 0 || 'Requerido' },
|
|
303
344
|
]);
|
|
345
|
+
|
|
346
|
+
// Activar la integracion ingresada manualmente
|
|
347
|
+
const actSpinner = ora({ text: chalk.gray('Activando integracion...'), spinner: 'dots', color: 'green' }).start();
|
|
348
|
+
const activated = await activateIntegration(baseUrl, ctx.workspaceId, key, headers);
|
|
349
|
+
if (activated) {
|
|
350
|
+
actSpinner.succeed(chalk.hex('#4ade80')('Integracion activada correctamente.'));
|
|
351
|
+
} else {
|
|
352
|
+
actSpinner.warn(chalk.hex('#FFA726')('No se pudo activar la integracion. Puedes activarla manualmente desde la plataforma.'));
|
|
353
|
+
}
|
|
354
|
+
|
|
304
355
|
channels.push({ channel: CHANNEL_AGENT_MAP[channelType], key, multianswer: false });
|
|
305
356
|
}
|
|
306
357
|
}
|