How to Display your Away Message on a Web Page

Having your blog display your AIM away message using the WIM API is a pretty simple operation. If you don't have an API key, you can grab one from developer.aim.com.

Follow these steps to get it up and running:

  1. In the head of your document, paste this line:
    <script type="text/javascript" src="http://o.aolcdn.com/aim/web-aim/aimapi.js"></script>
  2. Next, paste this code into your document directly after the previous script element:
    <script type="text/javascript">
    // Register a callback for the getPresenceInfo transaction
    AIM.params.callbacks.getPresenceInfo = ["awayMessageWidget.displayAwayMessage"];
    var awayMessageWidget = {
    	// Our init function, called from the window's onload event.
    	init: function() {
    		// Our API key. Be sure to change this to your own
    		AIM.params.wimKey = "sc1OCxN4ASAnSDj1";
    		// Call the getPresenceInfo transaction
    		AIM.transactions.getPresenceInfo();
    	},
    	// This function is the callback for our transaction. It takes the json response from the host as its argument
    	displayAwayMessage: function(json) {
    		// Only do stuff if the back-end tells us everything is Ok
    		if(json.response.statusCode==200) {
    			// Only do stuff if the satus of the user is "away"
    			if(json.response.data.users[0].state == "away") {
    				// grab the away message from the response and stick it in the "myAwayMessage" element.
    				document.getElementById("myAwayMessage").innerHTML = "My away message: " + json.response.data.users[0].awayMsg;
    			}
    		}
    	}
    }
    // attach the init function to the onload event of the window
    window.addEventListener?window.addEventListener("load",awayMessageWidget.init,false):window.attachEvent("onload",awayMessageWidget.init);
    </script>
  3. Finally, paste this line into the body of your document where you want your away message to appear. Replace schipman8 with your own AIM ID (unless, of course, you'd rather see my away messages...).
    <div id="myAwayMessage" class="AIMPresenceWidget schipman8"></div>

If you aren't away or the backend returns an error code, nothing will be displayed. Feel free to modify this code to your hearts content. Enjoy!

slayeroffice Displaying an Away Message on a Web Page
version 1.0
last revision: 12.13.2006
http://slayeroffice.com