What happened to the Messenger Plus! forums on msghelp.net?
Shoutbox » MsgHelp Archive » Messenger Plus! for Live Messenger » Scripting » Need Help With Sending A Message

Need Help With Sending A Message
Author: Message:
Matti
Elite Member
*****

Avatar
Script Developer and Helper

Posts: 1646
Reputation: 39
32 / Male / Flag
Joined: Apr 2004
RE: Need Help With Sending A Message
It's just a matter of finding a way to retrieve a ChatWnd object through one of the functions or events Plus! Live gives you. When you have a ChatWnd object, you'll have to check if you can send a message first with the ChatWnd.EditChangeAllowed property and then, you can send a message to it.

I'll give you one example about how you should find such things out.
quote:
Originally posted by flashmaniac
You can send a message when a chat window is created by using the ChatWnd parameter of OnEvent_ChatWndCreated.

  1. The scripting documentation is your best friend! Look up the event!
    quote:
    Scripting Documentation > Events > Messenger Events > OnEvent_ChatWndCreated

    The OnEvent_ChatWndCreated event is fired when a new chat window is created.

    Syntax
    code:
    OnEvent_ChatWndCreated(
        [object] ChatWnd
    );

  2. Now we know how our function declaration should be built. Plus! Live will try to find a function called OnEvent_ChatWndCreated in your script and when a chat window is created, it'll send a ChatWnd object as parameter to your function. Using this information, you can already built this event in your script:
    code:
    function OnEvent_ChatWndCreated(oChatWnd) {
       //oChatWnd will be a ChatWnd object for the chat window that was created
    }
  3. Because we want to send a message when the chat window is created, we'll need to know more about the ChatWnd.SendMessage() function. The scripting documentation says this:
    quote:
    Scripting Documentation > Objects > ChatWnd Object > SendMessage
    The ChatWnd::SendMessage function sends a message to the contacts currently present in the chat window.

    Syntax
    code:
    [boolean] SendMessage(
        [string] Message
    );
    Return Value
    If the message is sent successfully, the return value is true, else, the return value is false.
    ...
    Remarks
    ...
    The EditChangeAllowed property should be checked before this function is called.
  4. Now we know that the SendMessage function accepts one parameter Message of the type string, which means that it's a literal value. The return value of the function is a boolean value (true or false) defining if the function succeeded in sending the message or not. This value is important because you can't always be sure if the message was actually sent, since there are cases where Plus! can't send it. One of these cases is that the chat window was destroyed, but that would be very unlikely because in our case of OnEvent_ChatWndCreated, it was just created! However, in a serious script, you should take every possibility in account, but I won't go about that now. The other case is that the typing area is disabled because the contact has been blocked by the user. Therefore, the remarks state that you should first check if the ChatWnd.EditChangeAllowed property is set to true. Only then you know you can send a message. This brings us to the final piece of code:
    code:
    function OnEvent_ChatWndCreated(oChatWnd) {
       if(oChatWnd.EditChangeAllowed) { //Check if the typing area is available
          var Result = oChatWnd.SendMessage("Hello there!"); //Send the message
          Debug.Trace("SendMessage returned: "+Result); //Send the result to the script debugger, if you want to check if everything went right
       }
    }

And with this way too long manual, you should be able to find out the other things yourself! Because that's what scripting (and programming in general) is all about: combine the things you need in such a way that you can get the right result. ;)
Plus! Script Developer | Plus! Beta Tester | Creator of Countdown Live | Co-developer of Screenshot Sender 5

Found my post useful? Rate me!
12-24-2007 10:55 AM
Profile E-Mail PM Web Find Quote Report
« Next Oldest Return to Top Next Newest »

Messages In This Thread
Need Help With Sending A Message - by flashmaniac on 12-23-2007 at 03:13 AM
RE: Need Help With Sending A Message - by Matti on 12-23-2007 at 09:25 AM
RE: Need Help With Sending A Message - by flashmaniac on 12-24-2007 at 12:10 AM
RE: Need Help With Sending A Message - by Matti on 12-24-2007 at 10:55 AM


Threaded Mode | Linear Mode
View a Printable Version
Send this Thread to a Friend
Subscribe | Add to Favorites
Rate This Thread:

Forum Jump:

Forum Rules:
You cannot post new threads
You cannot post replies
You cannot post attachments
You can edit your posts
HTML is Off
myCode is On
Smilies are On
[img] Code is On