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.dateProcessor = new DateProcessor();
|
||||||
this.userSessions = new Map(); // Armazena sessões de usuário
|
this.userSessions = new Map(); // Armazena sessões de usuário
|
||||||
this.suporteSessions = new Map(); // Armazena sessões de suporte em andamento
|
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');
|
logger.info('BotHandler inicializado');
|
||||||
console.log('🎯 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_')) {
|
} else if (data.startsWith('restart_onu_srv_')) {
|
||||||
console.log(`🔍 Condição restart_onu_srv_ atendida`);
|
console.log(`🔍 Condição restart_onu_srv_ atendida`);
|
||||||
await this.handleRestartOnuServicoCallback(callbackQuery, data);
|
await this.handleRestartOnuServicoCallback(callbackQuery, data);
|
||||||
} else if (data.startsWith('confirm_restart_onu_')) {
|
} else if (data.startsWith('confirm_rst_')) {
|
||||||
console.log(`🔍 Condição confirm_restart_onu_ atendida`);
|
console.log(`🔍 Condição confirm_rst_ atendida`);
|
||||||
await this.handleConfirmRestartOnuCallback(callbackQuery, data);
|
await this.handleConfirmRestartOnuCallback(callbackQuery, data);
|
||||||
} else if (data.startsWith('diag_servico_')) {
|
} else if (data.startsWith('diag_servico_')) {
|
||||||
console.log(`🔍 Condição diag_servico_ atendida`);
|
console.log(`🔍 Condição diag_servico_ atendida`);
|
||||||
@@ -8650,7 +8652,10 @@ Digite /help para ver todos os comandos disponíveis!
|
|||||||
servicos.forEach((s, i) => {
|
servicos.forEach((s, i) => {
|
||||||
const nome = s.descricao || s.nome || `Serviço ${i + 1}`;
|
const nome = s.descricao || s.nome || `Serviço ${i + 1}`;
|
||||||
const serial = s.serial || s.comodato_serial || s.mac || '';
|
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([{
|
keyboard.push([{
|
||||||
text: `🔄 ${nome.substring(0, 35)}`,
|
text: `🔄 ${nome.substring(0, 35)}`,
|
||||||
callback_data: `restart_onu_srv_${idCliente}_${s.id_servico || s.id}_${location}`
|
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, '\\_');
|
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,
|
await this.bot.sendMessage(chatId,
|
||||||
`⚠️ *Confirmar Reinicialização de ONU*\n\n` +
|
`⚠️ *Confirmar Reinicialização de ONU*\n\n` +
|
||||||
`📦 *Serviço:* ${nome}\n` +
|
`📦 *Serviço:* ${nome}\n` +
|
||||||
@@ -8693,7 +8702,7 @@ Digite /help para ver todos os comandos disponíveis!
|
|||||||
reply_markup: {
|
reply_markup: {
|
||||||
inline_keyboard: [
|
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' }
|
{ 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;
|
const chatId = callbackQuery.message.chat.id;
|
||||||
await this.bot.answerCallbackQuery(callbackQuery.id);
|
await this.bot.answerCallbackQuery(callbackQuery.id);
|
||||||
|
|
||||||
// Formato: confirm_restart_onu_SERIAL_BASE_LOCATION
|
// Formato: confirm_rst_ID
|
||||||
const rest = data.replace('confirm_restart_onu_', '');
|
const restartId = data.replace('confirm_rst_', '');
|
||||||
// Serial é o primeiro token (12 chars alfanuméricos)
|
const pending = this.pendingRestarts.get(restartId);
|
||||||
const serialMatch = rest.match(/^([A-Za-z0-9]+)_(.*)$/);
|
if (!pending) {
|
||||||
if (!serialMatch) {
|
await this.bot.sendMessage(chatId, '❌ Dados de reinicialização expirados. Tente novamente.');
|
||||||
await this.bot.sendMessage(chatId, '❌ Erro ao processar dados de reinicialização.');
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
this.pendingRestarts.delete(restartId);
|
||||||
|
|
||||||
const serial = serialMatch[1];
|
const { serial, base } = pending;
|
||||||
const remaining = serialMatch[2]; // BASE_LOCATION
|
|
||||||
const base = remaining; // usa o restante como base (pode conter location junto)
|
|
||||||
|
|
||||||
const oltHint = this._resolverOLTporBase(base);
|
const oltHint = this._resolverOLTporBase(base);
|
||||||
|
|
||||||
|
|||||||
Reference in new issue
Block a user