Catalina Messages app: run applescript on receive new message & when the message is read?
You could try Jared, which is an iMessage Chat Bot: https://github.com/ZekeSnider/Jared

There's a sample plugin in the repository, yet this requires some Xcode knowledge. 

It seems Apple removed the handler because they launched iMessage for Business https://developer.apple.com/business-chat/. If you look into the API, there‘s a „Message received“ handler, so it may be possible using that service, but probably not a good idea for personal stuff.

Edit2:
Back to the SQL solution, this article dives pretty deep in explaining: https://stmorse.github.io/journal/iMessage.html

Edit3:
I found the following repositories based on nodejs :
https://github.com/CamHenlin/imessageclient
https://github.com/CamHenlin/imessagebot