How to tell Mac OS Messages.app to go online from the command line? I observed that quite often some accounts on Messages.app (Mac OS Sierra) may become offline and I want to automate the reconnection when I connect to VPN.

So, the question is: what command line commands should I run in order to start Messages.app and restore connections. Note: Messages.app may already be opened but my account may be offline.
Here is the command for terminal:

osascript -e 'tell application "Messages" to log in'