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
600555596d
commit
ee22ecf693
4 files changed
+724
No files matched your search
@@ -92,6 +92,7 @@ class BotHandler {
|
||||
*/
|
||||
async executeAction(chatId, intent, user) {
|
||||
const { action, target, confidence, type } = intent;
|
||||
const userId = user.id; // Extrair userId do objeto user
|
||||
|
||||
// Se a confiança é muito baixa, pedir esclarecimento
|
||||
if (confidence < 0.3 && action) {
|
||||
@@ -178,6 +179,11 @@ class BotHandler {
|
||||
await this.handleAdicionarOnuVlan(chatId, target, intent.vlanId);
|
||||
break;
|
||||
|
||||
case 'adicionar_onu_fiberhome':
|
||||
console.log(`➕ Executando handleAdicionarOnuFiberhome com target: ${target}`);
|
||||
await this.handleAdicionarOnuFiberhome(chatId, target, userId);
|
||||
break;
|
||||
|
||||
case 'buscar_cliente':
|
||||
console.log(`🔍 Executando handleBuscarCliente com target: ${target}`);
|
||||
await this.handleBuscarCliente(chatId, target);
|
||||
@@ -314,6 +320,7 @@ Digite /help para ver todos os comandos disponíveis!
|
||||
📡 **OLT/ONU:**
|
||||
• "ver sinal DACM91569513"
|
||||
• "adicionar onu SERIAL"
|
||||
• "adicionar onu fiberhome SERIAL"
|
||||
• "remover onu SERIAL"
|
||||
|
||||
� **JUNIPER:**
|
||||
@@ -411,6 +418,20 @@ Digite /help para ver todos os comandos disponíveis!
|
||||
• "add onu vlan 700 ABCD12345678"
|
||||
• "adicionar vlan 603 SERIAL_NUMBER"
|
||||
|
||||
**➕ ADICIONAR ONU FIBERHOME VIA TL1:**
|
||||
• "adicionar onu fiberhome FHTT12345678"
|
||||
• "fiberhome onu FHTT12345678"
|
||||
• Processo interativo com:
|
||||
- Nome/alias do usuário
|
||||
- Nome da OLT
|
||||
- Porta PON (ex: 7-1)
|
||||
- Tipo da ONU (AN5506-02-B ou AN5506-01-A)
|
||||
- VLAN (padrão: 1002)
|
||||
• Configura automaticamente:
|
||||
- WAN Services
|
||||
- Login Web (admin/clicknet10)
|
||||
- Reinicia a ONU
|
||||
|
||||
**🗑️ REMOVER ONU:**
|
||||
• "remover onu DACM91569513"
|
||||
• "deletar ABCD12345678"
|
||||
@@ -1047,6 +1068,156 @@ Digite /help para ver todos os comandos disponíveis!
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Comando para adicionar ONU Fiberhome via TL1
|
||||
*/
|
||||
async handleAdicionarOnuFiberhome(chatId, serialNumber, userId) {
|
||||
if (!serialNumber) {
|
||||
await this.bot.sendMessage(chatId,
|
||||
'❌ Por favor, informe o serial da ONU Fiberhome.\n\n' +
|
||||
'Exemplo: `adicionar onu fiberhome FHTT12345678`',
|
||||
{ parse_mode: 'Markdown' }
|
||||
);
|
||||
return;
|
||||
}
|
||||
|
||||
// Criar sessão para coletar informações
|
||||
this.userSessions.set(userId, {
|
||||
action: 'adicionar_onu_fiberhome_step1',
|
||||
serial: serialNumber,
|
||||
timestamp: Date.now()
|
||||
});
|
||||
|
||||
// Perguntar o alias/nome do usuário
|
||||
await this.bot.sendMessage(chatId,
|
||||
`➕ **Adicionar ONU Fiberhome**\n\n` +
|
||||
`📱 **Serial:** ${serialNumber}\n` +
|
||||
`🔍 A porta PON será descoberta automaticamente\n\n` +
|
||||
'👤 Digite o **nome/alias** do usuário:',
|
||||
{ parse_mode: 'Markdown' }
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Processar input do usuário durante sessões
|
||||
*/
|
||||
async handleUserSessionInput(chatId, text, userId, session) {
|
||||
try {
|
||||
switch (session.action) {
|
||||
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 = {
|
||||
inline_keyboard: [
|
||||
[{ 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: '❌ Cancelar', callback_data: 'cancel_action' }]
|
||||
]
|
||||
};
|
||||
|
||||
await this.bot.sendMessage(chatId,
|
||||
`📡 **Porta PON:** ${session.portAlias}\n\n` +
|
||||
'🔌 Selecione o **tipo da ONU**:',
|
||||
{ reply_markup: keyboard, parse_mode: 'Markdown' }
|
||||
);
|
||||
break;
|
||||
|
||||
case 'adicionar_onu_fiberhome_step5':
|
||||
// Recebeu confirmação de VLAN customizada
|
||||
const vlanInput = text.trim();
|
||||
|
||||
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 {
|
||||
session.vlan = 1002;
|
||||
}
|
||||
|
||||
// Limpar sessão
|
||||
this.userSessions.delete(userId);
|
||||
|
||||
// Executar adição da ONU
|
||||
await this.executarAdicaoOnuFiberhome(chatId, session);
|
||||
break;
|
||||
|
||||
default:
|
||||
// Sessão desconhecida, limpar
|
||||
this.userSessions.delete(userId);
|
||||
await this.bot.sendMessage(chatId, '❌ Sessão expirada. Por favor, comece novamente.');
|
||||
break;
|
||||
}
|
||||
} catch (error) {
|
||||
console.error('❌ Erro ao processar input da sessão:', error);
|
||||
this.userSessions.delete(userId);
|
||||
await this.bot.sendMessage(chatId, '❌ Erro ao processar sua resposta. Tente novamente.');
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Executar adição da ONU Fiberhome
|
||||
*/
|
||||
async executarAdicaoOnuFiberhome(chatId, session) {
|
||||
try {
|
||||
const { serial, usuario, vlan, onuType } = session;
|
||||
|
||||
await this.bot.sendMessage(chatId,
|
||||
`⏳ Adicionando ONU Fiberhome...\n\n` +
|
||||
`🔍 Descobrindo porta PON automaticamente...\n` +
|
||||
`👤 **Usuário:** ${usuario}\n` +
|
||||
`📱 **Serial:** ${serial}\n` +
|
||||
`🔌 **Tipo:** ${onuType}\n` +
|
||||
`🏷️ **VLAN:** ${vlan}`,
|
||||
{ parse_mode: 'Markdown' }
|
||||
);
|
||||
|
||||
// Executar comando TL1 via Fiberhome Manager
|
||||
const resultado = await this.fiberhome.adicionarOnuFiberhome(
|
||||
serial,
|
||||
usuario,
|
||||
vlan,
|
||||
onuType
|
||||
);
|
||||
|
||||
if (resultado.success) {
|
||||
await this.bot.sendMessage(chatId,
|
||||
`✅ **ONU Fiberhome Adicionada com Sucesso!**\n\n` +
|
||||
`👤 **Usuário:** ${usuario}\n` +
|
||||
`🏢 **OLT:** ${resultado.details.olt}\n` +
|
||||
`📡 **Porta descoberta:** Slot ${resultado.details.slot}, PON ${resultado.details.ponPort}\n` +
|
||||
`📱 **Serial:** ${serial}\n` +
|
||||
`🔌 **Tipo:** ${onuType}\n` +
|
||||
`🏷️ **VLAN:** ${vlan}\n` +
|
||||
`⚙️ **Portas configuradas:** ${resultado.details.portas}\n\n` +
|
||||
`🔐 **Login Web:** admin / clicknet10\n\n` +
|
||||
`⚡ A ONU foi reiniciada e estará disponível em alguns instantes.`,
|
||||
{ parse_mode: 'Markdown' }
|
||||
);
|
||||
} else {
|
||||
await this.bot.sendMessage(chatId,
|
||||
`❌ **Erro ao adicionar ONU Fiberhome**\n\n` +
|
||||
`⚠️ ${resultado.error}`,
|
||||
{ parse_mode: 'Markdown' }
|
||||
);
|
||||
}
|
||||
|
||||
} catch (error) {
|
||||
console.error('❌ Erro ao executar adição de ONU Fiberhome:', error);
|
||||
await this.bot.sendMessage(chatId,
|
||||
`❌ **Erro ao adicionar ONU Fiberhome**\n\n` +
|
||||
`⚠️ ${error.message}`,
|
||||
{ parse_mode: 'Markdown' }
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Comando não reconhecido
|
||||
*/
|
||||
@@ -1158,6 +1329,12 @@ Digite /help para ver todos os comandos disponíveis!
|
||||
} else if (data.startsWith('add_onu_')) {
|
||||
console.log(`🔍 Chamando handleAddOnuCallback`);
|
||||
await this.handleAddOnuCallback(callbackQuery, data);
|
||||
} else if (data.startsWith('fh_onu_type_')) {
|
||||
console.log(`🔍 Chamando handleFiberhomeOnuTypeCallback`);
|
||||
await this.handleFiberhomeOnuTypeCallback(callbackQuery, data);
|
||||
} else if (data.startsWith('fh_vlan_')) {
|
||||
console.log(`🔍 Chamando handleFiberhomeVlanCallback`);
|
||||
await this.handleFiberhomeVlanCallback(callbackQuery, data);
|
||||
} else if (data.startsWith('fiberhome_details_')) {
|
||||
console.log(`🔍 Condição fiberhome_details_ atendida`);
|
||||
const serialNumber = data.replace('fiberhome_details_', '');
|
||||
@@ -1180,6 +1357,12 @@ Digite /help para ver todos os comandos disponíveis!
|
||||
await this.bot.answerCallbackQuery(callbackQuery.id);
|
||||
} else if (data === 'cancel_action') {
|
||||
await this.bot.answerCallbackQuery(callbackQuery.id, 'Ação cancelada');
|
||||
|
||||
// Limpar sessão do usuário se existir
|
||||
if (this.userSessions.has(userId)) {
|
||||
this.userSessions.delete(userId);
|
||||
}
|
||||
|
||||
await this.bot.editMessageText('❌ Ação cancelada.', {
|
||||
chat_id: chatId,
|
||||
message_id: callbackQuery.message.message_id
|
||||
@@ -2444,6 +2627,96 @@ Digite /help para ver todos os comandos disponíveis!
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Handle callback para tipo de ONU Fiberhome
|
||||
*/
|
||||
async handleFiberhomeOnuTypeCallback(callbackQuery, data) {
|
||||
const chatId = callbackQuery.message.chat.id;
|
||||
const userId = callbackQuery.from.id;
|
||||
|
||||
// Formato: fh_onu_type_AN5506-02-B ou fh_onu_type_AN5506-01-A
|
||||
const onuType = data.replace('fh_onu_type_', '');
|
||||
|
||||
// Recuperar sessão
|
||||
const session = this.userSessions.get(userId);
|
||||
if (!session || session.action !== 'adicionar_onu_fiberhome_step4') {
|
||||
await this.bot.answerCallbackQuery(callbackQuery.id, '❌ Sessão expirada');
|
||||
await this.bot.sendMessage(chatId, '❌ Sessão expirada. Por favor, comece novamente.');
|
||||
this.userSessions.delete(userId);
|
||||
return;
|
||||
}
|
||||
|
||||
session.onuType = onuType;
|
||||
|
||||
await this.bot.answerCallbackQuery(callbackQuery.id);
|
||||
|
||||
// Perguntar sobre VLAN
|
||||
const keyboard = {
|
||||
inline_keyboard: [
|
||||
[{ text: '✅ Usar VLAN 1002 (padrão)', callback_data: 'fh_vlan_1002' }],
|
||||
[{ text: '🔧 Usar outra VLAN', callback_data: 'fh_vlan_custom' }],
|
||||
[{ text: '❌ Cancelar', callback_data: 'cancel_action' }]
|
||||
]
|
||||
};
|
||||
|
||||
await this.bot.editMessageText(
|
||||
`🔌 **Tipo da ONU:** ${onuType}\n\n` +
|
||||
`🏷️ **VLAN:**\n` +
|
||||
`A VLAN padrão é 1002. Deseja usar esta VLAN ou configurar outra?`,
|
||||
{
|
||||
chat_id: chatId,
|
||||
message_id: callbackQuery.message.message_id,
|
||||
reply_markup: keyboard,
|
||||
parse_mode: 'Markdown'
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Handle callback para VLAN Fiberhome
|
||||
*/
|
||||
async handleFiberhomeVlanCallback(callbackQuery, data) {
|
||||
const chatId = callbackQuery.message.chat.id;
|
||||
const userId = callbackQuery.from.id;
|
||||
|
||||
// Recuperar sessão
|
||||
const session = this.userSessions.get(userId);
|
||||
if (!session || session.action !== 'adicionar_onu_fiberhome_step2') {
|
||||
await this.bot.answerCallbackQuery(callbackQuery.id, '❌ Sessão expirada');
|
||||
await this.bot.sendMessage(chatId, '❌ Sessão expirada. Por favor, comece novamente.');
|
||||
this.userSessions.delete(userId);
|
||||
return;
|
||||
}
|
||||
|
||||
await this.bot.answerCallbackQuery(callbackQuery.id);
|
||||
|
||||
if (data === 'fh_vlan_1002') {
|
||||
// Usar VLAN padrão 1002
|
||||
session.vlan = 1002;
|
||||
|
||||
// Limpar sessão
|
||||
this.userSessions.delete(userId);
|
||||
|
||||
// Executar adição da ONU
|
||||
await this.executarAdicaoOnuFiberhome(chatId, session);
|
||||
|
||||
} else if (data === 'fh_vlan_custom') {
|
||||
// Pedir VLAN customizada
|
||||
session.action = 'adicionar_onu_fiberhome_step3';
|
||||
this.userSessions.set(userId, session);
|
||||
|
||||
await this.bot.editMessageText(
|
||||
`🏷️ **VLAN Customizada**\n\n` +
|
||||
`Digite o número da VLAN que deseja usar (1-4094):`,
|
||||
{
|
||||
chat_id: chatId,
|
||||
message_id: callbackQuery.message.message_id,
|
||||
parse_mode: 'Markdown'
|
||||
}
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Handle callback para confirmar adição de ONU
|
||||
*/
|
||||
|
||||
Reference in new issue
Block a user