I'm not sure whether you want to call your function only if the contact initiates the chat or also when you start a convo and your contact responds for the first time.
My most logical guess is the first (contact initiates chat), so i wrote a bit of code for that:
code:
var aNewChat = new Array();
var aSent = new Array();
function OnEvent_ChatWndCreated(oChatWnd)
{
aNewChat[oChatWnd.Handle] = 1; //mark the convo as a new one
MsgPlus.AddTimer("NewChat" + oChatWnd.Handle, 100); //set a timer to remove "new" mark
}
function OnEvent_Timer(sTimerId)
{
if (sTimerId.substr(0, 7) == "NewChat")
{
delete aNewChat[sTimerId.substr(7)]; //remove "new" mark
}
}
function OnEvent_ChatWndSendMessage(oChatWnd, sMessage)
{
aSent[oChatWnd.Handle] = sMessage; //store last sent message for the chat window
}
function OnEvent_ChatWndReceiveMessage(oChatWnd, sOrigin, sMessage, eMessageKind)
{
if (sMessage == aSent[oChatWnd.Handle]) //check if you sent the message yourself
{
delete aSent[oChatWnd.Handle]; //if it was your message, delete it from the array
} else {
if (aNewChat[oChatWnd.Handle] == 1) //check if it's a "new" convo
{
//do your stuff here
}
}
}
This code will do your stuff there if a contact sends a message which opens a chat on your side, or in the quite unlikely scenario where a contact sends you a message within 100ms after you opened a convo with them.