How to hang event handlers on the JXA (JavaScript for Automation) in macOS?

I want to hang up the handler for incoming message app Messages. From the documentation, to me personally, nothing is clear. Written only a few words about the parameters, and what to hang and how - no. Online information on handlers is almost there, and if there is something not working. Perhaps there are knowledgeable?
June 7th 19 at 14:41
1 answer
June 7th 19 at 14:43
A good collection of recipes: JavaScript for Automation Cookbook.

To listen to events through Messages - Preferences - AppleScript handler.

On stackoverflow dismantled.

Find more questions by tags JavaScriptmacOS