reiniciar: fix function
Signed-off-by: Rodrigo Martins <rodrigo@martinsevieira.adv.br>
This commit is contained in:
1 parent
6176a150e1
commit
3ec5ad73cb
1 file changed
+20
-13
+20
-13
@@ -20,6 +20,8 @@ class BotHandler {
|
||||
this.dateProcessor = new DateProcessor();
|
||||
this.userSessions = new Map(); // Armazena sessões de usuário
|
||||
this.suporteSessions = new Map(); // Armazena sessões de suporte em andamento
|
||||
this.pendingRestarts = new Map(); // Armazena dados de reinicialização pendentes
|
||||
this._restartIdCounter = 0;
|
||||
|
||||
logger.info('BotHandler inicializado');
|
||||
console.log('🎯 BotHandler inicializado');
|
||||
@@ -2146,8 +2148,8 @@ Digite /help para ver todos os comandos disponíveis!
|
||||
} else if (data.startsWith('restart_onu_srv_')) {
|
||||
console.log(`🔍 Condição restart_onu_srv_ atendida`);
|
||||
await this.handleRestartOnuServicoCallback(callbackQuery, data);
|
||||
} else if (data.startsWith('confirm_restart_onu_')) {
|
||||
console.log(`🔍 Condição confirm_restart_onu_ atendida`);
|
||||
} else if (data.startsWith('confirm_rst_')) {
|
||||
console.log(`🔍 Condição confirm_rst_ atendida`);
|
||||
await this.handleConfirmRestartOnuCallback(callbackQuery, data);
|
||||
} else if (data.startsWith('diag_servico_')) {
|
||||
console.log(`🔍 Condição diag_servico_ atendida`);
|
||||
@@ -8650,7 +8652,10 @@ Digite /help para ver todos os comandos disponíveis!
|
||||
servicos.forEach((s, i) => {
|
||||
const nome = s.descricao || s.nome || `Serviço ${i + 1}`;
|
||||
const serial = s.serial || s.comodato_serial || s.mac || '';
|
||||
message += `*${i + 1}.* ${nome}${serial ? ` — \`${serial}\`` : ''}\n`;
|
||||
const endereco = s.instalacao_endereco || '';
|
||||
message += `*${i + 1}.* ${nome}${serial ? ` — \`${serial}\`` : ''}`;
|
||||
if (endereco) message += `\n 📍 ${endereco}`;
|
||||
message += '\n';
|
||||
keyboard.push([{
|
||||
text: `🔄 ${nome.substring(0, 35)}`,
|
||||
callback_data: `restart_onu_srv_${idCliente}_${s.id_servico || s.id}_${location}`
|
||||
@@ -8681,6 +8686,10 @@ Digite /help para ver todos os comandos disponíveis!
|
||||
|
||||
const serialEscaped = serial.replace(/_/g, '\\_');
|
||||
|
||||
// Gerar ID curto para não estourar o limite de 64 bytes do callback_data
|
||||
const restartId = String(++this._restartIdCounter);
|
||||
this.pendingRestarts.set(restartId, { serial, base, location });
|
||||
|
||||
await this.bot.sendMessage(chatId,
|
||||
`⚠️ *Confirmar Reinicialização de ONU*\n\n` +
|
||||
`📦 *Serviço:* ${nome}\n` +
|
||||
@@ -8693,7 +8702,7 @@ Digite /help para ver todos os comandos disponíveis!
|
||||
reply_markup: {
|
||||
inline_keyboard: [
|
||||
[
|
||||
{ text: '✅ SIM, Reiniciar', callback_data: `confirm_restart_onu_${serial}_${base}_${location}` },
|
||||
{ text: '✅ SIM, Reiniciar', callback_data: `confirm_rst_${restartId}` },
|
||||
{ text: '❌ Cancelar', callback_data: 'cancel_action' }
|
||||
]
|
||||
]
|
||||
@@ -8753,18 +8762,16 @@ Digite /help para ver todos os comandos disponíveis!
|
||||
const chatId = callbackQuery.message.chat.id;
|
||||
await this.bot.answerCallbackQuery(callbackQuery.id);
|
||||
|
||||
// Formato: confirm_restart_onu_SERIAL_BASE_LOCATION
|
||||
const rest = data.replace('confirm_restart_onu_', '');
|
||||
// Serial é o primeiro token (12 chars alfanuméricos)
|
||||
const serialMatch = rest.match(/^([A-Za-z0-9]+)_(.*)$/);
|
||||
if (!serialMatch) {
|
||||
await this.bot.sendMessage(chatId, '❌ Erro ao processar dados de reinicialização.');
|
||||
// Formato: confirm_rst_ID
|
||||
const restartId = data.replace('confirm_rst_', '');
|
||||
const pending = this.pendingRestarts.get(restartId);
|
||||
if (!pending) {
|
||||
await this.bot.sendMessage(chatId, '❌ Dados de reinicialização expirados. Tente novamente.');
|
||||
return;
|
||||
}
|
||||
this.pendingRestarts.delete(restartId);
|
||||
|
||||
const serial = serialMatch[1];
|
||||
const remaining = serialMatch[2]; // BASE_LOCATION
|
||||
const base = remaining; // usa o restante como base (pode conter location junto)
|
||||
const { serial, base } = pending;
|
||||
|
||||
const oltHint = this._resolverOLTporBase(base);
|
||||
|
||||
|
||||
Reference in new issue
Block a user