It is easy to add windows live chat to your website between yourself and your visitors. First you have to go here and select the option that says “Allow anyone on the web to see my presence and send me messages.” and click Save. Now your website visitors will be able to chat with you. Then you select “Create HTML” and choose one of the 3 options available for either displaying a chat window or just an online/offline image that when clicked will direct your visitor to a dedicated chat window.
If you want to hack the code a little bit here are some examples:
By using javascript you can display your own image instead of the default green buddy icon like this:
<script type=”text/javascript”>
function msn_status(json) {
if ( (json.status != ‘Offline’) && (json.result.code == 200) ) {
document.statusimage.src = ‘Online.gif’;
}
}
</script>
<a target=”_blank” href=”http://settings.messenger.live.com/Conversation/IMMe.aspx?invitee=<insert_your_id>@apps.messenger.live.com&mkt=en”>
<img style=”border-style: none;” name=”statusimage” src=”Offline.gif”/>
</a>
<script type=”text/javascript” src=”http://messenger.services.live.com/users/<insert_your_id>@apps.messenger.live.com/presence/?cb=msn_status”></script>
In any case replace <insert_your_id> with the id number you will get from the live messenger web settings -> “Create HTML” page that I mentioned above.
more info on the available data can be found here:
http://msdn.microsoft.com/en-us/library/bb936687%28v=MSDN.10%29.aspx
http://msdn.microsoft.com/en-us/library/bb936688%28v=MSDN.10%29.aspx
http://msdn.microsoft.com/en-us/library/cc742832%28v=MSDN.10%29.aspx
You can also use PHP. In php ver. 5.2 and above there is a function called json_decode tha will be very helpfull. But in earlier versions you can use some code like this:
echo msn_status();
function msn_status() {
if ( !function_exists(‘json_decode’) ) {
function json_decode($json) {
// Author: walidator.info 2009
$comment = false;
$out = ‘$x=’;
for ($i=0; $i<strlen($json); $i++)
{
if (!$comment)
{
if ($json[$i] == ‘{‘) $out .= ‘ array(‘;
else if ($json[$i] == ‘}’) $out .= ‘)’;
else if ($json[$i] == ‘:’) $out .= ‘=>’;
else $out .= $json[$i];
}
else $out .= $json[$i];
if ($json[$i] == ‘”‘) $comment = !$comment;
}
eval($out . ‘;’);
return $x;
}
}
$url = ‘http://messenger.services.live.com/users/<insert_your_id>@apps.messenger.live.com/presence’;
$file = @ fopen(($url),”r”) or die (“Can’t read input stream”);
$json = fread($file,1000);
$obj = json_decode($json);
$status = $obj['status'];
$resultcode = $obj['result']['code'];
if ( ($status != ‘Offline’ ) and ($resultcode == 200 ) ) {
return “ONLINE”;
}
else {
return “OFFLINE”;
}
}
thanks goes to the guy on this post:
http://www.php.net/manual/en/function.json-decode.php#91216
Tags: javascript, json, live messenger, php