plazbot-cli 0.1.3 → 0.1.4
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.
- package/.claude/settings.local.json +14 -0
- package/CLAUDE.md +92 -0
- package/README.md +1 -1
- package/dist/cli.js +14 -5
- package/dist/commands/agent/ai-config.js +107 -0
- package/dist/commands/agent/chat.js +130 -34
- package/dist/commands/agent/copy.js +37 -0
- package/dist/commands/agent/create.js +80 -17
- package/dist/commands/agent/files.js +142 -0
- package/dist/commands/agent/index.js +14 -2
- package/dist/commands/agent/set.js +127 -0
- package/dist/commands/agent/templates.js +240 -0
- package/dist/commands/agent/tools.js +161 -0
- package/dist/commands/agent/wizard.js +369 -0
- package/dist/commands/whatsapp/broadcast.js +97 -0
- package/dist/commands/whatsapp/channels.js +86 -0
- package/dist/commands/whatsapp/chat.js +74 -0
- package/dist/commands/whatsapp/index.js +11 -2
- package/dist/commands/whatsapp/send-template.js +51 -14
- package/dist/commands/whatsapp/send.js +10 -10
- package/dist/commands/whatsapp/widget.js +64 -0
- package/dist/utils/banner.js +87 -0
- package/dist/utils/logger.js +27 -6
- package/dist/utils/ui.js +111 -0
- package/package.json +10 -2
- package/src/cli.ts +13 -5
- package/src/commands/agent/ai-config.ts +112 -0
- package/src/commands/agent/chat.ts +149 -40
- package/src/commands/agent/copy.ts +40 -0
- package/src/commands/agent/create.ts +58 -23
- package/src/commands/agent/files.ts +158 -0
- package/src/commands/agent/index.ts +14 -2
- package/src/commands/agent/set.ts +137 -0
- package/src/commands/agent/templates.ts +249 -0
- package/src/commands/agent/tools.ts +167 -0
- package/src/commands/agent/wizard.ts +475 -0
- package/src/commands/whatsapp/broadcast.ts +100 -0
- package/src/commands/whatsapp/channels.ts +98 -0
- package/src/commands/whatsapp/chat.ts +77 -0
- package/src/commands/whatsapp/index.ts +11 -2
- package/src/commands/whatsapp/send-template.ts +57 -19
- package/src/commands/whatsapp/send.ts +15 -14
- package/src/commands/whatsapp/widget.ts +67 -0
- package/src/utils/banner.ts +94 -0
- package/src/utils/logger.ts +26 -7
- package/src/utils/ui.ts +109 -0
- package/dist/commands/message/delete-webhook.js +0 -39
- package/dist/commands/message/index.js +0 -14
- package/dist/commands/message/register-webhook.js +0 -42
- package/dist/commands/message/send-template.js +0 -42
- package/dist/commands/message/send.js +0 -42
package/src/utils/ui.ts
ADDED
|
@@ -0,0 +1,109 @@
|
|
|
1
|
+
import chalk from 'chalk';
|
|
2
|
+
import ora, { Ora } from 'ora';
|
|
3
|
+
import Table from 'cli-table3';
|
|
4
|
+
|
|
5
|
+
// Colores del tema Plazbot
|
|
6
|
+
export const theme = {
|
|
7
|
+
primary: chalk.hex('#4CAF50'),
|
|
8
|
+
secondary: chalk.hex('#2196F3'),
|
|
9
|
+
accent: chalk.hex('#FFA726'),
|
|
10
|
+
success: chalk.hex('#66BB6A'),
|
|
11
|
+
error: chalk.hex('#EF5350'),
|
|
12
|
+
warning: chalk.hex('#FFA726'),
|
|
13
|
+
muted: chalk.gray,
|
|
14
|
+
bold: chalk.bold,
|
|
15
|
+
dim: chalk.dim,
|
|
16
|
+
};
|
|
17
|
+
|
|
18
|
+
// Spinner
|
|
19
|
+
export function createSpinner(text: string): Ora {
|
|
20
|
+
return ora({
|
|
21
|
+
text: theme.muted(text),
|
|
22
|
+
spinner: 'dots',
|
|
23
|
+
color: 'green',
|
|
24
|
+
});
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
// Tabla formateada
|
|
28
|
+
export function createTable(headers: string[], rows: string[][]): string {
|
|
29
|
+
const table = new Table({
|
|
30
|
+
head: headers.map(h => theme.bold.hex('#4CAF50')(h)),
|
|
31
|
+
style: {
|
|
32
|
+
head: [],
|
|
33
|
+
border: ['gray'],
|
|
34
|
+
},
|
|
35
|
+
chars: {
|
|
36
|
+
'top': '─', 'top-mid': '┬', 'top-left': '┌', 'top-right': '┐',
|
|
37
|
+
'bottom': '─', 'bottom-mid': '┴', 'bottom-left': '└', 'bottom-right': '┘',
|
|
38
|
+
'left': '│', 'left-mid': '├', 'mid': '─', 'mid-mid': '┼',
|
|
39
|
+
'right': '│', 'right-mid': '┤', 'middle': '│'
|
|
40
|
+
}
|
|
41
|
+
});
|
|
42
|
+
rows.forEach(row => table.push(row));
|
|
43
|
+
return table.toString();
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
// Box simple
|
|
47
|
+
export function box(content: string, title?: string): string {
|
|
48
|
+
const lines = content.split('\n');
|
|
49
|
+
const maxLen = Math.max(...lines.map(l => stripAnsi(l).length), title ? stripAnsi(title).length + 4 : 0);
|
|
50
|
+
const width = maxLen + 4;
|
|
51
|
+
|
|
52
|
+
let result = '';
|
|
53
|
+
if (title) {
|
|
54
|
+
result += theme.muted(' ┌─ ') + theme.primary(title) + theme.muted(' ' + '─'.repeat(Math.max(0, width - stripAnsi(title).length - 5))) + theme.muted('┐') + '\n';
|
|
55
|
+
} else {
|
|
56
|
+
result += theme.muted(' ┌' + '─'.repeat(width) + '┐') + '\n';
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
for (const line of lines) {
|
|
60
|
+
const pad = ' '.repeat(Math.max(0, maxLen - stripAnsi(line).length));
|
|
61
|
+
result += theme.muted(' │') + ' ' + line + pad + ' ' + theme.muted('│') + '\n';
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
result += theme.muted(' └' + '─'.repeat(width) + '┘');
|
|
65
|
+
return result;
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
// Strip ANSI codes para calcular longitud real
|
|
69
|
+
function stripAnsi(str: string): string {
|
|
70
|
+
return str.replace(/\x1b\[[0-9;]*m/g, '');
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
// Formato de fecha legible
|
|
74
|
+
export function formatDate(date: string | Date): string {
|
|
75
|
+
const d = new Date(date);
|
|
76
|
+
return d.toLocaleDateString('es-ES', {
|
|
77
|
+
year: 'numeric',
|
|
78
|
+
month: 'short',
|
|
79
|
+
day: 'numeric',
|
|
80
|
+
hour: '2-digit',
|
|
81
|
+
minute: '2-digit'
|
|
82
|
+
});
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
// Status badge
|
|
86
|
+
export function statusBadge(enabled: boolean): string {
|
|
87
|
+
return enabled
|
|
88
|
+
? theme.success('● activo')
|
|
89
|
+
: theme.error('○ inactivo');
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
// Key-value pair formateado
|
|
93
|
+
export function kvPair(key: string, value: string): string {
|
|
94
|
+
return ` ${theme.muted(key + ':')} ${value}`;
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
// Sección con título
|
|
98
|
+
export function section(title: string): string {
|
|
99
|
+
return '\n' + theme.bold.hex('#4CAF50')(` ${title}`) + '\n' + theme.muted(' ' + '─'.repeat(40));
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
// Progress bar simple
|
|
103
|
+
export function progressBar(current: number, total: number, width: number = 30): string {
|
|
104
|
+
const percent = Math.round((current / total) * 100);
|
|
105
|
+
const filled = Math.round((current / total) * width);
|
|
106
|
+
const empty = width - filled;
|
|
107
|
+
const bar = theme.success('█'.repeat(filled)) + theme.muted('░'.repeat(empty));
|
|
108
|
+
return `${bar} ${theme.bold(percent + '%')} (${current}/${total})`;
|
|
109
|
+
}
|
|
@@ -1,39 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.deleteWebhookCommand = void 0;
|
|
4
|
-
const commander_1 = require("commander");
|
|
5
|
-
const plazbot_1 = require("plazbot");
|
|
6
|
-
const credentials_1 = require("../../utils/credentials");
|
|
7
|
-
const logger_1 = require("../../utils/logger");
|
|
8
|
-
exports.deleteWebhookCommand = new commander_1.Command('delete-webhook')
|
|
9
|
-
.description('Elimina un webhook registrado')
|
|
10
|
-
.argument('<number>', 'Número de WhatsApp (con código de país, ej: 51912345678)')
|
|
11
|
-
.option('--dev', 'Usar ambiente de desarrollo', false)
|
|
12
|
-
.action(async (number, options) => {
|
|
13
|
-
try {
|
|
14
|
-
// Obtener credenciales guardadas
|
|
15
|
-
const credentials = await (0, credentials_1.getStoredCredentials)();
|
|
16
|
-
const messageClient = new plazbot_1.Message({
|
|
17
|
-
workspaceId: credentials.workspace,
|
|
18
|
-
apiKey: credentials.apiKey,
|
|
19
|
-
zone: credentials.zone,
|
|
20
|
-
...(options.dev && { customUrl: "http://localhost:5090" })
|
|
21
|
-
});
|
|
22
|
-
logger_1.logger.info('\n🗑️ Eliminando webhook...');
|
|
23
|
-
logger_1.logger.info(`Número: ${number}`);
|
|
24
|
-
const response = await messageClient.deleteWebhook({
|
|
25
|
-
number
|
|
26
|
-
});
|
|
27
|
-
logger_1.logger.success('Webhook eliminado exitosamente');
|
|
28
|
-
logger_1.logger.info('\n📋 Detalles:');
|
|
29
|
-
logger_1.logger.info(JSON.stringify(response, null, 2));
|
|
30
|
-
if (options.dev) {
|
|
31
|
-
logger_1.logger.warning('\nAmbiente: desarrollo');
|
|
32
|
-
}
|
|
33
|
-
}
|
|
34
|
-
catch (error) {
|
|
35
|
-
const message = error instanceof Error ? error.message : 'Error desconocido al eliminar el webhook';
|
|
36
|
-
logger_1.logger.error(message);
|
|
37
|
-
process.exit(1);
|
|
38
|
-
}
|
|
39
|
-
});
|
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.messageCommands = void 0;
|
|
4
|
-
const commander_1 = require("commander");
|
|
5
|
-
const send_1 = require("./send");
|
|
6
|
-
const send_template_1 = require("./send-template");
|
|
7
|
-
const register_webhook_1 = require("./register-webhook");
|
|
8
|
-
const delete_webhook_1 = require("./delete-webhook");
|
|
9
|
-
exports.messageCommands = new commander_1.Command('message')
|
|
10
|
-
.description('Comandos relacionados con mensajes de WhatsApp')
|
|
11
|
-
.addCommand(send_1.sendMessageCommand)
|
|
12
|
-
.addCommand(send_template_1.sendTemplateCommand)
|
|
13
|
-
.addCommand(register_webhook_1.registerWebhookCommand)
|
|
14
|
-
.addCommand(delete_webhook_1.deleteWebhookCommand);
|
|
@@ -1,42 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.registerWebhookCommand = void 0;
|
|
4
|
-
const commander_1 = require("commander");
|
|
5
|
-
const plazbot_1 = require("plazbot");
|
|
6
|
-
const credentials_1 = require("../../utils/credentials");
|
|
7
|
-
const logger_1 = require("../../utils/logger");
|
|
8
|
-
exports.registerWebhookCommand = new commander_1.Command('register-webhook')
|
|
9
|
-
.description('Registra un webhook para recibir mensajes de WhatsApp')
|
|
10
|
-
.argument('<number>', 'Número de WhatsApp (con código de país, ej: 51912345678)')
|
|
11
|
-
.argument('<webhookUrl>', 'URL del webhook')
|
|
12
|
-
.option('--dev', 'Usar ambiente de desarrollo', false)
|
|
13
|
-
.action(async (number, webhookUrl, options) => {
|
|
14
|
-
try {
|
|
15
|
-
// Obtener credenciales guardadas
|
|
16
|
-
const credentials = await (0, credentials_1.getStoredCredentials)();
|
|
17
|
-
const messageClient = new plazbot_1.Message({
|
|
18
|
-
workspaceId: credentials.workspace,
|
|
19
|
-
apiKey: credentials.apiKey,
|
|
20
|
-
zone: credentials.zone,
|
|
21
|
-
...(options.dev && { customUrl: "http://localhost:5090" })
|
|
22
|
-
});
|
|
23
|
-
logger_1.logger.info('\n🔗 Registrando webhook...');
|
|
24
|
-
logger_1.logger.info(`Número: ${number}`);
|
|
25
|
-
logger_1.logger.info(`URL: ${webhookUrl}`);
|
|
26
|
-
const response = await messageClient.registerWebhook({
|
|
27
|
-
number,
|
|
28
|
-
webhookUrl
|
|
29
|
-
});
|
|
30
|
-
logger_1.logger.success('Webhook registrado exitosamente');
|
|
31
|
-
logger_1.logger.info('\n📋 Detalles:');
|
|
32
|
-
logger_1.logger.info(JSON.stringify(response, null, 2));
|
|
33
|
-
if (options.dev) {
|
|
34
|
-
logger_1.logger.warning('\nAmbiente: desarrollo');
|
|
35
|
-
}
|
|
36
|
-
}
|
|
37
|
-
catch (error) {
|
|
38
|
-
const message = error instanceof Error ? error.message : 'Error desconocido al registrar el webhook';
|
|
39
|
-
logger_1.logger.error(message);
|
|
40
|
-
process.exit(1);
|
|
41
|
-
}
|
|
42
|
-
});
|
|
@@ -1,42 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.sendTemplateCommand = void 0;
|
|
4
|
-
const commander_1 = require("commander");
|
|
5
|
-
const plazbot_1 = require("plazbot");
|
|
6
|
-
const credentials_1 = require("../../utils/credentials");
|
|
7
|
-
const logger_1 = require("../../utils/logger");
|
|
8
|
-
exports.sendTemplateCommand = new commander_1.Command('send-template')
|
|
9
|
-
.description('Envía una plantilla de WhatsApp')
|
|
10
|
-
.argument('<to>', 'Número de teléfono del destinatario (con código de país, ej: 51912345678)')
|
|
11
|
-
.argument('<template>', 'Nombre de la plantilla a enviar')
|
|
12
|
-
.option('--dev', 'Usar ambiente de desarrollo', false)
|
|
13
|
-
.action(async (to, template, options) => {
|
|
14
|
-
try {
|
|
15
|
-
// Obtener credenciales guardadas
|
|
16
|
-
const credentials = await (0, credentials_1.getStoredCredentials)();
|
|
17
|
-
const messageClient = new plazbot_1.Message({
|
|
18
|
-
workspaceId: credentials.workspace,
|
|
19
|
-
apiKey: credentials.apiKey,
|
|
20
|
-
zone: credentials.zone,
|
|
21
|
-
...(options.dev && { customUrl: "http://localhost:5090" })
|
|
22
|
-
});
|
|
23
|
-
logger_1.logger.info('\n📱 Enviando plantilla de WhatsApp...');
|
|
24
|
-
logger_1.logger.info(`A: ${to}`);
|
|
25
|
-
logger_1.logger.info(`Plantilla: ${template}`);
|
|
26
|
-
const response = await messageClient.onConversation({
|
|
27
|
-
to,
|
|
28
|
-
template
|
|
29
|
-
});
|
|
30
|
-
logger_1.logger.success('Plantilla enviada exitosamente');
|
|
31
|
-
logger_1.logger.info('\n📋 Detalles:');
|
|
32
|
-
logger_1.logger.info(JSON.stringify(response, null, 2));
|
|
33
|
-
if (options.dev) {
|
|
34
|
-
logger_1.logger.warning('\nAmbiente: desarrollo');
|
|
35
|
-
}
|
|
36
|
-
}
|
|
37
|
-
catch (error) {
|
|
38
|
-
const message = error instanceof Error ? error.message : 'Error desconocido al enviar la plantilla';
|
|
39
|
-
logger_1.logger.error(message);
|
|
40
|
-
process.exit(1);
|
|
41
|
-
}
|
|
42
|
-
});
|
|
@@ -1,42 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.sendMessageCommand = void 0;
|
|
4
|
-
const commander_1 = require("commander");
|
|
5
|
-
const plazbot_1 = require("plazbot");
|
|
6
|
-
const credentials_1 = require("../../utils/credentials");
|
|
7
|
-
const logger_1 = require("../../utils/logger");
|
|
8
|
-
exports.sendMessageCommand = new commander_1.Command('send-message')
|
|
9
|
-
.description('Envía un mensaje de WhatsApp')
|
|
10
|
-
.argument('<to>', 'Número de teléfono del destinatario (con código de país, ej: 51912345678)')
|
|
11
|
-
.argument('<message>', 'Mensaje a enviar')
|
|
12
|
-
.option('--dev', 'Usar ambiente de desarrollo', false)
|
|
13
|
-
.action(async (to, message, options) => {
|
|
14
|
-
try {
|
|
15
|
-
// Obtener credenciales guardadas
|
|
16
|
-
const credentials = await (0, credentials_1.getStoredCredentials)();
|
|
17
|
-
const messageClient = new plazbot_1.Message({
|
|
18
|
-
workspaceId: credentials.workspace,
|
|
19
|
-
apiKey: credentials.apiKey,
|
|
20
|
-
zone: credentials.zone,
|
|
21
|
-
...(options.dev && { customUrl: "http://localhost:5090" })
|
|
22
|
-
});
|
|
23
|
-
logger_1.logger.info('\n📱 Enviando mensaje de WhatsApp...');
|
|
24
|
-
logger_1.logger.info(`A: ${to}`);
|
|
25
|
-
logger_1.logger.info(`Mensaje: ${message}`);
|
|
26
|
-
const response = await messageClient.onWhatsappMessage({
|
|
27
|
-
message,
|
|
28
|
-
to
|
|
29
|
-
});
|
|
30
|
-
logger_1.logger.success('Mensaje enviado exitosamente');
|
|
31
|
-
logger_1.logger.info('\n📋 Detalles:');
|
|
32
|
-
logger_1.logger.info(JSON.stringify(response, null, 2));
|
|
33
|
-
if (options.dev) {
|
|
34
|
-
logger_1.logger.warning('\nAmbiente: desarrollo');
|
|
35
|
-
}
|
|
36
|
-
}
|
|
37
|
-
catch (error) {
|
|
38
|
-
const message = error instanceof Error ? error.message : 'Error desconocido al enviar el mensaje';
|
|
39
|
-
logger_1.logger.error(message);
|
|
40
|
-
process.exit(1);
|
|
41
|
-
}
|
|
42
|
-
});
|