https://discord.gg/botpress logo
Input AI and Input message limit
# 🤝help
b
Hi, is it possible to set a limit for AI input and a message limit, and if the user exceeds the maximum number of messages, they are banned for a certain amount of time?
w
what do you mean by AI input?
as for message limits, you can implement an "after turn ends" hook that increments with each message
b
To set a limit of character the user send
w
and use that to limit the amount of interactions
in the webchat?
b
yes
if the user send over 1000 caracters it wont respond
w
you could also add a hook that slices the message into the first X characters
i'm gonna see if you can limit the message field
b
no i want to do that for who want to spam the chatbot with many caracters to increase the input and the AI costs
and how to do a code that ban the user for x hours ? even if he restart the bot
w
Copy code
js
<script>
window.botpress.on('webchat:initialized', (event) => {
  setTimeout(() => {
    const textarea = document.querySelector('.bpComposerInput') || 
    
    if (textarea) {
      textarea.setAttribute('maxlength', '50');
    } else {
      console.warn('input area not found');
    }
  }, 100);
});
</script>
you can try this
it limits to 50 characters
feel free to change it
b
where i need to put the code ?
In the workflow or in the HTML code ?
w
in your website
It doesn't work...
Where the the text "input area not found" as to show ?
w
in your devtools console
ctrl shift I
w
yeah that's still going to incur a bit of cost i suppose
because of the agents
but nice solution
you can also just do event.preview instead of manually saving the input
b
yes true, thank you
Now i need to set up a thing to ban an user when he used to many times the chat
4 Views