https://discord.gg/botpress logo
UI feedback on sendEvent()?
# 🤝help
s
When window.botpress.sendEvent() is called is there a way to show UI feedback while the event is processing? There is a substantial delay between when sendEvent() is invoked and the bot responding where there is no UI feedback that anything is actually happening. Some ideas: * Show the bot typing indicator * And/or show a message as if its from the user (like what you see when sendMessage() is called. Thanks
s
There are ways and means to do this, but depends on the context of your sendEvent() What is the purpose of the sendEvent() A large part of that delay will be due to network and processing, and you can't show bot typing indicator on demand client-side. You also wouldn't get a response from the sendEvent() so you would have have to send an event back to the website from Botpress side. You could use JS/CSS/HTML to create your own UI feedback indicator on client side, by changing/adding elements and styles to webchat as soon as you send the sendEvent() and then reverting changes when Botpress sends an event back.
b
I can help you with any difficulty u're facing here Let's have a chet and proceed to our project
s
@sparse-eve-63408 there are buttons on a page that when clicked, pull some info from the page, and then sends it to botpress via sendEvent(). The bot handles the event and will send messages back and possibly send a custom event back. If sendEvent() had options for showing a typing indicator and a message that would be perfect.
s
@square-king-46874 Currently working on pretty much exactly the same thing myself for my own bot. Just like you, I have buttons on a page, that when clicked, pull info from the page and send it to Botpress via sendEvent(). The issue here is that I there is no way to show the typing indicator client-side, this is the same as sending a message as the Bot instead of the User. Both Bot messages and the typing indicator happen server-side. The delay between sending the event and the bot replying will likely be due to network and processing delays, so showing any feedback whatsoever would have to be client-side. The best way I can think of achieving this is forcing CSS changes to webchat as soon as the button is clicked/sentEvent() invoked. Those changes should then revert as soon as the bot replies, this will likely require sending an event back to the website/webchat on the Botpress side. The way i'm thinking of doing it, is by applying these CSS changes with JS on button click or sendEvent() .bpModalContainer { background: rgba(0,0,0,0.7); } .bpContainer { filter: blur(1.5px); } And injecting a loading spinner in the centre of the .bpModalContainer div. The loading spinner will be an animated GIF from https://loading.io however there are other spinner alternatives. This should cause the webchat to turn a little blurry, with a dark overlay and spinner while the event is "processing". On the Botpress side, the first card in the first node that reacts to your sent event would be a Send Custom Event card to send an event back to your website/webchat to inform your code that the event has finished processing and the bot is about to reply. I would then use JS to unset/remove all styles/elements that were changed/added when the event was sent. This seems like the most simple way to implement this event UI feedback to me.
I mean, if you were able to isolate the elements and styles of the Botpress typing indicator, you could probably inject the Botpress typing indicator into the webchat, but I don't think you can just invoke it with JS. Similarly you could also make your own typing indicator that looks similar and inject that too. However you decide to do it, it will likely involve manipulation of webchat styles and elements using JS.
s
I wonder if the botpress could enhance the web chat ui library to accommodate this? @prehistoric-airplane-85682 for visibility
3 Views