How do I set the presence for my bot using Java? (Either an away message or available with a status message.)
I could not figure out from the Javadocs how to do this, and would appreciate some guidance.
Thanks,
Michael
How do I set the presence for my bot using Java? (Either an away message or available with a status message.)
I could not figure out from the Javadocs how to do this, and would appreciate some guidance.
Thanks,
Michael
Hi,
What is your question?
What are the exceptions your are getting?
What are your trying to accomplish?
What language and environment are you using?
Please provide us with as much details as possible so that we can help you better.
Thanks.
Hi
Thanks for the prompt response, my question was how to obtain the status text, but I figure it out. Its just that the Java API is a bit convoluted.
Im trying to obtain the status message, I should expect an AccBartItem, seems like those contacts that do not have a status message, the application returns an Integer value, when it does, it returns an AccBartItem, so I was getting confused, by a whole bunch of exceptions, until I tested data each of the get's in arg5 (getObject, getInt, getString,etc.)
The problem would have been easier to debug if when there is no status text, instead of returning an Integer it returns an 'empty' AccBartItem, so I dont get an exception, and make the code flow less exception driven, like if there is an exception, then try getting an int value if there is another exception, try getting a string value.
Is there a way of knowing before hand what data type to expect in the return of a particular call?
This is the particular code involved
public void OnUserRequestPropertyResult(AccSession arg0, AccUser arg1, AccUserProp arg2, int arg3, AccResult arg4, AccVariant arg5) {
log.info("OnUserRequestPropertyResult: " + arg4);
if (arg2.equals(AccUserProp.StatusText)) {
personalMessagesObtained++;
try {
AccBartItem item = (AccBartItem) arg5.getObject("AccBartItem");
String status = item.getDataObject().getString();
String userName = arg1.getName();
personalMessages.add(userName + ":" + status);
System.out.println(userName + ":" + status);
} catch (AccException e) {
// TODO Auto-generated catch block
//e.printStackTrace();
}
}
if(personalMessagesObtained == personalMessagesRequested){
System.out.println("Messages are ready");
}
}
Use session.setAwayMessage or session.setStatusText.
For status text create an accbartitem from the session and set the dataobject property with a text variant.
So would this be correct?
(status is either "away" or "available")
public void setStatus(String status, String message) {
try {
if (status.equalsIgnoreCase("away")) {
AccIm awaymessage = session.getAwayMessage();
awaymessage.setText(message);
session.setAwayMessage(awaymessage);
}
else if (status.equalsIgnoreCase("available")) {
AccBartItem statustext = session.getStatusText();
statustext.setDataObject(new AccVariant(message));
session.setStatusText(statustext);
}
} catch (Exception ex) {
System.out.println("Error setting status message.");
}
}
Is there an easier way to do this? It just seems so cumbersome.
Thanks for your help,
Michael
Actually, the method I just posted doesn't work. The lines retrieving the away message/status message throw exceptions.
In my case those contacts that do not have a status message or away message, it returns an int value instead of a AccBartItem or AccIm, that produces the exception. in another post in this thread I post the code that worked for me.
You will have to 'cascade' try catch'es. try using the getint that will work if your contact has not messages, on the catch portion use the getstatus, if that doesnt throw an exception, is because your contact has a set message.
Either
com.aol.acc.AccException: IAccSession_GetStatusText
Hashcode: 21539363
or
com.aol.acc.AccException: IAccSession_GetAwayMessage
Hashcode: 21185076
com.aol.acc.AccException: IAccSession_GetStatusText
ACC_E_TYPEMISMATCH
com.aol.acc.AccException: IAccSession_GetAwayMessage
ACC_E_NO_DATA
Not sure where ACC_E_TYPEMISMATCH is coming from. Maybe post a description of what your code is doing or a code snippet (the previous snippet was doing a SET).
ACC_E_NO_DATA in a non-fatal error meaning the value is empty (i.e., an away message is not set).
The only thing the code is doing is setting an away message or status message. The code snippet I posted before is all there is. In order to set the status message I have to get the current message, change the text, and resend it to the server.
While ACC_E_NO_DATA may be a non-fatal error, the fact is, it's throwing an exception which is preventing my code from continuing. Am I supposed to enclose every line of code in its own try/catch?
Michael
OK, we'll investigate ACC_E_TYPE_MISMATCH.
Regarding exception handling: yes, it's good practice to wrap any methods that are reasonably expected ever to raise an exception with try/catch.
I think one can pass a string directly without having to create an accBartItem.
I'm still waiting for a response on this...
Asking our Java expert to respond so we get the syntax exactly right...
Me too
Any solution to this. my application requires obtaining status messages from users, but I get the same exceptions. PLEASE HELP!
Thanks