Livechat setDepartment function

Hello. I’m using Livechat on our website, we have a bot which should talk to users, and in some cases switch to real agents. For that we have 2 departments, one with bot and the other with all other agents. When user enters website he always gets bot as it’s department is only visible. But when the user gets agent after switch, the problem emerges. If the wants to get back to bot, he have to ask the agent forward back, it’s not what I want. I want some behaviour like closing a chat or the tab leads to switching back to bot. We got this behaviour with making window.Rocketchat callback function with setDepartment, but it leads to a bigger problem: if the user goes to another page at same website, livechat’s history will clear. I assume this is a bug, because for example if you open full livechat, then history will be back.