Add TopSapp preliminary support
Signed-off-by: Rodrigo B. de Sousa Martins <rodrigo.sousa.577@gmail.com>
This commit is contained in:
1 parent
d4c37a3f78
commit
723ad8c268
10 files changed
+11952
-2
No files matched your search
@@ -1,5 +1,6 @@
|
||||
const NLPProcessor = require('../nlp/processor');
|
||||
const SSHManager = require('../ssh/manager');
|
||||
const { TopSappManager } = require('../topsapp');
|
||||
const config = require('../config/config');
|
||||
|
||||
class BotHandler {
|
||||
@@ -7,6 +8,7 @@ class BotHandler {
|
||||
this.bot = bot;
|
||||
this.nlp = new NLPProcessor();
|
||||
this.ssh = new SSHManager();
|
||||
this.topsapp = new TopSappManager();
|
||||
this.userSessions = new Map(); // Armazena sessões de usuário
|
||||
|
||||
console.log('🎯 BotHandler inicializado');
|
||||
@@ -150,6 +152,36 @@ class BotHandler {
|
||||
await this.handleAdicionarOnu(chatId, target);
|
||||
break;
|
||||
|
||||
case 'buscar_cliente':
|
||||
console.log(`🔍 Executando handleBuscarCliente com target: ${target}`);
|
||||
await this.handleBuscarCliente(chatId, target);
|
||||
break;
|
||||
|
||||
case 'ver_faturas':
|
||||
console.log(`📄 Executando handleVerFaturas com target: ${target}`);
|
||||
await this.handleVerFaturas(chatId, target);
|
||||
break;
|
||||
|
||||
case 'gerar_boleto':
|
||||
console.log(`💸 Executando handleGerarBoleto com target: ${target}`);
|
||||
await this.handleGerarBoleto(chatId, target);
|
||||
break;
|
||||
|
||||
case 'bloquear_cliente':
|
||||
console.log(`🔒 Executando handleBloquearCliente com target: ${target}`);
|
||||
await this.handleBloquearCliente(chatId, target);
|
||||
break;
|
||||
|
||||
case 'liberar_cliente':
|
||||
console.log(`🔓 Executando handleLiberarCliente com target: ${target}`);
|
||||
await this.handleLiberarCliente(chatId, target);
|
||||
break;
|
||||
|
||||
case 'status_topsapp':
|
||||
console.log(`🏢 Executando handleStatusTopSapp`);
|
||||
await this.handleStatusTopSapp(chatId);
|
||||
break;
|
||||
|
||||
case 'conectar':
|
||||
await this.handleConnect(chatId, target);
|
||||
break;
|
||||
@@ -256,6 +288,16 @@ Digite /help para ver todos os comandos disponíveis!
|
||||
• Oferece opções de firmware específicas para cada modelo
|
||||
• Processo seguro com confirmação
|
||||
|
||||
🏢 TOPSAPP - GESTÃO DE CLIENTES:
|
||||
• "buscar cliente João da Silva"
|
||||
• "buscar cliente 123.456.789-10"
|
||||
• "buscar cliente Guarai João"
|
||||
• "ver faturas 123.456.789-10"
|
||||
• "gerar boleto fatura123"
|
||||
• "bloquear cliente 456"
|
||||
• "liberar cliente 456"
|
||||
• "status topsapp"
|
||||
|
||||
📊 STATUS E MONITORAMENTO:
|
||||
/status <equipamento> - Verifica status
|
||||
• "verificar concentrador"
|
||||
@@ -270,12 +312,18 @@ Digite /help para ver todos os comandos disponíveis!
|
||||
• "Listar usuários conectados"
|
||||
• "Reiniciar juniper"
|
||||
• "Ping 131.0.192.254"
|
||||
• "Buscar cliente João da Silva"
|
||||
• "Ver faturas do CPF 123.456.789-10"
|
||||
|
||||
✅ EXEMPLOS PRÁTICOS:
|
||||
• "desconectar cliente user123"
|
||||
• "ver sinal DACM91569513"
|
||||
• "adicionar onu DACM91569513"
|
||||
• "remover onu DACM91569513"
|
||||
• "buscar cliente João Pedro Afonso"
|
||||
• "ver faturas cliente 123.456.789-10"
|
||||
• "gerar boleto fatura456"
|
||||
• "bloquear cliente 789"
|
||||
• "listar clientes conectados"
|
||||
• "verificar status concentrador"
|
||||
|
||||
@@ -818,6 +866,12 @@ Digite /help para ver todos os comandos disponíveis!
|
||||
console.error(`❌ Erro em handleConfirmAddCallback:`, confirmError);
|
||||
await this.bot.answerCallbackQuery(callbackQuery.id, 'Erro na confirmação');
|
||||
}
|
||||
} else if (data.startsWith('confirm_block_')) {
|
||||
console.log(`🔍 Chamando handleConfirmBlockCallback`);
|
||||
await this.handleConfirmBlockCallback(callbackQuery, data);
|
||||
} else if (data.startsWith('confirm_unblock_')) {
|
||||
console.log(`🔍 Chamando handleConfirmUnblockCallback`);
|
||||
await this.handleConfirmUnblockCallback(callbackQuery, data);
|
||||
} else if (data.startsWith('confirm_')) {
|
||||
console.log(`🔍 Condição confirm_ atendida`);
|
||||
await this.handleConfirmCallback(callbackQuery, data);
|
||||
@@ -2040,6 +2094,550 @@ Digite /help para ver todos os comandos disponíveis!
|
||||
{ parse_mode: 'Markdown' }
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Status do TopSapp
|
||||
*/
|
||||
async handleStatusTopSapp(chatId) {
|
||||
try {
|
||||
await this.bot.sendMessage(chatId, '🔄 Verificando status do TopSapp...');
|
||||
|
||||
const status = this.topsapp.getConfigStatus();
|
||||
const instances = this.topsapp.getInstances();
|
||||
|
||||
let message = `🏢 **STATUS TOPSAPP**\n\n`;
|
||||
|
||||
if (status.ready) {
|
||||
message += `✅ **Configuração**: OK\n`;
|
||||
message += `📊 **Instâncias configuradas**: ${instances.length}\n\n`;
|
||||
|
||||
instances.forEach(instance => {
|
||||
message += `🌐 **${instance.location}**\n`;
|
||||
message += `└ ${instance.host}\n`;
|
||||
message += `└ Status: ${status.instances.find(i => i.location === instance.location)?.configured ? '✅ Configurado' : '❌ Não configurado'}\n\n`;
|
||||
});
|
||||
|
||||
message += `💡 Use os comandos:\n`;
|
||||
message += `• "buscar cliente João"\n`;
|
||||
message += `• "ver faturas 123.456.789-10"\n`;
|
||||
message += `• "gerar boleto fatura123"\n`;
|
||||
message += `• "bloquear cliente 456"`;
|
||||
} else {
|
||||
message += `❌ **Configuração**: Incompleta\n\n`;
|
||||
message += `⚠️ **Problemas encontrados**:\n`;
|
||||
|
||||
status.instances.forEach(instance => {
|
||||
if (!instance.configured) {
|
||||
message += `• ${instance.location}: Credenciais não configuradas\n`;
|
||||
}
|
||||
});
|
||||
|
||||
message += `\n📝 **Configure no arquivo .env**:\n`;
|
||||
message += `• TOPSAPP_GUARAI_USER\n`;
|
||||
message += `• TOPSAPP_GUARAI_PASS\n`;
|
||||
message += `• TOPSAPP_PEDRO_AFONSO_USER\n`;
|
||||
message += `• TOPSAPP_PEDRO_AFONSO_PASS`;
|
||||
}
|
||||
|
||||
await this.bot.sendMessage(chatId, message, { parse_mode: 'Markdown' });
|
||||
|
||||
} catch (error) {
|
||||
console.error('❌ Erro ao verificar status TopSapp:', error);
|
||||
await this.bot.sendMessage(chatId,
|
||||
`❌ **Erro ao verificar status TopSapp**\n\n` +
|
||||
`⚠️ ${error.message}`,
|
||||
{ parse_mode: 'Markdown' }
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Buscar cliente no TopSapp
|
||||
*/
|
||||
async handleBuscarCliente(chatId, target) {
|
||||
if (!target) {
|
||||
await this.bot.sendMessage(chatId,
|
||||
`🔍 **Buscar Cliente**\n\n` +
|
||||
`💡 **Como usar:**\n` +
|
||||
`• "buscar cliente João da Silva"\n` +
|
||||
`• "buscar cliente 123.456.789-10"\n` +
|
||||
`• "buscar cliente Guarai João" (específica instância)\n` +
|
||||
`• "buscar cliente Pedro Afonso Maria"`
|
||||
);
|
||||
return;
|
||||
}
|
||||
|
||||
try {
|
||||
await this.bot.sendMessage(chatId, '🔍 Buscando cliente...');
|
||||
|
||||
// Detectar se especificou uma localização
|
||||
let location = '';
|
||||
let query = target;
|
||||
|
||||
if (target.toLowerCase().includes('guarai') || target.toLowerCase().includes('colmeia')) {
|
||||
location = 'Guarai/Colmeia';
|
||||
query = target.replace(/(guarai|colmeia)/gi, '').trim();
|
||||
} else if (target.toLowerCase().includes('pedro afonso')) {
|
||||
location = 'Pedro Afonso';
|
||||
query = target.replace(/pedro afonso/gi, '').trim();
|
||||
}
|
||||
|
||||
const resultado = await this.topsapp.buscarCliente(query, location);
|
||||
|
||||
if (!resultado.success) {
|
||||
await this.bot.sendMessage(chatId,
|
||||
`❌ **Erro na busca**\n\n` +
|
||||
`⚠️ ${resultado.error}`,
|
||||
{ parse_mode: 'Markdown' }
|
||||
);
|
||||
return;
|
||||
}
|
||||
|
||||
if (!resultado.clientes || resultado.clientes.length === 0) {
|
||||
await this.bot.sendMessage(chatId,
|
||||
`🔍 **Nenhum cliente encontrado**\n\n` +
|
||||
`📝 Termo buscado: "${query}"\n` +
|
||||
`🌐 Instância: ${resultado.instancia || 'Todas'}`,
|
||||
{ parse_mode: 'Markdown' }
|
||||
);
|
||||
return;
|
||||
}
|
||||
|
||||
let message = `🔍 **Clientes encontrados**\n\n`;
|
||||
message += `📊 **Total**: ${resultado.total} cliente(s)\n`;
|
||||
message += `🌐 **Instância**: ${resultado.instancia}\n\n`;
|
||||
|
||||
resultado.clientes.slice(0, 5).forEach((cliente, index) => {
|
||||
message += `👤 **${index + 1}. ${cliente.nome}**\n`;
|
||||
message += `🆔 ID: \`${cliente.id}\`\n`;
|
||||
message += `📄 CPF: \`${cliente.cpf}\`\n`;
|
||||
message += `📧 Email: ${cliente.email || 'Não informado'}\n`;
|
||||
message += `📞 Telefone: ${cliente.telefone || 'Não informado'}\n`;
|
||||
message += `📍 Endereço: ${cliente.endereco}\n`;
|
||||
message += `🏙️ Cidade: ${cliente.cidade}\n`;
|
||||
message += `📊 Status: ${cliente.status === 1 ? '✅ Ativo' : '❌ Inativo'}\n\n`;
|
||||
});
|
||||
|
||||
if (resultado.total > 5) {
|
||||
message += `📋 *Mostrando apenas os primeiros 5 resultados de ${resultado.total}*\n\n`;
|
||||
}
|
||||
|
||||
message += `💡 **Comandos úteis:**\n`;
|
||||
message += `• "ver faturas ${resultado.clientes[0].cpf}"\n`;
|
||||
message += `• "bloquear cliente ${resultado.clientes[0].id}"\n`;
|
||||
message += `• "liberar cliente ${resultado.clientes[0].id}"`;
|
||||
|
||||
await this.bot.sendMessage(chatId, message, { parse_mode: 'Markdown' });
|
||||
|
||||
} catch (error) {
|
||||
console.error('❌ Erro ao buscar cliente:', error);
|
||||
await this.bot.sendMessage(chatId,
|
||||
`❌ **Erro ao buscar cliente**\n\n` +
|
||||
`⚠️ ${error.message}`,
|
||||
{ parse_mode: 'Markdown' }
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Ver faturas do cliente
|
||||
*/
|
||||
async handleVerFaturas(chatId, target) {
|
||||
if (!target) {
|
||||
await this.bot.sendMessage(chatId,
|
||||
`📄 **Ver Faturas**\n\n` +
|
||||
`💡 **Como usar:**\n` +
|
||||
`• "ver faturas 123.456.789-10"\n` +
|
||||
`• "ver faturas cliente123"\n` +
|
||||
`• "ver faturas Guarai 123.456.789-10"`
|
||||
);
|
||||
return;
|
||||
}
|
||||
|
||||
try {
|
||||
await this.bot.sendMessage(chatId, '📄 Buscando faturas...');
|
||||
|
||||
// Detectar se especificou uma localização
|
||||
let location = '';
|
||||
let clienteId = target;
|
||||
|
||||
if (target.toLowerCase().includes('guarai') || target.toLowerCase().includes('colmeia')) {
|
||||
location = 'Guarai/Colmeia';
|
||||
clienteId = target.replace(/(guarai|colmeia)/gi, '').trim();
|
||||
} else if (target.toLowerCase().includes('pedro afonso')) {
|
||||
location = 'Pedro Afonso';
|
||||
clienteId = target.replace(/pedro afonso/gi, '').trim();
|
||||
}
|
||||
|
||||
// Se é CPF, buscar o cliente primeiro
|
||||
let idCliente = clienteId;
|
||||
if (clienteId.includes('.') || clienteId.includes('-')) {
|
||||
const busca = await this.topsapp.buscarCliente(clienteId, location);
|
||||
if (busca.success && busca.clientes && busca.clientes.length > 0) {
|
||||
idCliente = busca.clientes[0].id;
|
||||
location = busca.instancia;
|
||||
} else {
|
||||
await this.bot.sendMessage(chatId,
|
||||
`❌ **Cliente não encontrado**\n\n` +
|
||||
`📝 CPF/Nome: "${clienteId}"`,
|
||||
{ parse_mode: 'Markdown' }
|
||||
);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
const resultado = await this.topsapp.obterBoletos(idCliente, location);
|
||||
|
||||
if (!resultado.success) {
|
||||
await this.bot.sendMessage(chatId,
|
||||
`❌ **Erro ao buscar faturas**\n\n` +
|
||||
`⚠️ ${resultado.error}`,
|
||||
{ parse_mode: 'Markdown' }
|
||||
);
|
||||
return;
|
||||
}
|
||||
|
||||
if (!resultado.boletos || resultado.boletos.length === 0) {
|
||||
await this.bot.sendMessage(chatId,
|
||||
`📄 **Nenhuma fatura encontrada**\n\n` +
|
||||
`👤 Cliente ID: ${idCliente}\n` +
|
||||
`🌐 Instância: ${resultado.instancia || location}`,
|
||||
{ parse_mode: 'Markdown' }
|
||||
);
|
||||
return;
|
||||
}
|
||||
|
||||
let message = `📄 **Faturas do Cliente**\n\n`;
|
||||
message += `📊 **Total**: ${resultado.total} fatura(s)\n`;
|
||||
message += `🌐 **Instância**: ${resultado.instancia}\n\n`;
|
||||
|
||||
resultado.boletos.slice(0, 10).forEach((boleto, index) => {
|
||||
message += `💸 **${index + 1}. Fatura #${boleto.id}**\n`;
|
||||
message += `💰 Valor: R$ ${boleto.valor}\n`;
|
||||
message += `📅 Vencimento: ${boleto.vencimento}\n`;
|
||||
message += `📊 Status: ${this.getStatusFatura(boleto.status)}\n`;
|
||||
message += `📝 Descrição: ${boleto.descricao || 'Não informada'}\n`;
|
||||
|
||||
if (boleto.linhaDigitavel) {
|
||||
message += `🔢 Linha digitável: \`${boleto.linhaDigitavel}\`\n`;
|
||||
}
|
||||
|
||||
message += '\n';
|
||||
});
|
||||
|
||||
if (resultado.total > 10) {
|
||||
message += `📋 *Mostrando apenas as primeiras 10 faturas de ${resultado.total}*\n\n`;
|
||||
}
|
||||
|
||||
if (resultado.boletos.length > 0) {
|
||||
message += `💡 **Gerar boleto:**\n`;
|
||||
message += `• "gerar boleto ${resultado.boletos[0].id}"`;
|
||||
}
|
||||
|
||||
await this.bot.sendMessage(chatId, message, { parse_mode: 'Markdown' });
|
||||
|
||||
} catch (error) {
|
||||
console.error('❌ Erro ao buscar faturas:', error);
|
||||
await this.bot.sendMessage(chatId,
|
||||
`❌ **Erro ao buscar faturas**\n\n` +
|
||||
`⚠️ ${error.message}`,
|
||||
{ parse_mode: 'Markdown' }
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Gerar boleto PDF
|
||||
*/
|
||||
async handleGerarBoleto(chatId, target) {
|
||||
if (!target) {
|
||||
await this.bot.sendMessage(chatId,
|
||||
`💸 **Gerar Boleto**\n\n` +
|
||||
`💡 **Como usar:**\n` +
|
||||
`• "gerar boleto 12345"\n` +
|
||||
`• "gerar boleto fatura123"`
|
||||
);
|
||||
return;
|
||||
}
|
||||
|
||||
try {
|
||||
await this.bot.sendMessage(chatId, '💸 Gerando boleto PDF...');
|
||||
|
||||
const resultado = await this.topsapp.gerarBoletoPDF(target);
|
||||
|
||||
if (!resultado.success) {
|
||||
await this.bot.sendMessage(chatId,
|
||||
`❌ **Erro ao gerar boleto**\n\n` +
|
||||
`⚠️ ${resultado.error}`,
|
||||
{ parse_mode: 'Markdown' }
|
||||
);
|
||||
return;
|
||||
}
|
||||
|
||||
// Enviar o PDF
|
||||
await this.bot.sendDocument(chatId, resultado.buffer, {
|
||||
filename: resultado.filename,
|
||||
caption: `💸 **Boleto Gerado**\n\n` +
|
||||
`📄 Arquivo: ${resultado.filename}\n` +
|
||||
`🌐 Instância: ${resultado.instancia}`,
|
||||
parse_mode: 'Markdown'
|
||||
});
|
||||
|
||||
await this.bot.sendMessage(chatId,
|
||||
`✅ **Boleto enviado com sucesso!**\n\n` +
|
||||
`📄 Arquivo: ${resultado.filename}\n` +
|
||||
`🌐 Instância: ${resultado.instancia}`,
|
||||
{ parse_mode: 'Markdown' }
|
||||
);
|
||||
|
||||
} catch (error) {
|
||||
console.error('❌ Erro ao gerar boleto:', error);
|
||||
await this.bot.sendMessage(chatId,
|
||||
`❌ **Erro ao gerar boleto**\n\n` +
|
||||
`⚠️ ${error.message}`,
|
||||
{ parse_mode: 'Markdown' }
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Bloquear cliente
|
||||
*/
|
||||
async handleBloquearCliente(chatId, target) {
|
||||
if (!target) {
|
||||
await this.bot.sendMessage(chatId,
|
||||
`🔒 **Bloquear Cliente**\n\n` +
|
||||
`💡 **Como usar:**\n` +
|
||||
`• "bloquear cliente 456"\n` +
|
||||
`• "bloquear 789"`
|
||||
);
|
||||
return;
|
||||
}
|
||||
|
||||
try {
|
||||
// Solicitar confirmação
|
||||
const keyboard = {
|
||||
inline_keyboard: [
|
||||
[
|
||||
{ text: '✅ Confirmar Bloqueio', callback_data: `confirm_block_${target}` },
|
||||
{ text: '❌ Cancelar', callback_data: 'cancel_action' }
|
||||
]
|
||||
]
|
||||
};
|
||||
|
||||
await this.bot.sendMessage(chatId,
|
||||
`🔒 **Confirmar Bloqueio**\n\n` +
|
||||
`⚠️ Deseja bloquear o cliente ID: ${target}?\n\n` +
|
||||
`📋 Esta ação bloqueará todos os serviços ativos do cliente.`,
|
||||
{
|
||||
parse_mode: 'Markdown',
|
||||
reply_markup: keyboard
|
||||
}
|
||||
);
|
||||
|
||||
} catch (error) {
|
||||
console.error('❌ Erro ao preparar bloqueio:', error);
|
||||
await this.bot.sendMessage(chatId,
|
||||
`❌ **Erro ao preparar bloqueio**\n\n` +
|
||||
`⚠️ ${error.message}`,
|
||||
{ parse_mode: 'Markdown' }
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Liberar cliente
|
||||
*/
|
||||
async handleLiberarCliente(chatId, target) {
|
||||
if (!target) {
|
||||
await this.bot.sendMessage(chatId,
|
||||
`🔓 **Liberar Cliente**\n\n` +
|
||||
`💡 **Como usar:**\n` +
|
||||
`• "liberar cliente 456"\n` +
|
||||
`• "liberar 789"`
|
||||
);
|
||||
return;
|
||||
}
|
||||
|
||||
try {
|
||||
// Solicitar confirmação
|
||||
const keyboard = {
|
||||
inline_keyboard: [
|
||||
[
|
||||
{ text: '✅ Confirmar Liberação', callback_data: `confirm_unblock_${target}` },
|
||||
{ text: '❌ Cancelar', callback_data: 'cancel_action' }
|
||||
]
|
||||
]
|
||||
};
|
||||
|
||||
await this.bot.sendMessage(chatId,
|
||||
`🔓 **Confirmar Liberação**\n\n` +
|
||||
`✅ Deseja liberar o cliente ID: ${target}?\n\n` +
|
||||
`📋 Esta ação liberará todos os serviços bloqueados do cliente.`,
|
||||
{
|
||||
parse_mode: 'Markdown',
|
||||
reply_markup: keyboard
|
||||
}
|
||||
);
|
||||
|
||||
} catch (error) {
|
||||
console.error('❌ Erro ao preparar liberação:', error);
|
||||
await this.bot.sendMessage(chatId,
|
||||
`❌ **Erro ao preparar liberação**\n\n` +
|
||||
`⚠️ ${error.message}`,
|
||||
{ parse_mode: 'Markdown' }
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Utilitário para obter status da fatura
|
||||
*/
|
||||
getStatusFatura(status) {
|
||||
switch (status) {
|
||||
case 1: return '✅ Paga';
|
||||
case 2: return '⏳ Pendente';
|
||||
case 3: return '❌ Vencida';
|
||||
case 4: return '🔄 Em processamento';
|
||||
default: return '❓ Status desconhecido';
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Callback para confirmar bloqueio de cliente
|
||||
*/
|
||||
async handleConfirmBlockCallback(callbackQuery, data) {
|
||||
const chatId = callbackQuery.message.chat.id;
|
||||
const clienteId = data.replace('confirm_block_', '');
|
||||
|
||||
try {
|
||||
await this.bot.answerCallbackQuery(callbackQuery.id, 'Processando bloqueio...');
|
||||
|
||||
await this.bot.editMessageText(
|
||||
`🔒 **Bloqueando cliente ID: ${clienteId}**\n\n⏳ Aguarde...`,
|
||||
{
|
||||
chat_id: chatId,
|
||||
message_id: callbackQuery.message.message_id,
|
||||
parse_mode: 'Markdown'
|
||||
}
|
||||
);
|
||||
|
||||
const resultado = await this.topsapp.bloquearCliente(clienteId);
|
||||
|
||||
if (!resultado.success) {
|
||||
await this.bot.editMessageText(
|
||||
`❌ **Erro ao bloquear cliente**\n\n` +
|
||||
`🆔 Cliente ID: ${clienteId}\n` +
|
||||
`⚠️ Erro: ${resultado.error}`,
|
||||
{
|
||||
chat_id: chatId,
|
||||
message_id: callbackQuery.message.message_id,
|
||||
parse_mode: 'Markdown'
|
||||
}
|
||||
);
|
||||
return;
|
||||
}
|
||||
|
||||
let message = `🔒 **Cliente bloqueado com sucesso!**\n\n`;
|
||||
message += `🆔 Cliente ID: ${clienteId}\n`;
|
||||
message += `🌐 Instância: ${resultado.instancia}\n`;
|
||||
message += `📊 Serviços bloqueados: ${resultado.total}\n\n`;
|
||||
|
||||
if (resultado.servicosBloqueados && resultado.servicosBloqueados.length > 0) {
|
||||
message += `📋 **Detalhes dos bloqueios:**\n`;
|
||||
resultado.servicosBloqueados.forEach((servico, index) => {
|
||||
message += `${index + 1}. ${servico.descricao}: ${servico.resultado.success ? '✅ Bloqueado' : '❌ Erro'}\n`;
|
||||
});
|
||||
}
|
||||
|
||||
await this.bot.editMessageText(message, {
|
||||
chat_id: chatId,
|
||||
message_id: callbackQuery.message.message_id,
|
||||
parse_mode: 'Markdown'
|
||||
});
|
||||
|
||||
} catch (error) {
|
||||
console.error('❌ Erro ao bloquear cliente:', error);
|
||||
await this.bot.editMessageText(
|
||||
`❌ **Erro interno ao bloquear cliente**\n\n` +
|
||||
`🆔 Cliente ID: ${clienteId}\n` +
|
||||
`⚠️ ${error.message}`,
|
||||
{
|
||||
chat_id: chatId,
|
||||
message_id: callbackQuery.message.message_id,
|
||||
parse_mode: 'Markdown'
|
||||
}
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Callback para confirmar liberação de cliente
|
||||
*/
|
||||
async handleConfirmUnblockCallback(callbackQuery, data) {
|
||||
const chatId = callbackQuery.message.chat.id;
|
||||
const clienteId = data.replace('confirm_unblock_', '');
|
||||
|
||||
try {
|
||||
await this.bot.answerCallbackQuery(callbackQuery.id, 'Processando liberação...');
|
||||
|
||||
await this.bot.editMessageText(
|
||||
`🔓 **Liberando cliente ID: ${clienteId}**\n\n⏳ Aguarde...`,
|
||||
{
|
||||
chat_id: chatId,
|
||||
message_id: callbackQuery.message.message_id,
|
||||
parse_mode: 'Markdown'
|
||||
}
|
||||
);
|
||||
|
||||
const resultado = await this.topsapp.liberarCliente(clienteId);
|
||||
|
||||
if (!resultado.success) {
|
||||
await this.bot.editMessageText(
|
||||
`❌ **Erro ao liberar cliente**\n\n` +
|
||||
`🆔 Cliente ID: ${clienteId}\n` +
|
||||
`⚠️ Erro: ${resultado.error}`,
|
||||
{
|
||||
chat_id: chatId,
|
||||
message_id: callbackQuery.message.message_id,
|
||||
parse_mode: 'Markdown'
|
||||
}
|
||||
);
|
||||
return;
|
||||
}
|
||||
|
||||
let message = `🔓 **Cliente liberado com sucesso!**\n\n`;
|
||||
message += `🆔 Cliente ID: ${clienteId}\n`;
|
||||
message += `🌐 Instância: ${resultado.instancia}\n`;
|
||||
message += `📊 Serviços liberados: ${resultado.total}\n\n`;
|
||||
|
||||
if (resultado.servicosLiberados && resultado.servicosLiberados.length > 0) {
|
||||
message += `📋 **Detalhes das liberações:**\n`;
|
||||
resultado.servicosLiberados.forEach((servico, index) => {
|
||||
message += `${index + 1}. ${servico.descricao}: ${servico.resultado.success ? '✅ Liberado' : '❌ Erro'}\n`;
|
||||
});
|
||||
}
|
||||
|
||||
await this.bot.editMessageText(message, {
|
||||
chat_id: chatId,
|
||||
message_id: callbackQuery.message.message_id,
|
||||
parse_mode: 'Markdown'
|
||||
});
|
||||
|
||||
} catch (error) {
|
||||
console.error('❌ Erro ao liberar cliente:', error);
|
||||
await this.bot.editMessageText(
|
||||
`❌ **Erro interno ao liberar cliente**\n\n` +
|
||||
`🆔 Cliente ID: ${clienteId}\n` +
|
||||
`⚠️ ${error.message}`,
|
||||
{
|
||||
chat_id: chatId,
|
||||
message_id: callbackQuery.message.message_id,
|
||||
parse_mode: 'Markdown'
|
||||
}
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = BotHandler;
|
||||
Reference in new issue
Block a user