How to listen for events?

Please see:

https://github.com/thekosmix/Java-WhatsappChatBot/blob/master/src/main/java/in/strollup/whatsapp/main/WebWhatsapp.java

But this is some Java browser automation example using Selenium Webdriver and you cannot save the phone number of the incoming messages to contacts for e.g because you don´t have access to contacts on web.whatsapp.com.

So my idea was to do the same with Appium directly on some emulated device instead.