IM Host Object
1.0 Introduction
The IM object allows users to send out Instant Messages from there mashups. It helps you notify users of certain events and acts as a brigde between mashups and users. Supported IM protocols are MSN, AIM, ICQ, Jabber and Yahoo.
Note : The Mashup Server does not ship the library used by the yahoo protocol. If you wish to use the Yahoo protocol, please download the ymsg (Yahoo Instant Messager and Chat protocols) library from and add it to the lib directory of the Mashup Server. Please note that this would need a restart of the server.
1.1 Example
function IMExample() {
var im = new IM("msn");
im.login("username@hotmail.com","password");
im.sendMessage("sendTo@hotmail.com","Hi, This was sent from the WSO2 Mashup Server!");
im.disconnect();
}
2.0 IM Object
2.1 IM Object Constructor
The IM Object which has a single constructor taken in the protocol to be used as an argument to it. Supported values are "msn", "aim", "icq", "jabber" and "yahoo".
2.2 IM login method
By passing needed account details as below into the login mothod, user can successfully login.
var im = new IM("msn");
im.login("username@hotmail.com","password");
2.3 API Documentation
| Member | Description |
| void login (String username, String password) | Uses the username and password as credentials to log the user
into the IM server. When the jabber protocol is used the username
should be of the form username@jabberServer.
im.login(username, password); |
| void sendMessage(String to, String message) | Sends the IM to the specified user.
im.sendMessage( "sendTo@hotmail.com" ,"Hi, This was sent from the WSO2 Mashup Server!"); |
| void disconnect() | Logs the user out of the IM server.
Note: The AIM and ICQ protocols does not allow users to log in and out frequently. In such a situation these two protocols block the user for a breif time (Around 10 Minutes). im.disconnect(); |
3.0 Using the IM object in conjection with the session object
If you expect your mashup to send out IMs frequestly it may not be optimal to login each time you need to send a message. Such situations can be combated by using the IM object in conjunction with the session object. The following is an example of such a usage.
this.scope="application";
function login(){
var im = new IM("msn");
im.login("username@hotmail.com","password");
session.put("im", im);
}
sendMessage.outputType="string";
function sendMessage(){
var im = session.get("im");
if (im != null) {
im.sendMessage("sendTo@hotmail.com","Hi, This was sent from the WSO2 Mashup Server!");
return "Message succesfullt sent";
}
return "Message not sent";
}
function disconnect() {
var im = session.get("im");
if (im != null) {
im.disconnect();
}
}