plazbot-cli
Version:
CLI para Plazbot SDK
68 lines (59 loc) • 2.38 kB
text/typescript
import { Command } from 'commander';
import { Agent } from 'plazbot';
import { getStoredCredentials } from '../../utils/credentials';
import { logger } from '../../utils/logger';
import { createSpinner } from '../../utils/ui';
const widgetGroup = new Command('widget')
.description('Gestionar widget de WhatsApp');
widgetGroup.command('enable')
.description('Activar widget de WhatsApp en un agente')
.argument('<agentId>', 'ID del agente')
.requiredOption('-u, --url <url>', 'URL de WhatsApp (ej: https://wa.me/51912345678)')
.option('--dev', 'Usar ambiente de desarrollo', false)
.action(async (agentId: string, options: any) => {
try {
const credentials = await getStoredCredentials();
const agent = new Agent({
workspaceId: credentials.workspace,
apiKey: credentials.apiKey,
zone: credentials.zone,
...(options.dev && { customUrl: "http://localhost:5090" })
});
const spinner = createSpinner('Activando widget WhatsApp...');
spinner.start();
await agent.updateAgent(agentId, {
enableWhatsappWidget: true,
urlWhatsappWidget: options.url,
});
spinner.succeed('Widget WhatsApp activado');
logger.label('URL', options.url);
} catch (error) {
const message = error instanceof Error ? error.message : 'Error desconocido';
logger.error(message);
process.exit(1);
}
});
widgetGroup.command('disable')
.description('Desactivar widget de WhatsApp de un agente')
.argument('<agentId>', 'ID del agente')
.option('--dev', 'Usar ambiente de desarrollo', false)
.action(async (agentId: string, options: any) => {
try {
const credentials = await getStoredCredentials();
const agent = new Agent({
workspaceId: credentials.workspace,
apiKey: credentials.apiKey,
zone: credentials.zone,
...(options.dev && { customUrl: "http://localhost:5090" })
});
const spinner = createSpinner('Desactivando widget WhatsApp...');
spinner.start();
await agent.updateAgent(agentId, { enableWhatsappWidget: false });
spinner.succeed('Widget WhatsApp desactivado');
} catch (error) {
const message = error instanceof Error ? error.message : 'Error desconocido';
logger.error(message);
process.exit(1);
}
});
export const widgetCommand = widgetGroup;