diff --git a/src/bot/handler.js b/src/bot/handler.js index dd3947f..d65d72d 100644 --- a/src/bot/handler.js +++ b/src/bot/handler.js @@ -6361,6 +6361,74 @@ Digite /help para ver todos os comandos disponíveis! this.userSessions.delete(userId); } } + + /** + * Callback: Seleção de cliente via botão inline no fluxo de suporte + */ + async handleSuporteClienteCallback(callbackQuery, data) { + const chatId = callbackQuery.message.chat.id; + const userId = callbackQuery.from.id; + + await this.bot.answerCallbackQuery(callbackQuery.id); + + const index = parseInt(data.replace('suporte_cliente_', '')); + + const sessaoAtiva = Array.from(this.suporteSessions.values()).find( + session => session.chatId === chatId && session.userId === userId + ); + + if (!sessaoAtiva) { + await this.bot.sendMessage(chatId, + `❌ **Sessão expirada**\n\nUse o comando "abrir suporte" para iniciar novamente.`, + { parse_mode: 'Markdown' } + ); + return; + } + + const clientes = sessaoAtiva.dados.clientesEncontrados; + if (!clientes || index < 0 || index >= clientes.length) { + await this.bot.sendMessage(chatId, `❌ **Cliente inválido.** Por favor, tente novamente.`, { parse_mode: 'Markdown' }); + return; + } + + sessaoAtiva.dados.clienteSelecionado = clientes[index]; + sessaoAtiva.etapa = 'selecionar_servico'; + await this.processarEtapaSelecionarServico(sessaoAtiva.id); + } + + /** + * Callback: Seleção de serviço via botão inline no fluxo de suporte + */ + async handleSuporteServicoCallback(callbackQuery, data) { + const chatId = callbackQuery.message.chat.id; + const userId = callbackQuery.from.id; + + await this.bot.answerCallbackQuery(callbackQuery.id); + + const index = parseInt(data.replace('suporte_servico_', '')); + + const sessaoAtiva = Array.from(this.suporteSessions.values()).find( + session => session.chatId === chatId && session.userId === userId + ); + + if (!sessaoAtiva) { + await this.bot.sendMessage(chatId, + `❌ **Sessão expirada**\n\nUse o comando "abrir suporte" para iniciar novamente.`, + { parse_mode: 'Markdown' } + ); + return; + } + + const servicos = sessaoAtiva.dados.servicos; + if (!servicos || index < 0 || index >= servicos.length) { + await this.bot.sendMessage(chatId, `❌ **Serviço inválido.** Por favor, tente novamente.`, { parse_mode: 'Markdown' }); + return; + } + + sessaoAtiva.dados.servicoSelecionado = servicos[index]; + sessaoAtiva.etapa = 'selecionar_categoria'; + await this.processarEtapaSelecionarCategoria(sessaoAtiva.id); + } } module.exports = BotHandler;