A recent feature addition that I've been working on for Altos Research requires that our server-side application be aware of our LivePerson on-line support status. Although LivePerson provides sample client-side javascript utilities for this purpose, there are times when your sever app just needs to know if your support representatives are online, busy, or offline.
My solution to this comes from a bit of reverse engineering of the javascript library that LivePerson makes available and is described in one of their help documents.
The solution consists of three classes - one of which is a public domain utility named ImageInfo, which is available for download. The first of the new classes written for this is a simple enum type to hold the possible status values:
public enum LivePersonStatus {
offline, online, unknown, occupied
}
The work is done using a simple class with a single static method - getStatus - which takes your LivePerson account number as input:
public static LivePersonStatus getStatus(Integer lpNum) {
if ( lpNum == null ) return LivePersonStatus.unknown;
URL u = null;
try {
u = new URL("http://server.iad.liveperson.net/hc/"+lpNum.toString() + "/?cmd=repstate&site="+lpNum.toString()+"&useSize=true&d="+ System.currentTimeMillis());
ImageInfo i = new ImageInfo();
i.setInput(u.openStream());
if ( i.check()) {
int width = i.getWidth();
if ( width == 40 ) return LivePersonStatus.online;
else if ( width == 50 ) return LivePersonStatus.offline;
else if ( width == 60 ) return LivePersonStatus.occupied;
else return LivePersonStatus.unknown;
}
} catch (MalformedURLException e) {
//LOGGER.warn("URL problem with u: " + u);
return LivePersonStatus.unknown;
} catch (IOException e) {
//LOGGER.warn("URL problem with u: " + u);
return LivePersonStatus.unknown;
}
return LivePersonStatus.unknown;
}
Once the method returns the current status, you are free to take appropriate action. Enjoy.





