plazbot-cli 0.1.2

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.
Files changed (76) hide show
  1. package/agent.config.json +21 -0
  2. package/dist/cli.js +22 -0
  3. package/dist/commands/agent/chat.js +92 -0
  4. package/dist/commands/agent/create.js +52 -0
  5. package/dist/commands/agent/delete.js +61 -0
  6. package/dist/commands/agent/enable-widget.js +55 -0
  7. package/dist/commands/agent/get.js +161 -0
  8. package/dist/commands/agent/index.js +22 -0
  9. package/dist/commands/agent/list.js +47 -0
  10. package/dist/commands/agent/on-message.js +67 -0
  11. package/dist/commands/agent/update.js +52 -0
  12. package/dist/commands/auth/index.js +9 -0
  13. package/dist/commands/auth/login.js +52 -0
  14. package/dist/commands/auth/logout.js +23 -0
  15. package/dist/commands/message/delete-webhook.js +39 -0
  16. package/dist/commands/message/index.js +14 -0
  17. package/dist/commands/message/register-webhook.js +42 -0
  18. package/dist/commands/message/send-template.js +42 -0
  19. package/dist/commands/message/send.js +42 -0
  20. package/dist/commands/portal/add-agent.js +58 -0
  21. package/dist/commands/portal/add-link.js +33 -0
  22. package/dist/commands/portal/clear-links.js +27 -0
  23. package/dist/commands/portal/create.js +51 -0
  24. package/dist/commands/portal/delete.js +58 -0
  25. package/dist/commands/portal/get.js +66 -0
  26. package/dist/commands/portal/index.js +22 -0
  27. package/dist/commands/portal/list.js +65 -0
  28. package/dist/commands/portal/update.js +79 -0
  29. package/dist/commands/whatsapp/delete-webhook.js +32 -0
  30. package/dist/commands/whatsapp/index.js +14 -0
  31. package/dist/commands/whatsapp/register-webhook.js +35 -0
  32. package/dist/commands/whatsapp/send-template.js +41 -0
  33. package/dist/commands/whatsapp/send.js +42 -0
  34. package/dist/types/agent.js +2 -0
  35. package/dist/types/auth.js +2 -0
  36. package/dist/types/common.js +2 -0
  37. package/dist/types/message.js +2 -0
  38. package/dist/types/portal.js +2 -0
  39. package/dist/utils/credentials.js +33 -0
  40. package/dist/utils/logger.js +24 -0
  41. package/package.json +47 -0
  42. package/src/cli.ts +26 -0
  43. package/src/commands/agent/chat.ts +103 -0
  44. package/src/commands/agent/create.ts +53 -0
  45. package/src/commands/agent/delete.ts +64 -0
  46. package/src/commands/agent/enable-widget.ts +62 -0
  47. package/src/commands/agent/get.ts +175 -0
  48. package/src/commands/agent/index.ts +20 -0
  49. package/src/commands/agent/list.ts +52 -0
  50. package/src/commands/agent/on-message.ts +75 -0
  51. package/src/commands/agent/update.ts +53 -0
  52. package/src/commands/auth/index.ts +8 -0
  53. package/src/commands/auth/login.ts +56 -0
  54. package/src/commands/auth/logout.ts +22 -0
  55. package/src/commands/portal/add-agent.ts +66 -0
  56. package/src/commands/portal/add-link.ts +39 -0
  57. package/src/commands/portal/clear-links.ts +26 -0
  58. package/src/commands/portal/create.ts +55 -0
  59. package/src/commands/portal/delete.ts +63 -0
  60. package/src/commands/portal/get.ts +75 -0
  61. package/src/commands/portal/index.ts +20 -0
  62. package/src/commands/portal/list.ts +73 -0
  63. package/src/commands/portal/update.ts +82 -0
  64. package/src/commands/whatsapp/delete-webhook.ts +37 -0
  65. package/src/commands/whatsapp/index.ts +12 -0
  66. package/src/commands/whatsapp/register-webhook.ts +41 -0
  67. package/src/commands/whatsapp/send-template.ts +44 -0
  68. package/src/commands/whatsapp/send.ts +46 -0
  69. package/src/types/agent.ts +63 -0
  70. package/src/types/auth.ts +8 -0
  71. package/src/types/common.ts +10 -0
  72. package/src/types/message.ts +34 -0
  73. package/src/types/portal.ts +56 -0
  74. package/src/utils/credentials.ts +37 -0
  75. package/src/utils/logger.ts +21 -0
  76. package/tsconfig.json +15 -0
@@ -0,0 +1,55 @@
1
+ import { Command } from 'commander';
2
+ import { Portal } from 'plazbot';
3
+ import { getStoredCredentials } from '../../utils/credentials';
4
+ import { logger } from '../../utils/logger';
5
+ import { PortalCommandOptions } from '../../types/portal';
6
+
7
+ export const createCommand = new Command('create')
8
+ .description('Crea un nuevo portal con configuración simplificada')
9
+ .requiredOption('-n, --name <name>', 'Nombre del portal')
10
+ .requiredOption('-t, --title <title>', 'Título de bienvenida del portal')
11
+ .option('--dev', 'Usar ambiente de desarrollo', false)
12
+ .action(async (options: PortalCommandOptions & { name: string; title: string }) => {
13
+ try {
14
+ // Obtener credenciales guardadas
15
+ const credentials = await getStoredCredentials();
16
+
17
+ const portal = new Portal({
18
+ workspaceId: credentials.workspace,
19
+ apiKey: credentials.apiKey,
20
+ zone: credentials.zone,
21
+ ...(options.dev && { customUrl: "http://localhost:5090" })
22
+ });
23
+
24
+ logger.info('\n🚀 Creando portal...');
25
+
26
+ const portalCreated = await portal.addPortal({
27
+ name: options.name,
28
+ title: options.title,
29
+ zone: credentials.zone as "LA" | "EU",
30
+ // Valores por defecto
31
+ subtitle: "",
32
+ logo: "",
33
+ logodark: "",
34
+ access: "direct",
35
+ disabled: false,
36
+ brandOff: false
37
+ });
38
+
39
+ logger.success('Portal creado exitosamente');
40
+ logger.info('\n📋 Detalles del portal:');
41
+ logger.divider();
42
+ logger.info(`ID: ${portalCreated.id}`);
43
+ logger.info(`URL: ${portalCreated.url}`);
44
+ logger.divider();
45
+
46
+ if (options.dev) {
47
+ logger.warning('\nAmbiente: desarrollo');
48
+ }
49
+
50
+ } catch (error) {
51
+ const message = error instanceof Error ? error.message : 'Error desconocido al crear el portal';
52
+ logger.error(message);
53
+ process.exit(1);
54
+ }
55
+ });
@@ -0,0 +1,63 @@
1
+ import { Command } from 'commander';
2
+ import { Portal } from 'plazbot';
3
+ import { getStoredCredentials } from '../../utils/credentials';
4
+ import { logger } from '../../utils/logger';
5
+ import { PortalCommandOptions, PortalResponse } from '../../types/portal';
6
+ import inquirer from 'inquirer';
7
+
8
+ export const deleteCommand = new Command('delete')
9
+ .description('Elimina un portal')
10
+ .argument('<portalId>', 'ID del portal')
11
+ .option('--force', 'Eliminar sin confirmación', false)
12
+ .option('--dev', 'Usar ambiente de desarrollo', false)
13
+ .action(async (portalId: string, options: PortalCommandOptions) => {
14
+ try {
15
+ // Obtener credenciales guardadas
16
+ const credentials = await getStoredCredentials();
17
+
18
+ const portal = new Portal({
19
+ workspaceId: credentials.workspace,
20
+ apiKey: credentials.apiKey,
21
+ zone: credentials.zone,
22
+ ...(options.dev && { customUrl: "http://localhost:5090" })
23
+ });
24
+
25
+ // Obtener detalles del portal para mostrar qué se va a eliminar
26
+ const portalDetails = await portal.getPortal(portalId) as PortalResponse;
27
+
28
+ logger.info('\n🗑️ Portal a eliminar:');
29
+ logger.divider();
30
+ logger.info(`ID: ${portalDetails.portal.id}`);
31
+ logger.info(`Nombre: ${portalDetails.portal.name}`);
32
+ logger.info(`URL: ${portalDetails.portal.url}`);
33
+
34
+ if (!options.force) {
35
+ const { confirm } = await inquirer.prompt([{
36
+ type: 'confirm',
37
+ name: 'confirm',
38
+ message: '¿Estás seguro de que quieres eliminar este portal?',
39
+ default: false
40
+ }]);
41
+
42
+ if (!confirm) {
43
+ logger.info('Operación cancelada.');
44
+ return;
45
+ }
46
+ }
47
+
48
+ logger.info('\n🔄 Eliminando portal...');
49
+
50
+ await portal.deletePortal(portalId);
51
+
52
+ logger.success('Portal eliminado exitosamente');
53
+
54
+ if (options.dev) {
55
+ logger.warning('\nAmbiente: desarrollo');
56
+ }
57
+
58
+ } catch (error) {
59
+ const message = error instanceof Error ? error.message : 'Error desconocido al eliminar el portal';
60
+ logger.error(message);
61
+ process.exit(1);
62
+ }
63
+ });
@@ -0,0 +1,75 @@
1
+ import { Command } from 'commander';
2
+ import { Portal } from 'plazbot';
3
+ import { getStoredCredentials } from '../../utils/credentials';
4
+ import { logger } from '../../utils/logger';
5
+ import { PortalCommandOptions, PortalResponse, PortalLink, PortalAgent } from '../../types/portal';
6
+
7
+ export const getCommand = new Command('get')
8
+ .description('Muestra información detallada de un portal')
9
+ .argument('<portalId>', 'ID del portal')
10
+ .option('--dev', 'Usar ambiente de desarrollo', false)
11
+ .action(async (portalId: string, options: PortalCommandOptions) => {
12
+ try {
13
+ // Obtener credenciales guardadas
14
+ const credentials = await getStoredCredentials();
15
+
16
+ const portal = new Portal({
17
+ workspaceId: credentials.workspace,
18
+ apiKey: credentials.apiKey,
19
+ zone: credentials.zone,
20
+ ...(options.dev && { customUrl: "http://localhost:5090" })
21
+ });
22
+
23
+ logger.info('\n🔄 Obteniendo detalles del portal...');
24
+
25
+ const response = await portal.getPortal(portalId) as PortalResponse;
26
+ const portalDetails = response.portal;
27
+
28
+ logger.info('\n🌐 Detalles del portal:');
29
+ logger.divider();
30
+
31
+ logger.info(`ID: ${portalDetails.id}`);
32
+ logger.info(`Nombre: ${portalDetails.name}`);
33
+ logger.info(`URL: ${portalDetails.url}`);
34
+ logger.info(`Acceso: ${portalDetails.access}`);
35
+ logger.info(`Estado: ${portalDetails.disabled ? 'Deshabilitado' : 'Habilitado'}`);
36
+
37
+ if (portalDetails.title) {
38
+ logger.info(`Título: ${portalDetails.title}`);
39
+ }
40
+ if (portalDetails.subtitle) {
41
+ logger.info(`Subtítulo: ${portalDetails.subtitle}`);
42
+ }
43
+
44
+ if (portalDetails.logo) {
45
+ logger.info(`\n🖼️ Recursos:`);
46
+ logger.info(`Logo: ${portalDetails.logo}`);
47
+ if (portalDetails.logodark) {
48
+ logger.info(`Logo (modo oscuro): ${portalDetails.logodark}`);
49
+ }
50
+ }
51
+
52
+ if (portalDetails.links && portalDetails.links.length > 0) {
53
+ logger.info('\n🔗 Enlaces:');
54
+ portalDetails.links.forEach((link: PortalLink) => {
55
+ logger.info(`- ${link.value}: ${link.url}`);
56
+ });
57
+ }
58
+
59
+ if (portalDetails.agents && portalDetails.agents.length > 0) {
60
+ logger.info('\n🤖 Agentes asociados:');
61
+ portalDetails.agents.forEach((agent: PortalAgent) => {
62
+ logger.info(`- ${agent.name} (${agent.id})`);
63
+ });
64
+ }
65
+
66
+ if (options.dev) {
67
+ logger.warning('\nAmbiente: desarrollo');
68
+ }
69
+
70
+ } catch (error) {
71
+ const message = error instanceof Error ? error.message : 'Error desconocido al obtener detalles del portal';
72
+ logger.error(message);
73
+ process.exit(1);
74
+ }
75
+ });
@@ -0,0 +1,20 @@
1
+ import { Command } from 'commander';
2
+ import { getCommand } from './get';
3
+ import { deleteCommand } from './delete';
4
+ import { createCommand } from './create';
5
+ import { updateCommand } from './update';
6
+ import { addAgentCommand } from './add-agent';
7
+ import { listCommand } from './list';
8
+ import { addLinkCommand } from './add-link';
9
+ import { clearLinksCommand } from './clear-links';
10
+
11
+ export const portalCommands = new Command('portal')
12
+ .description('Comandos relacionados con portales')
13
+ .addCommand(listCommand)
14
+ .addCommand(getCommand)
15
+ .addCommand(deleteCommand)
16
+ .addCommand(createCommand)
17
+ .addCommand(updateCommand)
18
+ .addCommand(addAgentCommand)
19
+ .addCommand(addLinkCommand)
20
+ .addCommand(clearLinksCommand);
@@ -0,0 +1,73 @@
1
+ import { Command } from 'commander';
2
+ import { Portal } from 'plazbot';
3
+ import { getStoredCredentials } from '../../utils/credentials';
4
+ import { logger } from '../../utils/logger';
5
+ import { PortalCommandOptions } from '../../types/portal';
6
+
7
+ export const listCommand = new Command('list')
8
+ .description('Muestra el portal asociado al workspace')
9
+ .option('--dev', 'Usar ambiente de desarrollo', false)
10
+ .action(async (options: PortalCommandOptions) => {
11
+ try {
12
+ // Obtener credenciales guardadas
13
+ const credentials = await getStoredCredentials();
14
+
15
+ const portal = new Portal({
16
+ workspaceId: credentials.workspace,
17
+ apiKey: credentials.apiKey,
18
+ zone: credentials.zone,
19
+ ...(options.dev && { customUrl: "http://localhost:5090" })
20
+ });
21
+
22
+ logger.info('\n🔍 Buscando portal del workspace...');
23
+
24
+ const response = await portal.getExistsPortal();
25
+ const portalDetails = response.portal;
26
+
27
+ logger.info('\n🌐 Portal encontrado:');
28
+ logger.divider();
29
+ logger.info(`ID: ${portalDetails.id}`);
30
+ logger.info(`Nombre: ${portalDetails.name}`);
31
+ logger.info(`URL: ${portalDetails.url}`);
32
+ logger.info(`Acceso: ${portalDetails.access}`);
33
+ logger.info(`Estado: ${portalDetails.disabled ? 'Deshabilitado' : 'Habilitado'}`);
34
+
35
+ if (portalDetails.title) {
36
+ logger.info(`Título: ${portalDetails.title}`);
37
+ }
38
+ if (portalDetails.subtitle) {
39
+ logger.info(`Subtítulo: ${portalDetails.subtitle}`);
40
+ }
41
+
42
+ if (portalDetails.logo) {
43
+ logger.info('\n🖼️ Recursos:');
44
+ logger.info(`Logo: ${portalDetails.logo}`);
45
+ if (portalDetails.logodark) {
46
+ logger.info(`Logo (modo oscuro): ${portalDetails.logodark}`);
47
+ }
48
+ }
49
+
50
+ if (portalDetails.links && portalDetails.links.length > 0) {
51
+ logger.info('\n🔗 Enlaces:');
52
+ portalDetails.links.forEach((link: { value: string; url: string }) => {
53
+ logger.info(`- ${link.value}: ${link.url}`);
54
+ });
55
+ }
56
+
57
+ if (portalDetails.agents && portalDetails.agents.length > 0) {
58
+ logger.info('\n🤖 Agentes asociados:');
59
+ portalDetails.agents.forEach((agent: { name: string; id: string }) => {
60
+ logger.info(`- ${agent.name} (${agent.id})`);
61
+ });
62
+ }
63
+
64
+ if (options.dev) {
65
+ logger.warning('\nAmbiente: desarrollo');
66
+ }
67
+
68
+ } catch (error) {
69
+ const message = error instanceof Error ? error.message : 'Error desconocido al listar el portal';
70
+ logger.error(message);
71
+ process.exit(1);
72
+ }
73
+ });
@@ -0,0 +1,82 @@
1
+ import { Command } from 'commander';
2
+ import { Portal } from 'plazbot';
3
+ import { getStoredCredentials } from '../../utils/credentials';
4
+ import { logger } from '../../utils/logger';
5
+ import { PortalCommandOptions } from '../../types/portal';
6
+
7
+ export const updateCommand = new Command('update')
8
+ .description('Actualiza un portal existente')
9
+ .argument('<portalId>', 'ID del portal a actualizar')
10
+ .option('-n, --name <name>', 'Nuevo nombre del portal')
11
+ .option('-t, --title <title>', 'Nuevo título del portal')
12
+ .option('-s, --subtitle <subtitle>', 'Nuevo subtítulo del portal')
13
+ .option('-l, --logo <url>', 'Nueva URL del logo')
14
+ .option('-d, --logo-dark <url>', 'Nueva URL del logo en modo oscuro')
15
+ .option('-a, --access <type>', 'Tipo de acceso (direct o form)')
16
+ .option('--disabled <value>', 'Estado de deshabilitación (true o false)')
17
+ .option('--brand-off <value>', 'Estado de marca deshabilitada (true o false)')
18
+ .option('--dev', 'Usar ambiente de desarrollo', false)
19
+ .action(async (portalId: string, options: PortalCommandOptions) => {
20
+ try {
21
+ // Obtener credenciales guardadas
22
+ const credentials = await getStoredCredentials();
23
+
24
+ const portal = new Portal({
25
+ workspaceId: credentials.workspace,
26
+ apiKey: credentials.apiKey,
27
+ zone: credentials.zone,
28
+ ...(options.dev && { customUrl: "http://localhost:5090" })
29
+ });
30
+
31
+ // Obtener detalles actuales del portal
32
+ const currentPortal = await portal.getPortal(portalId);
33
+
34
+ logger.info('\n🌐 Actualizando portal...');
35
+ logger.info('Portal actual:');
36
+ logger.info(JSON.stringify(currentPortal.portal, null, 2));
37
+
38
+ // Construir objeto de actualización solo con los campos proporcionados
39
+ const updateData: any = { id: portalId };
40
+
41
+ if (options.name) updateData.name = options.name;
42
+ if (options.title) updateData.title = options.title;
43
+ if (options.subtitle) updateData.subtitle = options.subtitle;
44
+ if (options.logo) updateData.logo = options.logo;
45
+ if (options.logoDark) updateData.logodark = options.logoDark;
46
+ if (options.access) {
47
+ if (options.access !== 'direct' && options.access !== 'form') {
48
+ throw new Error('El tipo de acceso debe ser "direct" o "form"');
49
+ }
50
+ updateData.access = options.access;
51
+ }
52
+ if (options.disabled) {
53
+ if (options.disabled !== 'true' && options.disabled !== 'false') {
54
+ throw new Error('El valor de disabled debe ser "true" o "false"');
55
+ }
56
+ updateData.disabled = options.disabled === 'true';
57
+ }
58
+ if (options.brandOff) {
59
+ if (options.brandOff !== 'true' && options.brandOff !== 'false') {
60
+ throw new Error('El valor de brand-off debe ser "true" o "false"');
61
+ }
62
+ updateData.brandOff = options.brandOff === 'true';
63
+ }
64
+
65
+ logger.info('\nCambios a aplicar:');
66
+ logger.info(JSON.stringify(updateData, null, 2));
67
+
68
+ const result = await portal.updatePortal(updateData);
69
+
70
+ logger.success('Portal actualizado exitosamente');
71
+ logger.info(`Mensaje: ${result.message}`);
72
+
73
+ if (options.dev) {
74
+ logger.warning('\nAmbiente: desarrollo');
75
+ }
76
+
77
+ } catch (error) {
78
+ const message = error instanceof Error ? error.message : 'Error desconocido al actualizar el portal';
79
+ logger.error(message);
80
+ process.exit(1);
81
+ }
82
+ });
@@ -0,0 +1,37 @@
1
+ import { Command } from 'commander';
2
+ import { Message } from 'plazbot';
3
+ import { getStoredCredentials } from '../../utils/credentials';
4
+ import { logger } from '../../utils/logger';
5
+
6
+ interface DeleteWebhookOptions {
7
+ dev?: boolean;
8
+ number: string;
9
+ }
10
+
11
+ export const deleteWebhookCommand = new Command('delete-webhook')
12
+ .description('Elimina el webhook de WhatsApp')
13
+ .requiredOption('-n, --number <phone>', 'Número de WhatsApp (con código de país, ej: 51912345678)')
14
+ .option('--dev', 'Usar ambiente de desarrollo', false)
15
+ .action(async (options: DeleteWebhookOptions) => {
16
+ try {
17
+ const credentials = await getStoredCredentials();
18
+ const messageClient = new Message({
19
+ workspaceId: credentials.workspace,
20
+ apiKey: credentials.apiKey,
21
+ zone: credentials.zone,
22
+ ...(options.dev && { customUrl: "http://localhost:5090" })
23
+ });
24
+
25
+ logger.info('\n🗑️ Eliminando webhook de WhatsApp...');
26
+ logger.info(`Número: ${options.number}`);
27
+
28
+ await messageClient.deleteWebhook({
29
+ number: options.number
30
+ });
31
+
32
+ logger.success('Webhook eliminado exitosamente');
33
+ } catch (error: unknown) {
34
+ logger.error(`❌ Error al eliminar webhook: ${(error as Error).message}`);
35
+ process.exit(1);
36
+ }
37
+ });
@@ -0,0 +1,12 @@
1
+ import { Command } from 'commander';
2
+ import { sendMessageCommand } from './send';
3
+ import { sendTemplateCommand } from './send-template';
4
+ import { registerWebhookCommand } from './register-webhook';
5
+ import { deleteWebhookCommand } from './delete-webhook';
6
+
7
+ export const whatsappCommands = new Command('whatsapp')
8
+ .description('Comandos relacionados con mensajes de WhatsApp')
9
+ .addCommand(sendMessageCommand)
10
+ .addCommand(sendTemplateCommand)
11
+ .addCommand(registerWebhookCommand)
12
+ .addCommand(deleteWebhookCommand);
@@ -0,0 +1,41 @@
1
+ import { Command } from 'commander';
2
+ import { Message } from 'plazbot';
3
+ import { getStoredCredentials } from '../../utils/credentials';
4
+ import { logger } from '../../utils/logger';
5
+
6
+ interface RegisterWebhookOptions {
7
+ dev?: boolean;
8
+ number: string;
9
+ url: string;
10
+ }
11
+
12
+ export const registerWebhookCommand = new Command('register-webhook')
13
+ .description('Registra un webhook para WhatsApp')
14
+ .requiredOption('-n, --number <phone>', 'Número de WhatsApp (con código de país, ej: 51912345678)')
15
+ .requiredOption('-u, --url <webhook>', 'URL del webhook')
16
+ .option('--dev', 'Usar ambiente de desarrollo', false)
17
+ .action(async (options: RegisterWebhookOptions) => {
18
+ try {
19
+ const credentials = await getStoredCredentials();
20
+ const messageClient = new Message({
21
+ workspaceId: credentials.workspace,
22
+ apiKey: credentials.apiKey,
23
+ zone: credentials.zone,
24
+ ...(options.dev && { customUrl: "http://localhost:5090" })
25
+ });
26
+
27
+ logger.info('\n🔗 Registrando webhook de WhatsApp...');
28
+ logger.info(`Número: ${options.number}`);
29
+ logger.info(`URL: ${options.url}`);
30
+
31
+ await messageClient.registerWebhook({
32
+ number: options.number,
33
+ webhookUrl: options.url
34
+ });
35
+
36
+ logger.success('Webhook registrado exitosamente');
37
+ } catch (error: unknown) {
38
+ logger.error(`❌ Error al registrar webhook: ${(error as Error).message}`);
39
+ process.exit(1);
40
+ }
41
+ });
@@ -0,0 +1,44 @@
1
+ import { Command } from 'commander';
2
+ import { Message } from 'plazbot';
3
+ import { getStoredCredentials } from '../../utils/credentials';
4
+ import { logger } from '../../utils/logger';
5
+ import { TemplateCommandOptions } from '../../types/message';
6
+
7
+ export const sendTemplateCommand = new Command('send-template')
8
+ .description('Envía una plantilla de WhatsApp')
9
+ .requiredOption('-p, --phone <number>', 'Número de teléfono del destinatario (con código de país, ej: 51912345678)')
10
+ .requiredOption('-t, --template <name>', 'Nombre de la plantilla a enviar')
11
+ .option('--dev', 'Usar ambiente de desarrollo', false)
12
+ .action(async (options: TemplateCommandOptions) => {
13
+ try {
14
+ const credentials = await getStoredCredentials();
15
+ const messageClient = new Message({
16
+ workspaceId: credentials.workspace,
17
+ apiKey: credentials.apiKey,
18
+ zone: credentials.zone,
19
+ ...(options.dev && { customUrl: "http://localhost:5090" })
20
+ });
21
+
22
+ logger.info('\n📱 Enviando plantilla de WhatsApp...');
23
+ logger.info(`A: ${options.phone}`);
24
+ logger.info(`Plantilla: ${options.template}`);
25
+
26
+ const response = await messageClient.onConversation({
27
+ to: options.phone,
28
+ template: options.template
29
+ });
30
+
31
+ logger.success('Plantilla enviada exitosamente');
32
+ logger.info('\n📋 Detalles:');
33
+ logger.info(JSON.stringify(response, null, 2));
34
+
35
+ if (options.dev) {
36
+ logger.warning('\nAmbiente: desarrollo');
37
+ }
38
+
39
+ } catch (error: unknown) {
40
+ const message = error instanceof Error ? error.message : 'Error desconocido al enviar la plantilla';
41
+ logger.error(message);
42
+ process.exit(1);
43
+ }
44
+ });
@@ -0,0 +1,46 @@
1
+ import { Command } from 'commander';
2
+ import { Message } from 'plazbot';
3
+ import { getStoredCredentials } from '../../utils/credentials';
4
+ import { logger } from '../../utils/logger';
5
+ import { DirectMessageCommandOptions } from '../../types/message';
6
+
7
+ export const sendMessageCommand = new Command('send-message')
8
+ .description('Envía un mensaje de WhatsApp')
9
+ .requiredOption('-t, --to <phone>', 'Número de teléfono del destinatario (con código de país, ej: 51912345678)')
10
+ .requiredOption('-m, --message <text>', 'Mensaje a enviar')
11
+ .option('--dev', 'Usar ambiente de desarrollo', false)
12
+ .action(async (options: DirectMessageCommandOptions) => {
13
+ try {
14
+ // Obtener credenciales guardadas
15
+ const credentials = await getStoredCredentials();
16
+
17
+ const messageClient = new Message({
18
+ workspaceId: credentials.workspace,
19
+ apiKey: credentials.apiKey,
20
+ zone: credentials.zone,
21
+ ...(options.dev && { customUrl: "http://localhost:5090" })
22
+ });
23
+
24
+ logger.info('\n📱 Enviando mensaje de WhatsApp...');
25
+ logger.info(`A: ${options.to}`);
26
+ logger.info(`Mensaje: ${options.message}`);
27
+
28
+ const response = await messageClient.onWhatsappMessage({
29
+ message: options.message,
30
+ to: options.to
31
+ });
32
+
33
+ logger.success('Mensaje enviado exitosamente');
34
+ logger.info('\n📋 Detalles:');
35
+ logger.info(JSON.stringify(response, null, 2));
36
+
37
+ if (options.dev) {
38
+ logger.warning('\nAmbiente: desarrollo');
39
+ }
40
+
41
+ } catch (error: unknown) {
42
+ const message = (error as Error)?.message || 'Error desconocido al enviar el mensaje';
43
+ logger.error(message);
44
+ process.exit(1);
45
+ }
46
+ });
@@ -0,0 +1,63 @@
1
+ import { BaseCommandOptions } from './common';
2
+
3
+ export interface AgentCommandOptions {
4
+ dev?: boolean;
5
+ }
6
+
7
+ export interface ChatOptions extends BaseCommandOptions {
8
+ agentId: string;
9
+ sessionId?: string;
10
+ multipleAnswers?: boolean;
11
+ }
12
+
13
+ export interface OnMessageOptions extends BaseCommandOptions {
14
+ agentId: string;
15
+ question: string;
16
+ sessionId?: string;
17
+ multipleAnswers?: boolean;
18
+ }
19
+
20
+ export interface EnableWidgetOptions extends AgentCommandOptions {
21
+ disable?: boolean;
22
+ }
23
+
24
+ export interface ListAgentsOptions extends BaseCommandOptions {
25
+ }
26
+
27
+ export interface AgentListItem {
28
+ id: string;
29
+ name: string;
30
+ enable: boolean;
31
+ description: string;
32
+ createdAt: string;
33
+ }
34
+
35
+ export interface ChatMessage {
36
+ timestamp: string;
37
+ role: string;
38
+ content: string;
39
+ metadata?: Record<string, any>;
40
+ source?: string;
41
+ }
42
+
43
+ export interface ChatHistoryParams {
44
+ id: string;
45
+ limit: number;
46
+ from?: string;
47
+ to?: string;
48
+ }
49
+
50
+ export interface ChatHistoryResponse {
51
+ messages: ChatMessage[];
52
+ success: boolean;
53
+ }
54
+
55
+ export interface AgentSource {
56
+ title?: string;
57
+ url?: string;
58
+ }
59
+
60
+ export interface AgentResponse {
61
+ answer: string;
62
+ sources?: AgentSource[];
63
+ }
@@ -0,0 +1,8 @@
1
+ import { BaseCommandOptions } from './common';
2
+
3
+ export interface LoginOptions extends BaseCommandOptions {
4
+ email: string;
5
+ apiKey: string;
6
+ workspace: string;
7
+ zone: "LA" | "EU";
8
+ }
@@ -0,0 +1,10 @@
1
+ export interface BaseCommandOptions {
2
+ dev?: boolean;
3
+ }
4
+
5
+ export interface SDKOptions {
6
+ workspaceId: string;
7
+ apiKey: string;
8
+ zone: "LA" | "EU";
9
+ customUrl?: string;
10
+ }
@@ -0,0 +1,34 @@
1
+ export interface MessageCommandOptions {
2
+ dev?: boolean;
3
+ to?: string;
4
+ message?: string;
5
+ phone?: string;
6
+ template?: string;
7
+ }
8
+
9
+ export interface DirectMessageCommandOptions {
10
+ dev?: boolean;
11
+ to: string;
12
+ message: string;
13
+ }
14
+
15
+ export interface TemplateCommandOptions {
16
+ dev?: boolean;
17
+ phone: string;
18
+ template: string;
19
+ }
20
+
21
+ export interface WhatsappMessageParams {
22
+ message: string;
23
+ to: string;
24
+ }
25
+
26
+ export interface ConversationTemplateParams {
27
+ to: string;
28
+ template: string;
29
+ }
30
+
31
+ export interface WebhookParams {
32
+ number: string;
33
+ webhookUrl: string;
34
+ }