https://discord.gg/botpress logo
How to make my agent wait the user to end sending ...
# 🤝help
a
Hi community. I'm looking to implement a behavior in my bot (currently integrated with Twilio for WhatsApp) where the bot waits for a set of messages before responding. The idea is: if a user sends multiple messages within a short time frame (e.g., three messages in under 10 seconds), the bot should wait and respond based on the full context of those messages, after 10 seconds have passed since the user's last message. I couldn’t find a clear response of this setup here, has anyone implemented something similar or found a simple solution for this use case? I tried using the Before Incoming hook with this code below, but it's not working. (The final part of the code is in the image) const DEBOUNCE_MS = 10000; const sessionState = event.state.session; const now = Date.now(); // Recupera ou inicializa os dados de estado const messageBuffer = sessionState.messageBuffer || []; const lastMessageTime = sessionState.lastMessageTime; console.log(
[Debounce] Mensagem recebida: "${event.payload.text}"
); console.log(
[Debounce] Mensagens acumuladas antes: ${JSON.stringify(messageBuffer)}
); // Adiciona a nova mensagem ao buffer messageBuffer.push(event.payload.text); sessionState.messageBuffer = messageBuffer; // Se ainda não temos um tempo salvo, salva e aguarda a próxima if (!lastMessageTime) { sessionState.lastMessageTime = now; console.log(
[Debounce] Primeira mensagem — aguardando próximas...
); (event as any).flags = (event as any).flags || {}; (event as any).flags['SKIP_PROCESSING'] = true; return; } const timeSinceLast = now - lastMessageTime; console.log(
[Debounce] Tempo desde a última mensagem: ${timeSinceLast}ms
); if (timeSinceLast < DEBOUNCE_MS) { // Atualiza tempo e aguarda mais mensagens sessionState.lastMessageTime = now; console.log(
[Debounce] Ainda dentro da janela. Aguardando mais mensagens...
); https://cdn.discordapp.com/attachments/1376922232575627455/1376922232865161277/Captura_de_Tela_2025-05-27_as_10.56.33.png?ex=68371642&is=6835c4c2&hm=62034be760bbb83515d88ac6b33c24f5fd36088e8696f0f16ede01bbe78ff66c&
p
I would recommend taking a look at this thread: https://discord.com/channels/1108396290624213082/1272647969866252453 Happy Bot Building!
3 Views