errbot icon indicating copy to clipboard operation
errbot copied to clipboard

get_jid_from_message not returning JID in groupchat

Open joshuatobin opened this issue 14 years ago • 9 comments

Hi I'm wondering if you've heard any issues of get_jid_from_message not returning properly when in a chat room. I've become (probably too) dependent on this function for a bunch of my err- plugins. Right now the only way I can successfully get the JID of the user sending a message is by PM'ing errbot. But if I try to retrieve the JID of the user sending a message in a chat room, it always returns the JID of the room, rather than the user.

joshuatobin avatar Nov 09 '12 17:11 joshuatobin

Hi,

Can you try to revert this one : 3ec34f0466d5c008ccd83f7cadf3690b251bc736 ? Are you using the hipchat backend by any chance ?

Thanks

gbin avatar Nov 09 '12 17:11 gbin

Yes I'm using the hipchat backend. I'm not 100% sure what is going on. I've tried parsing the mess object and pulling the JID of the user that is sending the message but still not luck. It always returns a string of 'josh tobin' rather than the expected 12345_1235 format. :/

joshuatobin avatar Nov 09 '12 17:11 joshuatobin

I'm actually seeing this on 1.6.3 as well. I'm not sure if its hipchat altering the message.

joshuatobin avatar Nov 09 '12 19:11 joshuatobin

Only some ideas as this is quite similar to #82

I'm not familiar with hipchat, however this looks like the backend is not sending the non-standard sender node with the real JID in the chat message and instead working as regular XMPP server in accordance with XEP-0045. The only way I know how to retrieve user's JID as defined in XEP is to handle presence stanza sent when an user connects to MUC (and you have to be admin on an owner of the MUC in order to retrieve the JID from the server this way.)

In this case the 'parsing' of the message fallbacks to my code returning muc@room/nick instead of the expected JID. Without my code it fallbacks to returning the nick of the chat member (similar to the resource part of the full JID). Had the sender node been present in the message stanza, it would have returned the expected value.

apophys avatar Nov 09 '12 23:11 apophys

I was having an issue where the bot wasn't ignoring messages that came from itself (in group chat). This was causing an infinite loop sometimes.

To workaround this issue I modified callback_message in jabber.py as follows (since we can't seem to rely on JID):

    # Ignore messages from myself
    if CHATROOM_FN == get_sender_username(mess):
        logging.debug('Ignoring a message from myself')
        return

SecondReality avatar Dec 17 '12 03:12 SecondReality

I'm also experiencing something similiar in HipChat. I've confirmed @SecondReality's workaround.

Here is some sample debug output for more detail.

Given the following config settings:

DEBUG:config.BOT_IDENTITY['username']: [email protected]
DEBUG:config.CHATROOM_FN: Err Bot

In a group chat room, it looks like all messages are coming from the room itself:

DEBUG:mess.getFrom().getStripped(): [email protected].

And the sender can be the bot itself...

DEBUG:get_sender_username(mess): Err Bot

This is where the trouble arises if the callback_message handler is listening for a token that it then responds to with a message containing that token.

err has changed a lot since I last took a look at it so I'm not sure where would be best to patch it to fix this issue right now. Without much thought, I patched my two plugins so I could use them without HipChat banning them after they've spun themselves into infinite loops :goberserk:

krismolendyke avatar Dec 18 '12 04:12 krismolendyke

Now that I have some spare time (3 weeks vacation, wheee!) I went ahead and read through XEP-0045, which describes how MUC works.

It's important to note that people joining a MUC are basically given a "new" JID, a so called "occupant JID" specific to that MUC. These are in the form of room@conference/nickname. This indeed means occupants real JID's are actually hidden.

There is one exception to this rule, which is in the case of non-anonymous rooms. Upon joining a non-anonymous room, the service will send the real JID's of the occupants along when it sends the presence information:

If the room is non-anonymous, the service MUST send the new occupant's full JID to all occupants using extended presence information in an element qualified by the 'http://jabber.org/protocol/muc#user' namespace and containing an child with a 'jid' attribute specifying the occupant's full JID

(@apophys explains what happens when you join a MUC very nicely in #82 as well)

It is my understanding that basically, there is no guaranteed way to get the real JID from a MUC, because the XMPP (draft) standard for MUC specifically states users are anonymous, unless the room is set to non-anonymous.

However, even without knowing the full real JID, it is still possible to reply privately, as @apophys explains in #82, by sending to the occupant JID with a type of "chat", as described in 7.5 Sending a Private Message:

Since each occupant has its own occupant JID, an occupant can send a "private message" to a selected occupant via the service by sending a message to the intended recipient's occupant JID. The message type SHOULD be "chat" and MUST NOT be "groupchat", but MAY be left unspecified (i.e., a normal message). This privilege is controlled by the "muc#roomconfig_allowpm" room configuration option.

This basically gives you a private chat with that person, without ever seeing their real JID.

So, turning this all back to the issue at hand, I think get_jid_from_message should either only work for messages of type "chat" (not in favor of this) or return the occupant JID when it is of type "groupchat". Additionally, in case of the HipChat backend, it may need to return something different there, as HipChat does some funky stuff with JID's. We'd need to delve into that and see how HipChat reacts in all cases.

@gbin what are your thoughts on this?


PS. @SecondReality, @krismolendyke, I made a seperate issue out of your comments to keep this discussion focussed on the MUC JID problem. Although your observations relate to this issue in that you indeed can't seem to always rely on the JID I think the core of your comments are more like a feature request to easily filter messages coming from self.

zoni avatar Dec 18 '12 12:12 zoni

I put an implementation of the "7.5 Sending a Private Message" in the sleekxmpp branch instead of trying to guess the private JID of the participants. It doesn't work under hipchat but can you try it out on other implementations ?

Thx

gbin avatar Dec 27 '12 17:12 gbin

this is really old and this area of the bot completely change, please reopen another bug if this is still true with the new implementation

gbin avatar Jul 10 '15 05:07 gbin