webchat: refactor into handler.js