plazbot-cli 0.2.24 → 0.2.26
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.
|
@@ -74,23 +74,59 @@ exports.whatsappConnectCommand = new commander_1.Command('connect')
|
|
|
74
74
|
});
|
|
75
75
|
console.log();
|
|
76
76
|
}
|
|
77
|
-
//
|
|
78
|
-
const
|
|
79
|
-
const
|
|
80
|
-
|
|
81
|
-
|
|
77
|
+
// Obtener o generar link de onboarding (mismo flujo que Plazbot Front)
|
|
78
|
+
const ONBOARDING_SHORT_DOMAIN = 'https://co.plzb.link';
|
|
79
|
+
const spinner = (0, ora_1.default)({ text: chalk_1.default.gray('Obteniendo link de conexion...'), spinner: 'dots', color: 'green' }).start();
|
|
80
|
+
let linkData = null;
|
|
81
|
+
// 1. Intentar obtener link existente (GET)
|
|
82
|
+
try {
|
|
83
|
+
const getRes = await axios_1.default.get(`${baseUrl}/api/workspace/${credentials.workspace}/onboarding-link`, { headers, params: { type: channelType } });
|
|
84
|
+
linkData = getRes.data?.data ?? null;
|
|
85
|
+
}
|
|
86
|
+
catch {
|
|
87
|
+
linkData = null;
|
|
88
|
+
}
|
|
89
|
+
// 2. Si existe pero esta expirado, regenerar
|
|
90
|
+
if (linkData?.expiresAt && new Date(linkData.expiresAt) < new Date()) {
|
|
91
|
+
try {
|
|
92
|
+
const regenRes = await axios_1.default.post(`${baseUrl}/api/workspace/${credentials.workspace}/onboarding-link/regenerate`, { type: channelType }, { headers });
|
|
93
|
+
linkData = regenRes.data?.data ?? null;
|
|
94
|
+
}
|
|
95
|
+
catch {
|
|
96
|
+
linkData = null;
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
// 3. Si no existe, generar uno nuevo (POST)
|
|
100
|
+
if (!linkData?.token) {
|
|
101
|
+
try {
|
|
102
|
+
const createRes = await axios_1.default.post(`${baseUrl}/api/workspace/${credentials.workspace}/onboarding-link`, { type: channelType }, { headers });
|
|
103
|
+
linkData = createRes.data?.data ?? null;
|
|
104
|
+
}
|
|
105
|
+
catch {
|
|
106
|
+
linkData = null;
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
if (!linkData?.token) {
|
|
110
|
+
spinner.fail(chalk_1.default.hex('#EF5350')('No se pudo obtener el link de conexion'));
|
|
82
111
|
process.exit(1);
|
|
83
112
|
}
|
|
84
|
-
const shortUrl =
|
|
113
|
+
const shortUrl = `${ONBOARDING_SHORT_DOMAIN}/${linkData.token}`;
|
|
114
|
+
const expiresAt = linkData.expiresAt ? new Date(linkData.expiresAt).toLocaleDateString('es-ES', { day: 'numeric', month: 'long', year: 'numeric' }) : '';
|
|
85
115
|
spinner.stop();
|
|
86
116
|
// Mostrar link
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
console.log(
|
|
91
|
-
console.log(
|
|
92
|
-
console.log(
|
|
93
|
-
console.log(chalk_1.default.hex('#
|
|
117
|
+
const W = 54;
|
|
118
|
+
const pad = (text) => text + ' '.repeat(Math.max(0, W - text.length));
|
|
119
|
+
const border = chalk_1.default.hex('#25D366');
|
|
120
|
+
console.log(border(' ┌' + '─'.repeat(W) + '┐'));
|
|
121
|
+
console.log(border(' │') + chalk_1.default.bold(pad(' Abre este link en tu navegador:')) + border('│'));
|
|
122
|
+
console.log(border(' │') + ' '.repeat(W) + border('│'));
|
|
123
|
+
console.log(border(' │') + chalk_1.default.hex('#22d3ee')(pad(` ${shortUrl}`)) + border('│'));
|
|
124
|
+
console.log(border(' │') + ' '.repeat(W) + border('│'));
|
|
125
|
+
console.log(border(' │') + chalk_1.default.gray(pad(' Escanea el codigo QR desde tu WhatsApp')) + border('│'));
|
|
126
|
+
if (expiresAt) {
|
|
127
|
+
console.log(border(' │') + chalk_1.default.gray(pad(` Expira: ${expiresAt}`)) + border('│'));
|
|
128
|
+
}
|
|
129
|
+
console.log(border(' └' + '─'.repeat(W) + '┘'));
|
|
94
130
|
console.log();
|
|
95
131
|
// Guardar IDs actuales para detectar nuevos
|
|
96
132
|
const prevIds = new Set(allIntegrations.map((i) => i.id));
|
package/package.json
CHANGED
|
@@ -79,31 +79,75 @@ export const whatsappConnectCommand = new Command('connect')
|
|
|
79
79
|
console.log();
|
|
80
80
|
}
|
|
81
81
|
|
|
82
|
-
//
|
|
83
|
-
const
|
|
82
|
+
// Obtener o generar link de onboarding (mismo flujo que Plazbot Front)
|
|
83
|
+
const ONBOARDING_SHORT_DOMAIN = 'https://co.plzb.link';
|
|
84
|
+
const spinner = ora({ text: chalk.gray('Obteniendo link de conexion...'), spinner: 'dots', color: 'green' }).start();
|
|
85
|
+
|
|
86
|
+
let linkData: any = null;
|
|
87
|
+
|
|
88
|
+
// 1. Intentar obtener link existente (GET)
|
|
89
|
+
try {
|
|
90
|
+
const getRes = await axios.get(
|
|
91
|
+
`${baseUrl}/api/workspace/${credentials.workspace}/onboarding-link`,
|
|
92
|
+
{ headers, params: { type: channelType } }
|
|
93
|
+
);
|
|
94
|
+
linkData = getRes.data?.data ?? null;
|
|
95
|
+
} catch {
|
|
96
|
+
linkData = null;
|
|
97
|
+
}
|
|
84
98
|
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
{
|
|
88
|
-
|
|
89
|
-
|
|
99
|
+
// 2. Si existe pero esta expirado, regenerar
|
|
100
|
+
if (linkData?.expiresAt && new Date(linkData.expiresAt) < new Date()) {
|
|
101
|
+
try {
|
|
102
|
+
const regenRes = await axios.post(
|
|
103
|
+
`${baseUrl}/api/workspace/${credentials.workspace}/onboarding-link/regenerate`,
|
|
104
|
+
{ type: channelType },
|
|
105
|
+
{ headers }
|
|
106
|
+
);
|
|
107
|
+
linkData = regenRes.data?.data ?? null;
|
|
108
|
+
} catch {
|
|
109
|
+
linkData = null;
|
|
110
|
+
}
|
|
111
|
+
}
|
|
90
112
|
|
|
91
|
-
|
|
92
|
-
|
|
113
|
+
// 3. Si no existe, generar uno nuevo (POST)
|
|
114
|
+
if (!linkData?.token) {
|
|
115
|
+
try {
|
|
116
|
+
const createRes = await axios.post(
|
|
117
|
+
`${baseUrl}/api/workspace/${credentials.workspace}/onboarding-link`,
|
|
118
|
+
{ type: channelType },
|
|
119
|
+
{ headers }
|
|
120
|
+
);
|
|
121
|
+
linkData = createRes.data?.data ?? null;
|
|
122
|
+
} catch {
|
|
123
|
+
linkData = null;
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
if (!linkData?.token) {
|
|
128
|
+
spinner.fail(chalk.hex('#EF5350')('No se pudo obtener el link de conexion'));
|
|
93
129
|
process.exit(1);
|
|
94
130
|
}
|
|
95
131
|
|
|
96
|
-
const shortUrl =
|
|
132
|
+
const shortUrl = `${ONBOARDING_SHORT_DOMAIN}/${linkData.token}`;
|
|
133
|
+
const expiresAt = linkData.expiresAt ? new Date(linkData.expiresAt).toLocaleDateString('es-ES', { day: 'numeric', month: 'long', year: 'numeric' }) : '';
|
|
97
134
|
spinner.stop();
|
|
98
135
|
|
|
99
136
|
// Mostrar link
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
console.log(
|
|
105
|
-
console.log(
|
|
106
|
-
console.log(
|
|
137
|
+
const W = 54;
|
|
138
|
+
const pad = (text: string) => text + ' '.repeat(Math.max(0, W - text.length));
|
|
139
|
+
const border = chalk.hex('#25D366');
|
|
140
|
+
|
|
141
|
+
console.log(border(' ┌' + '─'.repeat(W) + '┐'));
|
|
142
|
+
console.log(border(' │') + chalk.bold(pad(' Abre este link en tu navegador:')) + border('│'));
|
|
143
|
+
console.log(border(' │') + ' '.repeat(W) + border('│'));
|
|
144
|
+
console.log(border(' │') + chalk.hex('#22d3ee')(pad(` ${shortUrl}`)) + border('│'));
|
|
145
|
+
console.log(border(' │') + ' '.repeat(W) + border('│'));
|
|
146
|
+
console.log(border(' │') + chalk.gray(pad(' Escanea el codigo QR desde tu WhatsApp')) + border('│'));
|
|
147
|
+
if (expiresAt) {
|
|
148
|
+
console.log(border(' │') + chalk.gray(pad(` Expira: ${expiresAt}`)) + border('│'));
|
|
149
|
+
}
|
|
150
|
+
console.log(border(' └' + '─'.repeat(W) + '┘'));
|
|
107
151
|
console.log();
|
|
108
152
|
|
|
109
153
|
// Guardar IDs actuales para detectar nuevos
|