You can store the chat window in a variable on message sent/received and do it that way.
Example:
jscript code:
// Variable to store the chat window
var oChatWnd;
function OnEvent_ChatWndDestroyed(pChatWnd) {
// If a chat window is closed check to see if it is the current stored window, if so remove it
if (typeof oChatWnd === 'object' && oChatWnd.Handle === pChatWnd.Handle) oChatWnd = null;
}
function OnEvent_ChatWndSendMessage(pChatWnd, sMessage) {
oChatWnd = pChatWnd;
}
function OnEvent_ChatWndReceiveMessage(pChatWnd, sOrigin, sMessage, nMessageKind) {
oChatWnd = pChatWnd;
}
Therefore when you go to send a message using your script make sure you check that
jscript code:
typeof oChatWnd === 'object'
Or else your script will fail.