2

There is a way to get the user's nick(roomName@domain.com/nick) in the chatroom according to the document, but how can I get the user's real jid(name@domain.com/resource_name)? is it possible according to XMPP protocol?

woosley. xu
  • 182
  • 1
  • 12

1 Answers1

2

You can unless the room is anonymous. The Jabber protocol makes it possible that people in a chat room may be anonymous so that you cannot get back to their real JID. This is also why it provides a private message chat within the rooms, so you can still private message someone who has done this.

I have some code that does this in Bot::Backbone::Service::JabberChat:

# Figure out who sent this message
my $from_user = $room->get_user($xmpp_message->from_nick);

# Prefer the real JID as the username
my $from_username = $from_user->real_jid // $from_user->in_room_jid;
my $from_nickname = $from_user->nick;

See AnyEvent::XMPP::Ext::MUC::User and AnyEvent::XMPP::Ext::MUC::Room for more details.

zostay
  • 3,985
  • 21
  • 30
  • 2
    Actually I read your module code before I asked here :) Anyway, I find I have to grant my bot account admin privilege to see the real JID and now I can get it by using this code. Thanks for the help! – woosley. xu Jul 31 '12 at 03:14
  • Hmm, OpenFire (and it's 6+ year old predecessors) must allow `real_jid` to work for all accounts by default. That's all I've actually tested the code on. – zostay Jul 31 '12 at 13:35