Discourse Chatbot solved a similar challenge with current code without needing any specific changes in core, have you taken a look at my solution?