https://discord.gg/botpress logo
Conversation started trigger when session expired
# šŸ¤help
b
Hello everyone, I need a bit of help with session handling in Botpress. I’m building a chatbot where the first thing the bot should do is listen to the user’s question. So I’ve set up the following: • A ā€œconversation startedā€ trigger that goes to a node containing a Raw Input card. • The Raw Input captures the user’s question, sends it to an OpenAI card, and then loops back to listen again. The problem I’m solving is this: If I only use a ā€œstartā€ node (without the ā€œconversation startedā€ trigger), the first user message is used just to activate the bot — it doesn’t actually get answered. So I added the ā€œconversation startedā€ trigger to ensure the bot starts listening immediately, and that works fine for new users. However, I’ve hit an issue with returning users: If someone uses the bot, then closes the page or leaves, and comes back later, Botpress seems to recognize them (probably based on the userId), so it doesn’t fire the ā€œconversation startedā€ trigger again. But during that time, I think the bot session has expired or gone inactive, so the bot is no longer in listening mode. What happens is: • The returning user types a question. • The bot wakes up, but goes into listening mode only after that message. • So that first message is ignored • Only if they send a second message, the bot responds. So my question: How can I automatically re-enter the listening state for returning users (after session expiry), so their first message after returning gets captured and answered? Any best practices or recommended workarounds for this session edge case? Thanks a lot šŸ™
p
You might want to set your storage to session storage as that would generate new conversation and user every time the page is reopened.
b
Thanks for your answer ! The problem with using sessionStorage is that it would generate a new user record every time someone reopens the page. Since I’m on Botpress Cloud, this means it would create a lot of extra rows in the database (Table Rows), which would quickly increase my costs. Is there any alternative solution that would allow the conversation started trigger to fire again when a user returns without creating a brand-new user record each time? Ideally, I’d like to keep the same user ID (because of table rows cost) but still re-activate the bot after a period of inactivity.
p
The userId remains the same but the conversation Id does not. However, if you're referring to the conversations table, it does not relate to the UserId beyond it being a field. Hope this clarifies things.
b
Therefore by setting storage to session storage it should fix my problem and should not increase the cost (like table row or others) ? In that case I'm really interested in doing this, but don't know how to do it, could you help me ? Thank's a lot !
p
There is a dropdown in your dashboard's webchat page at the bottom of the general tab. Happy to help!
You might want to consider that starting a conversation is an event and you are limited in terms of the number of incoming events that can be fired per month based on your plan. This is the main area in which you could end up hitting the quota faster.
b
Hi! I tried switching the storage from Local Storage to Session Storage, but it didn’t resolve my issue. Also, I suspect the change isn’t actually being applied: after I click Save configuration, if I refresh the page, the setting reverts back to Local Storage. Is this expected or a bug? Do I need to do anything else (clear cache, redeploy, wait for propagation) for the setting to persist? ( I find the button on webchat -> setting -> storage location)
p
Clearing your cache is a good practice for sure. Another thing you can do is reembed the latest version when the changes have actually been saved.
2 Views