Extract IM functionality into a node module

The CLI is changed to use the newly introduced library. The protocol did not change, so you should be able to chat with previous clients too!