refactor rest.chat