plazbot-cli 0.2.11 → 0.2.15

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.
@@ -50,6 +50,15 @@ async function fetchWorkspaceIntegrations(baseUrl, workspaceId, headers) {
50
50
  return [];
51
51
  }
52
52
  }
53
+ async function activateIntegration(baseUrl, workspaceId, integrationId, headers) {
54
+ try {
55
+ const res = await axios_1.default.post(`${baseUrl}/api/workspace/${workspaceId}/integrations/${integrationId}/activate`, { isActive: true }, { headers });
56
+ return res.data?.success === true;
57
+ }
58
+ catch {
59
+ return false;
60
+ }
61
+ }
53
62
  async function connectChannelFlow(ctx) {
54
63
  const channels = [];
55
64
  const baseUrl = getBaseUrl(ctx.zone, ctx.dev);
@@ -92,6 +101,17 @@ async function connectChannelFlow(ctx) {
92
101
  // Selecciono una existente
93
102
  selectedIntegration = existing.find((ig) => ig.id === selected);
94
103
  const label = getIntegrationLabel(selectedIntegration);
104
+ // Activar la integracion si no esta activa
105
+ if (!selectedIntegration.isActive) {
106
+ const actSpinner = (0, ora_1.default)({ text: chalk_1.default.gray('Activando integracion...'), spinner: 'dots', color: 'green' }).start();
107
+ const activated = await activateIntegration(baseUrl, ctx.workspaceId, selectedIntegration.id, headers);
108
+ if (activated) {
109
+ actSpinner.succeed(chalk_1.default.hex('#4ade80')('Integracion activada correctamente.'));
110
+ }
111
+ else {
112
+ actSpinner.warn(chalk_1.default.hex('#FFA726')('No se pudo activar la integracion. Puedes activarla manualmente desde la plataforma.'));
113
+ }
114
+ }
95
115
  channels.push({
96
116
  channel: CHANNEL_AGENT_MAP[channelType],
97
117
  key: selectedIntegration.id,
@@ -178,6 +198,15 @@ async function connectChannelFlow(ctx) {
178
198
  if (detected) {
179
199
  const detectedName = getIntegrationLabel(detected);
180
200
  pollSpinner.succeed(chalk_1.default.hex('#4ade80')(`Conexion detectada: ${detectedName}`));
201
+ // Activar la integracion detectada
202
+ const actSpinner = (0, ora_1.default)({ text: chalk_1.default.gray('Activando integracion...'), spinner: 'dots', color: 'green' }).start();
203
+ const activated = await activateIntegration(baseUrl, ctx.workspaceId, detected.id, headers);
204
+ if (activated) {
205
+ actSpinner.succeed(chalk_1.default.hex('#4ade80')('Integracion activada correctamente.'));
206
+ }
207
+ else {
208
+ actSpinner.warn(chalk_1.default.hex('#FFA726')('No se pudo activar la integracion. Puedes activarla manualmente desde la plataforma.'));
209
+ }
181
210
  channels.push({
182
211
  channel: CHANNEL_AGENT_MAP[channelType],
183
212
  key: detected.id,
@@ -199,6 +228,15 @@ async function connectChannelFlow(ctx) {
199
228
  const { key } = await inquirer_1.default.prompt([
200
229
  { type: 'input', name: 'key', message: `ID/numero del canal ${channelLabel}:`, validate: (v) => v.length > 0 || 'Requerido' },
201
230
  ]);
231
+ // Activar la integracion ingresada manualmente
232
+ const actSpinner = (0, ora_1.default)({ text: chalk_1.default.gray('Activando integracion...'), spinner: 'dots', color: 'green' }).start();
233
+ const activated = await activateIntegration(baseUrl, ctx.workspaceId, key, headers);
234
+ if (activated) {
235
+ actSpinner.succeed(chalk_1.default.hex('#4ade80')('Integracion activada correctamente.'));
236
+ }
237
+ else {
238
+ actSpinner.warn(chalk_1.default.hex('#FFA726')('No se pudo activar la integracion. Puedes activarla manualmente desde la plataforma.'));
239
+ }
202
240
  channels.push({ channel: CHANNEL_AGENT_MAP[channelType], key, multianswer: false });
203
241
  }
204
242
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "plazbot-cli",
3
- "version": "0.2.11",
3
+ "version": "0.2.15",
4
4
  "description": "CLI para Plazbot SDK",
5
5
  "main": "dist/cli.js",
6
6
  "bin": {
@@ -141,6 +141,19 @@ async function fetchWorkspaceIntegrations(baseUrl: string, workspaceId: string,
141
141
  }
142
142
  }
143
143
 
144
+ async function activateIntegration(baseUrl: string, workspaceId: string, integrationId: string, headers: any): Promise<boolean> {
145
+ try {
146
+ const res = await axios.post(
147
+ `${baseUrl}/api/workspace/${workspaceId}/integrations/${integrationId}/activate`,
148
+ { isActive: true },
149
+ { headers }
150
+ );
151
+ return res.data?.success === true;
152
+ } catch {
153
+ return false;
154
+ }
155
+ }
156
+
144
157
  async function connectChannelFlow(ctx: WizardContext): Promise<AgentChannel[]> {
145
158
  const channels: AgentChannel[] = [];
146
159
  const baseUrl = getBaseUrl(ctx.zone, ctx.dev);
@@ -190,6 +203,18 @@ async function connectChannelFlow(ctx: WizardContext): Promise<AgentChannel[]> {
190
203
  // Selecciono una existente
191
204
  selectedIntegration = existing.find((ig: any) => ig.id === selected);
192
205
  const label = getIntegrationLabel(selectedIntegration);
206
+
207
+ // Activar la integracion si no esta activa
208
+ if (!selectedIntegration.isActive) {
209
+ const actSpinner = ora({ text: chalk.gray('Activando integracion...'), spinner: 'dots', color: 'green' }).start();
210
+ const activated = await activateIntegration(baseUrl, ctx.workspaceId, selectedIntegration.id, headers);
211
+ if (activated) {
212
+ actSpinner.succeed(chalk.hex('#4ade80')('Integracion activada correctamente.'));
213
+ } else {
214
+ actSpinner.warn(chalk.hex('#FFA726')('No se pudo activar la integracion. Puedes activarla manualmente desde la plataforma.'));
215
+ }
216
+ }
217
+
193
218
  channels.push({
194
219
  channel: CHANNEL_AGENT_MAP[channelType],
195
220
  key: selectedIntegration.id,
@@ -281,6 +306,16 @@ async function connectChannelFlow(ctx: WizardContext): Promise<AgentChannel[]> {
281
306
  if (detected) {
282
307
  const detectedName = getIntegrationLabel(detected);
283
308
  pollSpinner.succeed(chalk.hex('#4ade80')(`Conexion detectada: ${detectedName}`));
309
+
310
+ // Activar la integracion detectada
311
+ const actSpinner = ora({ text: chalk.gray('Activando integracion...'), spinner: 'dots', color: 'green' }).start();
312
+ const activated = await activateIntegration(baseUrl, ctx.workspaceId, detected.id, headers);
313
+ if (activated) {
314
+ actSpinner.succeed(chalk.hex('#4ade80')('Integracion activada correctamente.'));
315
+ } else {
316
+ actSpinner.warn(chalk.hex('#FFA726')('No se pudo activar la integracion. Puedes activarla manualmente desde la plataforma.'));
317
+ }
318
+
284
319
  channels.push({
285
320
  channel: CHANNEL_AGENT_MAP[channelType],
286
321
  key: detected.id,
@@ -301,6 +336,16 @@ async function connectChannelFlow(ctx: WizardContext): Promise<AgentChannel[]> {
301
336
  const { key } = await (inquirer as any).prompt([
302
337
  { type: 'input', name: 'key', message: `ID/numero del canal ${channelLabel}:`, validate: (v: string) => v.length > 0 || 'Requerido' },
303
338
  ]);
339
+
340
+ // Activar la integracion ingresada manualmente
341
+ const actSpinner = ora({ text: chalk.gray('Activando integracion...'), spinner: 'dots', color: 'green' }).start();
342
+ const activated = await activateIntegration(baseUrl, ctx.workspaceId, key, headers);
343
+ if (activated) {
344
+ actSpinner.succeed(chalk.hex('#4ade80')('Integracion activada correctamente.'));
345
+ } else {
346
+ actSpinner.warn(chalk.hex('#FFA726')('No se pudo activar la integracion. Puedes activarla manualmente desde la plataforma.'));
347
+ }
348
+
304
349
  channels.push({ channel: CHANNEL_AGENT_MAP[channelType], key, multianswer: false });
305
350
  }
306
351
  }