This script detects what window the computer it is running on is focused into, and logs when it changes, from a quick search, but I don't have experience with it, so I can't give a exact bit of code, but I can give a psuedocode path.
1 - Have this script running on every admins computer.
2 - Assign a variable to each chat, let's call it human focus for this. When a chat is initially opened, human focus is 0, signalling for this chatbot to be active.
3 - When this script detects a human focusing into the window of a specific chat, set that chats 'human focus' to 1, signalling for the chatbot to be disabled.
3.5 - If the human sends a message, set 'human focus' to 2.
4 - When they shift focus away, if 'human focus' is 1, set it back to 0, reactivating the chatbot, if not, do nothing.