fiberhome: add remove onu option

Signed-off-by: Rodrigo Bertoldo de Sousa Martins <rodrigo.sousa.577@gmail.com>
This commit is contained in:
rodrigo committed 2026-02-10 20:15:40 -03:00
1 parent e5f8bcf546
commit 41a8d1b6c5
3 files changed
+333

No files matched your search

+133
View File
@@ -186,6 +186,11 @@ class BotHandler {
await this.handleAdicionarOnuFiberhome(chatId, target, userId);
break;
case 'remover_onu_fiberhome':
console.log(`🗑️ Executando handleRemoverOnuFiberhome com target: ${target}`);
await this.handleRemoverOnuFiberhome(chatId, target, userId);
break;
case 'buscar_cliente':
console.log(`🔍 Executando handleBuscarCliente com target: ${target}`);
await this.handleBuscarCliente(chatId, target);
@@ -1267,6 +1272,54 @@ Digite /help para ver todos os comandos disponíveis!
}
}
/**
* Handler para remover ONU Fiberhome via TL1
*/
async handleRemoverOnuFiberhome(chatId, serialNumber, userId) {
try {
// Validar serial
if (!serialNumber || serialNumber.length !== 12) {
await this.bot.sendMessage(chatId,
'❌ Serial inválido. O serial deve conter 12 caracteres.\n\n' +
'Exemplo: `FHTT199cf3c8`'
);
return;
}
// Escapar caracteres especiais
const serialEscaped = serialNumber.replace(/_/g, '\\_');
// Solicitar confirmação
const keyboard = {
inline_keyboard: [
[
{ text: '✅ Sim, remover', callback_data: `confirm_remove_fh_${serialNumber}` },
{ text: '❌ Cancelar', callback_data: 'cancel_action' }
]
]
};
await this.bot.sendMessage(chatId,
`🗑️ *Remover ONU Fiberhome*\n\n` +
`📱 *Serial:* ${serialEscaped}\n\n` +
`⚠️ Esta ação irá remover a ONU e todas as suas configurações.\n\n` +
`Deseja confirmar a remoção?`,
{
reply_markup: keyboard,
parse_mode: 'Markdown'
}
);
} catch (error) {
console.error('❌ Erro ao preparar remoção de ONU Fiberhome:', error);
await this.bot.sendMessage(chatId,
`❌ *Erro ao preparar remoção*\n\n` +
`⚠️ ${error.message}`,
{ parse_mode: 'Markdown' }
);
}
}
/**
* Comando não reconhecido
*/
@@ -1306,6 +1359,14 @@ Digite /help para ver todos os comandos disponíveis!
if (data.startsWith('cmd_')) {
console.log(`🔍 Condição cmd_ atendida`);
await this.handleCommandCallback(callbackQuery, data);
} else if (data.startsWith('confirm_remove_fh_')) {
console.log(`🔍 Chamando handleConfirmRemoveFiberhomeCallback`);
try {
await this.handleConfirmRemoveFiberhomeCallback(callbackQuery, data);
} catch (confirmError) {
console.error(`❌ Erro em handleConfirmRemoveFiberhomeCallback:`, confirmError);
await this.bot.answerCallbackQuery(callbackQuery.id, 'Erro na confirmação');
}
} else if (data.startsWith('confirm_remove_')) {
console.log(`🔍 Chamando handleConfirmRemoveCallback`);
try {
@@ -2428,6 +2489,78 @@ Digite /help para ver todos os comandos disponíveis!
}
}
/**
* Handle callback para confirmar remoção de ONU Fiberhome via TL1
*/
async handleConfirmRemoveFiberhomeCallback(callbackQuery, data) {
const chatId = callbackQuery.message.chat.id;
console.log(`🔍 handleConfirmRemoveFiberhomeCallback chamado com data: ${data}`);
// Formato: confirm_remove_fh_SERIAL
const serialNumber = data.replace('confirm_remove_fh_', '').toUpperCase();
console.log(`🔍 Serial a remover: ${serialNumber}`);
await this.bot.answerCallbackQuery(callbackQuery.id);
// Escapar caracteres especiais
const serialEscaped = serialNumber.replace(/_/g, '\\_');
await this.bot.editMessageText(
`🗑️ *Removendo ONU Fiberhome...*\n\n` +
`📱 *Serial:* ${serialEscaped}\n\n` +
`⏳ Aguarde...`,
{
chat_id: chatId,
message_id: callbackQuery.message.message_id,
parse_mode: 'Markdown'
}
);
try {
// Executar comando TL1 de remoção
const resultado = await this.fiberhomeTL1.removerOnuFiberhome(serialNumber);
if (resultado.success) {
await this.bot.editMessageText(
`✅ *ONU Fiberhome Removida com Sucesso!*\n\n` +
`📱 *Serial:* ${serialEscaped}\n` +
`🏢 *OLT:* ${resultado.details.olt.replace(/_/g, '\\_')}\n` +
`📡 *Porta:* ${resultado.details.porta}\n\n` +
`🔄 A ONU foi removida do sistema.`,
{
chat_id: chatId,
message_id: callbackQuery.message.message_id,
parse_mode: 'Markdown'
}
);
} else {
await this.bot.editMessageText(
`❌ *Erro na Remoção*\n\n` +
`📱 *Serial:* ${serialEscaped}\n\n` +
`⚠️ *Erro:* ${resultado.error}\n\n` +
`🔄 Verifique o status da ONU ou tente novamente`,
{
chat_id: chatId,
message_id: callbackQuery.message.message_id,
parse_mode: 'Markdown'
}
);
}
} catch (error) {
console.error('❌ Erro ao remover ONU Fiberhome:', error);
await this.bot.editMessageText(
`❌ *Erro Interno*\n\n` +
`📱 *Serial:* ${serialEscaped}\n\n` +
`⚠️ ${error.message}`,
{
chat_id: chatId,
message_id: callbackQuery.message.message_id,
parse_mode: 'Markdown'
}
);
}
}
/**
* Handle callback para iniciar processo de adição de ONU
*/