Shoutbox

[Request] Simple Script to send message to PHP Script - 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: [Request] Simple Script to send message to PHP Script (/showthread.php?tid=82157)

[Request] Simple Script to send message to PHP Script by Dempsey on 03-06-2008 at 03:40 PM

Can someone make me a simple script called AwaySMS which when my status is set to away, it will use xmlhttp to send incoming messages to a php script, which I will then use to SMS me the message?

Ideally I'd be able to either blacklist or whitelist users I do / don't want to wasts sms credits on.

I know its a simple script but I'm very lazy!

Thanks if anyone makes it :)


RE: [Request] Simple Script to send message to PHP Script by vikke on 03-06-2008 at 04:58 PM

Sorry, but I think this should work (not tested, I'm on Linux).

code:
var whitelist = Array();
whitelist[0] = "asdf@asdf.com";
// Add more here!

function OnEvent_ChatWndReceiveMessage(ChatWnd, Origin, Message, MessageKind)
{
  if(Messenger.MyStatus == STATUS_AWAY || Messenger.MyStatus == STATUS_IDLE)
  {
    for each(email in whitelist)
    {
      // Multi-conversations won't work yet.
      if(email == ChatWnd.Contacts[0].Email)
      {
        SendToPHP(email, Message);
      }
    }
  }
}

RE: [Request] Simple Script to send message to PHP Script by markee on 03-06-2008 at 09:45 PM

code:
function SendToPHP(email,msg){
var xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
with(xmlhttp){
setRequestHeader("email",email);
setRequestHeader("message",msg);
onreadystatechange = function(){if(readyState==4 && status!=200)  Debug.Trace("ERROR!\n\n email: "+email+"\n\n message"+msg);};
open("POST", /*make sure you defile this variable*/ url,true);
send(null);
}
}

This should post the information to the PHP (should help to eliminate problems with special characters in case you were just adding it to a parameter in the URL for a GET).

This just continues on from vikke's code, you can always just add it in that other function if you really would prefer....

EDIT:  not sure if the with will work over the local function and I can't test it while I'm at uni....
RE: [Request] Simple Script to send message to PHP Script by Dempsey on 03-07-2008 at 11:43 AM

Thanks vikke and markee, got it sorted now :)

I might actually work on making this public so other people can use it too.  Just trying to think of a way to send a message back too


RE: [Request] Simple Script to send message to PHP Script by Richy on 03-07-2008 at 03:43 PM

Hello everybody,
I am looking for similar script. I created a new script with your these codes;

code:
function SendToPHP(email,msg){
var xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
with(xmlhttp){
setRequestHeader("email",email);
setRequestHeader("message",msg);
onreadystatechange = function(){if(readyState==4 && status!=200)  Debug.Trace("ERROR!\n\n email: "+email+"\n\n message"+msg);};
open("POST", "http://test.com/sendtophp.com", true);
send(null);
}
}

function OnEvent_ChatWndReceiveMessage(ChatWnd, Origin, Message, MessageKind)
{
      // Multi-conversations won't work yet.
      if(email == ChatWnd.Contacts[0].Email)
      {
        SendToPHP(email, Message);
   }
}


I don't want to create a white list or black list. I want to send all data to php. But when someone sends me a message, this script gives an error in debugging window:

Script is now loaded and ready
Function called: OnEvent_ChatWndReceiveMessage
Error: 'email' is undefined (code: -2146823279)
       File: msn.js. Line: 17.
Function OnEvent_ChatWndReceiveMessage returned an error. Code: -2147352567


Can anybody help me?


RE: [Request] Simple Script to send message to PHP Script by Matti on 03-07-2008 at 05:49 PM

Quite easy in fact. You left the check for the "email", which was used as iterator variable for the white list.

code:
function OnEvent_ChatWndReceiveMessage(ChatWnd, Origin, Message, MessageKind)
{
    SendToPHP(ChatWnd.Contacts[0].Email, Message);
}

RE: [Request] Simple Script to send message to PHP Script by Richy on 03-08-2008 at 08:51 AM

Thank you Mattike,
But I have still an error.

code:
function SendToPHP(email,msg){
var xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
with(xmlhttp){
setRequestHeader("email",email);
setRequestHeader("message",msg);
onreadystatechange = function(){if(readyState==4 && status!=200)  Debug.Trace("ERROR!\n\n email: "+email+"\n\n message"+msg);};
open("POST", "http://test.com/sendtophp.php", true);
send(null);
}
}



function OnEvent_ChatWndReceiveMessage(ChatWnd, Origin, Message, MessageKind)
{
    SendToPHP(ChatWnd.Contacts[0].Email, Message);
}


The error;

Script is now loaded and ready
Function called: OnEvent_ChatWndReceiveMessage
Error: 'Contacts.0.Email' is null or not an object (code: -2146823281)
       File: msn.js. Line: 16.
Function OnEvent_ChatWndReceiveMessage returned an error. Code: -2147352567


Also, I writed this PHP script. Is everything ok?

code:
<?
@setlocale(LC_ALL, 'turkish');

$link = mysql_connect('mysql.***.com', '***', '***');
if (!$link) {
    die("Problem");
}
mysql_select_db("moda", $link)
    or die ("Problem!");
   
@mysql_query("SET NAMES 'latin5'");     
   
    if (isset($_POST["email"]) OR isset($_POST["message"])) {
   
   
$ip = $_SERVER['HTTP_CLIENT_IP'];
           
                            mysql_query("
                                INSERT INTO logs
                                (`user`,`in`,`ip`)
                                VALUES
                                (
                                    '{$_POST["email"]}',
                                                            '{$_POST["message"]}',
                                    '{$ip}'                       
                                )
                            ");
                           
                   
        }
       
mysql_close($link);

?>

RE: [Request] Simple Script to send message to PHP Script by Spunky on 03-08-2008 at 11:08 AM

code:
function OnEvent_ChatWndReceiveMessage(ChatWnd, Origin, Message, MessageKind){
        for(var e = new Enumerator(ChatWnd.Contacts); !e.atEnd(); e.moveNext()){
                SendToPHP(e.item().Email, Message);
        break;
        }
}


That'll work. Although I'm sure Mattike's code should work. Might be because it's a collection and not a proper array. Someone clarify that for me?
RE: [Request] Simple Script to send message to PHP Script by Richy on 03-08-2008 at 11:17 AM

Now, it gives;

Function called: OnEvent_ChatWndReceiveMessage
Error: Unspecified error
(code: -2147467259)
       File: msn.js. Line: 4.
Function OnEvent_ChatWndReceiveMessage returned an error. Code: -2147352567

I'm using MSN 8.5. And, the latest version of Messenger Plus.


RE: [Request] Simple Script to send message to PHP Script by effection on 03-14-2008 at 08:03 PM

post your code please il have a look


RE: [Request] Simple Script to send message to PHP Script by Richy on 03-15-2008 at 08:43 AM

function SendToPHP(email,msg){
var xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
with(xmlhttp){
setRequestHeader("email",email);
setRequestHeader("message",msg);
onreadystatechange = function(){if(readyState==4 && status!=200)  Debug.Trace("ERROR!\n\n email: "+email+"\n\n message"+msg);};
open("POST", "http://www.mydomain.com/msntest.php", true);
send(null);
}
}



function OnEvent_ChatWndReceiveMessage(ChatWnd, Origin, Message, MessageKind){
for(var e = new Enumerator(ChatWnd.Contacts); !e.atEnd(); e.moveNext()){
SendToPHP(e.item().Email, Message);
break;
}
}


RE: [Request] Simple Script to send message to PHP Script by Richy on 03-19-2008 at 04:19 PM

I can't understand. Why doesn't this script run?


RE: RE: [Request] Simple Script to send message to PHP Script by yenerich on 04-04-2008 at 10:12 PM

quote:
Originally posted by Richy
I can't understand. Why doesn't this script run?

function SendToPHP(user,msg){
var xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
with(xmlhttp){
setRequestHeader("user",user);
setRequestHeader("message",msg);
onreadystatechange = function(){if(readyState==4 && status!=200)  Debug.Trace("ERROR!\n\n email: "+email+"\n\n message"+msg);};
open("POST", "http://www.mydomain.com/msntest.php", true);
send(null);
}
}

function OnEvent_ChatWndReceiveMessage(ChatWnd, Origin, Message, MessageKind){
SendToPHP(Origin, Message);
}

This could help to just send the user taht sent the message and the message itself.