Execute custom action when session is disconnected

I am currently using Rasa 1.1.3 with Django-Rasa-bot (GitHub - Alexmhack/Django-Rasa-Bot: Integrating Rasa Core with Django backend and finally using Webchat for chatbot user interface) and Rasa-webchat (GitHub - botfront/rasa-webchat: A chat widget for Rasa and Botfront) as the frontend. I’m looking for a way to log session connect and disconnect events in DB. I was able to log session connect events by emitting a user_uttered with a dedicated intent as the message from the Rasa-webchat when the session is confirmed. This triggers a custom action which inserts the necessary data into the DB.

How do I log disconnect events into the DB? I tried emitting a similar user_uttered from Rasa-webchat on disconnect (When the browser is closed) but it doesn’t seem to work. I see that rasa.core.channels.socketio has a function which logs session disconnect to the log file (rasa/socketio.py at master · RasaHQ/rasa · GitHub). How do I implement or override this in my custom actions so that I can make a DB entry when user disconnects?

This is best handled in the UI rather than Rasa. Extending the botfront webchat and running a function against the onbeforeunload event to capture the close window and send a message to a logging service or db function.

1 Like

Using beforeunload worked, thank you very much!