Sure, you can.
The event you should look for is
OnEvent_ChatWndReceiveMessage (be aware that it will detect your own messages in this event).
You can then do anything based on what is sent to you.
You can download the complete Scripting Documentation
here.