I won't give you simple copy-paste code because I think it's better for you to learn it yourself.
You'll first need an event to capture the message received. Then, you'll need to compare the Origin to all contact names in your list. When you have a match, you use the e-mail address of that contact to open a chat window and send a message.
So, you need an OnEvent_ChatWndReceiveMessage, which first checks that the message isn't yours by comparing Origin to Messenger.MyName. Then, you need to loop through ChatWnd.Contacts and check the name of each contact in the conversation. If you have a match, you store the contact object and break the loop. Then, you open a chat with "var oChatWnd = Messenger.OpenChat(Contact.Email)" and then you use "oChatWnd.SendMessage('Message')" to send the message.
Give it a try!