Agreed, there should be a way to retrieve the wid of the associated window, as well as target commands like /msg to the chat instance you want. For the first, it would be nice if $chat(-1).wid did that (like $get(-1) and $send(-1) in the on FILERCVD etc events). For the second, simply /msg <wid> <text> would do the trick, since no chat, channel or query window name can be a number (or perhaps follow the window manipulation commands format, ie /msg @<wid> <text>).
A workaround for the first issue, however, can be pretty simpler and made to work in ^-prefixed on CHAT events too. Put this in your
first loaded file:
on ^*:chat:$($storecwid):{ }
alias storecwid set -u1 %cwid $wid
Then in your on CHAT events, use %cwid to get the wid of the associated window.