Hi Christiano,
On 7/27/2011 11:08 AM, Cristiano Gavião wrote:
Hi Scott,
yep, you are right... but I have change the ID because I'm trying
to following some tips from this thread: http://community.igniterealtime.org/thread/35976
Now I'm connecting... :D I think that my mistake was to setup the
ids on the product file instead of the launcher... because the
launcher is not updated once created... :(
but the ChatRobotApplication still not working properly...
The method handlePresence is trying to do something that is not
working. It is putting the fromChatId inside the rosterUsers:
public void handlePresence(ID fromID,
IPresence presence) {
System.out.println("handlePresence fromID="+fromID+"
presence="+presence);
IChatID fromChatID = (IChatID)
fromID.getAdapter(IChatID.class);
if (fromChatID != null) {
rosterUsers.put(fromChatID.getUsername() + "@" +
fromChatID.getHostname(), fromID);
}
and later rosterUsers is being compared with the TargetId that
I've setup... If my target is different from my sender, it will
never work... right ?
No...the handlePresence method is/should be called when your
*receiver* is added to your sender's roster after connection (i.e.
and is online/present). For example, if your sender/robot is
identified as
cvgaviao@xxxxxxxxx then the sender (c4bizconsulting@xxxxxxxxx)
should have this method called
public void handlePresence(ID fromID, Presence presence) {
ID == cvgaviao@xxxxxxxxx
...(put cvgaviao@xxxxxxxxx into rosterUsers
}
Then in the code that actually does the send...i.e.
// Get desired user ID from rosterUsers map. This is just
looking for a user that's active and on our contacts list
ID targetID = (ID) rosterUsers.get(originalArgs[2]);
This sets the targetID to the value that was put into rosterUsers by
the handlePresence method (should be ID=cvgaviao@xxxxxxxxx). This
simply builds in the assumption that the receiver is *on the
sender's contact list, and is active/present*. So you might need to
add cvgaviao@xxxxxxxxx to c4bizconsulting@xxxxxxxxx's roster (if
it's not already).
If you want to remove this restriction, and have the sender just
send to any receiver...i.e. one that may or may not be on your
contact list (if that's allowed by the service...I'm not sure
whether gtalk allows delivery of messages to arbitrary receivers or
not these days), then you could change the code to be like this:
ID targetID =
IDFactory.getDefauilt().createID(client.getConnectNamespace(),originalArgs[2]);
// Construct message
String msgToSend = (message==null)?"Hi, I'm an ECF chat
robot.":message;
System.out.println("ECF chat robot example sending to
targetAccount=" + originalArgs[2] + " message="+msgToSend);
// Send message to targetID
client.sendChat(targetID, msgToSend);
Does this make sense? The reason this restriction was put in place
was that sometimes the services restrict message delivery only to
receivers that are on the sender's contact list (to reduce IM spam,
I'm sure).
Scott
|