Need Help With Sending A Message - Printable Version
-Shoutbox (https://shoutbox.menthix.net)
+-- Forum: MsgHelp Archive (/forumdisplay.php?fid=58)
+--- Forum: Messenger Plus! for Live Messenger (/forumdisplay.php?fid=4)
+---- Forum: Scripting (/forumdisplay.php?fid=39)
+----- Thread: Need Help With Sending A Message (/showthread.php?tid=80346)
Need Help With Sending A Message by flashmaniac on 12-23-2007 at 03:13 AM
Hello Everyone.
Im Having Trouble With This Function.
[boolean] SendMessage(
[string] Message
);
I Dont Get How To Make It Send A Message, It Always Wants Me To Add Something In Or Take Something Out.
Someone Help Me!!!!!!!
RE: Need Help With Sending A Message by Matti on 12-23-2007 at 09:25 AM
SendMessage is a child function of the ChatWnd object. Therefore, to use this function, you first need the object. There are plenty of functions which return a ChatWnd object instance, it's up to you in what situation you need to send the message!
- You can send a message when a chat window is created by using the ChatWnd parameter of OnEvent_ChatWndCreated.
- You can send a message when the user sends or receives a message by using the ChatWnd parameter of OnEvent_ChatWndSendMessage or OnEvent_ChatWndReceiveMessage.
- You can send a message when the user clicks the Scripts button in a chat window and selects a menu-item from the script menu by using the OriginWnd parameter of OnEvent_MenuClicked.
- You can send a message after you've opened a chat window with Messenger.OpenChat():
code: var ChatWnd = Messenger.OpenChat("someone@hotmail.com");
ChatWnd.SendMessage("Hello Someone!");
- You can loop through the opened chat windows by enumerating the Messenger.CurrentChats collection and send messages.
- ...
Or in other words: please be a bit more specific when you want your script to send a message.
RE: Need Help With Sending A Message by flashmaniac on 12-24-2007 at 12:10 AM
Thanks!, Can You Give Some Examples Of The Ones Up Above?
These Ones:
You can send a message when a chat window is created by using the ChatWnd parameter of OnEvent_ChatWndCreated.
You can send a message when the user sends or receives a message by using the ChatWnd parameter of OnEvent_ChatWndSendMessage or OnEvent_ChatWndReceiveMessage.
You can send a message when the user clicks the Scripts button in a chat window and selects a menu-item from the script menu by using the OriginWnd parameter of OnEvent_MenuClicked.
Im A Begginner And Not Very Advanced So I Dont Really Know How These Functions Work.
RE: Need Help With Sending A Message by Matti on 12-24-2007 at 10:55 AM
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.
- 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
);
- 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
}
- 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.
- 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.
|