fiberhome: add prelimunary add ONU support
Signed-off-by: Rodrigo Bertoldo de Sousa Martins <rodrigo.sousa.577@gmail.com>
This commit is contained in:
1 parent
ee22ecf693
commit
669d27e2a8
1 file changed
+70
-65
+70
-65
@@ -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
|
|
||||||
session.usuario = text.trim();
|
|
||||||
session.action = 'adicionar_onu_fiberhome_step2';
|
|
||||||
this.userSessions.set(userId, session);
|
|
||||||
|
|
||||||
const keyboard = {
|
// Verificar se é sessão baseada em action (Fiberhome ONU)
|
||||||
inline_keyboard: [
|
if (session.action) {
|
||||||
[{ text: '🔌 AN5506-02-B (2 portas)', callback_data: 'fh_onu_type_AN5506-02-B' }],
|
switch (session.action) {
|
||||||
[{ text: '🔌 AN5506-01-A (1 porta)', callback_data: 'fh_onu_type_AN5506-01-A' }],
|
case 'adicionar_onu_fiberhome_step1':
|
||||||
[{ text: '❌ Cancelar', callback_data: 'cancel_action' }]
|
// 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);
|
||||||
|
|
||||||
await this.bot.sendMessage(chatId,
|
const keyboard = {
|
||||||
`📡 **Porta PON:** ${session.portAlias}\n\n` +
|
inline_keyboard: [
|
||||||
'🔌 Selecione o **tipo da ONU**:',
|
[{ text: '🔌 AN5506-02-B (2 portas)', callback_data: 'fh_onu_type_AN5506-02-B' }],
|
||||||
{ reply_markup: keyboard, parse_mode: 'Markdown' }
|
[{ text: '🔌 AN5506-01-A (1 porta)', callback_data: 'fh_onu_type_AN5506-01-A' }],
|
||||||
);
|
[{ text: '❌ Cancelar', callback_data: 'cancel_action' }]
|
||||||
break;
|
]
|
||||||
|
};
|
||||||
|
|
||||||
case 'adicionar_onu_fiberhome_step5':
|
await this.bot.sendMessage(chatId,
|
||||||
// Recebeu confirmação de VLAN customizada
|
`👤 **Usuário:** ${session.usuario}\n\n` +
|
||||||
const vlanInput = text.trim();
|
'🔌 Selecione o **tipo da ONU**:',
|
||||||
|
{ reply_markup: keyboard, parse_mode: 'Markdown' }
|
||||||
|
);
|
||||||
|
return;
|
||||||
|
|
||||||
if (vlanInput && !isNaN(vlanInput)) {
|
case 'adicionar_onu_fiberhome_step3':
|
||||||
const vlan = parseInt(vlanInput);
|
// Recebeu confirmação de VLAN customizada
|
||||||
if (vlan >= 1 && vlan <= 4094) {
|
const vlanInput = text.trim();
|
||||||
session.vlan = vlan;
|
|
||||||
|
if (vlanInput && !isNaN(vlanInput)) {
|
||||||
|
const vlan = parseInt(vlanInput);
|
||||||
|
if (vlan >= 1 && vlan <= 4094) {
|
||||||
|
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
|
||||||
@@ -2639,7 +2645,7 @@ Digite /help para ver todos os comandos disponíveis!
|
|||||||
|
|
||||||
// Recuperar sessão
|
// Recuperar sessão
|
||||||
const session = this.userSessions.get(userId);
|
const session = this.userSessions.get(userId);
|
||||||
if (!session || session.action !== 'adicionar_onu_fiberhome_step4') {
|
if (!session || session.action !== 'adicionar_onu_fiberhome_step2') {
|
||||||
await this.bot.answerCallbackQuery(callbackQuery.id, '❌ Sessão expirada');
|
await this.bot.answerCallbackQuery(callbackQuery.id, '❌ Sessão expirada');
|
||||||
await this.bot.sendMessage(chatId, '❌ Sessão expirada. Por favor, comece novamente.');
|
await this.bot.sendMessage(chatId, '❌ Sessão expirada. Por favor, comece novamente.');
|
||||||
this.userSessions.delete(userId);
|
this.userSessions.delete(userId);
|
||||||
@@ -2647,6 +2653,8 @@ Digite /help para ver todos os comandos disponíveis!
|
|||||||
}
|
}
|
||||||
|
|
||||||
session.onuType = onuType;
|
session.onuType = onuType;
|
||||||
|
session.action = 'adicionar_onu_fiberhome_step3';
|
||||||
|
this.userSessions.set(userId, session);
|
||||||
|
|
||||||
await this.bot.answerCallbackQuery(callbackQuery.id);
|
await this.bot.answerCallbackQuery(callbackQuery.id);
|
||||||
|
|
||||||
@@ -2681,7 +2689,7 @@ Digite /help para ver todos os comandos disponíveis!
|
|||||||
|
|
||||||
// Recuperar sessão
|
// Recuperar sessão
|
||||||
const session = this.userSessions.get(userId);
|
const session = this.userSessions.get(userId);
|
||||||
if (!session || session.action !== 'adicionar_onu_fiberhome_step2') {
|
if (!session || session.action !== 'adicionar_onu_fiberhome_step3') {
|
||||||
await this.bot.answerCallbackQuery(callbackQuery.id, '❌ Sessão expirada');
|
await this.bot.answerCallbackQuery(callbackQuery.id, '❌ Sessão expirada');
|
||||||
await this.bot.sendMessage(chatId, '❌ Sessão expirada. Por favor, comece novamente.');
|
await this.bot.sendMessage(chatId, '❌ Sessão expirada. Por favor, comece novamente.');
|
||||||
this.userSessions.delete(userId);
|
this.userSessions.delete(userId);
|
||||||
@@ -2701,10 +2709,7 @@ Digite /help para ver todos os comandos disponíveis!
|
|||||||
await this.executarAdicaoOnuFiberhome(chatId, session);
|
await this.executarAdicaoOnuFiberhome(chatId, session);
|
||||||
|
|
||||||
} else if (data === 'fh_vlan_custom') {
|
} else if (data === 'fh_vlan_custom') {
|
||||||
// Pedir VLAN customizada
|
// Pedir VLAN customizada - manter sessão no step3 para receber input do usuário
|
||||||
session.action = 'adicionar_onu_fiberhome_step3';
|
|
||||||
this.userSessions.set(userId, session);
|
|
||||||
|
|
||||||
await this.bot.editMessageText(
|
await this.bot.editMessageText(
|
||||||
`🏷️ **VLAN Customizada**\n\n` +
|
`🏷️ **VLAN Customizada**\n\n` +
|
||||||
`Digite o número da VLAN que deseja usar (1-4094):`,
|
`Digite o número da VLAN que deseja usar (1-4094):`,
|
||||||
|
|||||||
Reference in new issue
Block a user