fiberhome: add prelimunary add ONU support

Signed-off-by: Rodrigo Bertoldo de Sousa Martins <rodrigo.sousa.577@gmail.com>
This commit is contained in:
rodrigo committed 2026-02-10 19:11:25 -03:00
1 parent ee22ecf693
commit dee32518aa
1 file changed
+66 -60
+66 -60
View File
@@ -1081,6 +1081,8 @@ Digite /help para ver todos os comandos disponíveis!
return; return;
} }
console.log(`📝 Criando sessão para usuário ${userId}, serial: ${serialNumber}`);
// Criar sessão para coletar informações // Criar sessão para coletar informações
this.userSessions.set(userId, { this.userSessions.set(userId, {
action: 'adicionar_onu_fiberhome_step1', action: 'adicionar_onu_fiberhome_step1',
@@ -1088,6 +1090,8 @@ Digite /help para ver todos os comandos disponíveis!
timestamp: Date.now() timestamp: Date.now()
}); });
console.log(`✅ Sessão criada. Sessões ativas:`, this.userSessions.size);
// Perguntar o alias/nome do usuário // Perguntar o alias/nome do usuário
await this.bot.sendMessage(chatId, await this.bot.sendMessage(chatId,
`➕ **Adicionar ONU Fiberhome**\n\n` + `➕ **Adicionar ONU Fiberhome**\n\n` +
@@ -1103,57 +1107,76 @@ Digite /help para ver todos os comandos disponíveis!
*/ */
async handleUserSessionInput(chatId, text, userId, session) { async handleUserSessionInput(chatId, text, userId, session) {
try { try {
switch (session.action) { console.log(`🔄 Processando input de sessão. Action: ${session.action}, Type: ${session.type}, Text: ${text}`);
case 'adicionar_onu_fiberhome_step1':
// Recebeu o nome do usuário, agora perguntar pelo tipo da ONU // Verificar se é sessão baseada em action (Fiberhome ONU)
session.usuario = text.trim(); if (session.action) {
session.action = 'adicionar_onu_fiberhome_step2'; switch (session.action) {
this.userSessions.set(userId, session); case 'adicionar_onu_fiberhome_step1':
// Recebeu o nome do usuário, agora perguntar pelo tipo da ONU
session.usuario = text.trim();
session.action = 'adicionar_onu_fiberhome_step2';
this.userSessions.set(userId, session);
const keyboard = { const keyboard = {
inline_keyboard: [ inline_keyboard: [
[{ text: '🔌 AN5506-02-B (2 portas)', callback_data: 'fh_onu_type_AN5506-02-B' }], [{ text: '🔌 AN5506-02-B (2 portas)', callback_data: 'fh_onu_type_AN5506-02-B' }],
[{ text: '🔌 AN5506-01-A (1 porta)', callback_data: 'fh_onu_type_AN5506-01-A' }], [{ text: '🔌 AN5506-01-A (1 porta)', callback_data: 'fh_onu_type_AN5506-01-A' }],
[{ text: '❌ Cancelar', callback_data: 'cancel_action' }] [{ text: '❌ Cancelar', callback_data: 'cancel_action' }]
] ]
}; };
await this.bot.sendMessage(chatId, await this.bot.sendMessage(chatId,
`📡 **Porta PON:** ${session.portAlias}\n\n` + `👤 **Usuário:** ${session.usuario}\n\n` +
'🔌 Selecione o **tipo da ONU**:', '🔌 Selecione o **tipo da ONU**:',
{ reply_markup: keyboard, parse_mode: 'Markdown' } { reply_markup: keyboard, parse_mode: 'Markdown' }
); );
break; return;
case 'adicionar_onu_fiberhome_step5': case 'adicionar_onu_fiberhome_step3':
// Recebeu confirmação de VLAN customizada // Recebeu confirmação de VLAN customizada
const vlanInput = text.trim(); const vlanInput = text.trim();
if (vlanInput && !isNaN(vlanInput)) { if (vlanInput && !isNaN(vlanInput)) {
const vlan = parseInt(vlanInput); const vlan = parseInt(vlanInput);
if (vlan >= 1 && vlan <= 4094) { if (vlan >= 1 && vlan <= 4094) {
session.vlan = vlan; session.vlan = vlan;
} else {
await this.bot.sendMessage(chatId, '❌ VLAN inválida. Usando VLAN padrão 1002.');
session.vlan = 1002;
}
} else { } else {
await this.bot.sendMessage(chatId, '❌ VLAN inválida. Usando VLAN padrão 1002.');
session.vlan = 1002; session.vlan = 1002;
} }
} else {
session.vlan = 1002;
}
// Limpar sessão // Limpar sessão
this.userSessions.delete(userId); this.userSessions.delete(userId);
// Executar adição da ONU // Executar adição da ONU
await this.executarAdicaoOnuFiberhome(chatId, session); await this.executarAdicaoOnuFiberhome(chatId, session);
break; return;
}
default:
// Sessão desconhecida, limpar
this.userSessions.delete(userId);
await this.bot.sendMessage(chatId, '❌ Sessão expirada. Por favor, comece novamente.');
break;
} }
// Verificar se é sessão baseada em type (outros fluxos)
if (session.type) {
switch (session.type) {
case 'waiting_custom_command':
await this.executeCustomCommand(chatId, session.connectionId, text);
this.userSessions.delete(userId);
return;
case 'waiting_username_disconnect':
await this.handleDisconnectUser(chatId, text.trim());
this.userSessions.delete(userId);
return;
}
}
// Estado desconhecido
console.log(`❓ Estado de sessão desconhecido: action=${session.action}, type=${session.type}`);
this.userSessions.delete(userId);
await this.bot.sendMessage(chatId, '❓ Estado de sessão desconhecido. Tente novamente.');
} catch (error) { } catch (error) {
console.error('❌ Erro ao processar input da sessão:', error); console.error('❌ Erro ao processar input da sessão:', error);
this.userSessions.delete(userId); this.userSessions.delete(userId);
@@ -1548,25 +1571,8 @@ Digite /help para ver todos os comandos disponíveis!
} }
/** /**
* Lida com input de usuário durante sessões específicas * MÉTODO REMOVIDO - handleUserSessionInput duplicado foi mesclado acima
*/ */
async handleUserSessionInput(chatId, text, userId, session) {
switch (session.type) {
case 'waiting_custom_command':
await this.executeCustomCommand(chatId, session.connectionId, text);
break;
case 'waiting_username_disconnect':
await this.handleDisconnectUser(chatId, text.trim());
break;
default:
await this.bot.sendMessage(chatId, '❓ Estado de sessão desconhecido. Tente novamente.');
}
// Limpar sessão
this.userSessions.delete(userId);
}
/** /**
* Executa comando personalizado em uma conexão SSH * Executa comando personalizado em uma conexão SSH