errbot icon indicating copy to clipboard operation
errbot copied to clipboard

get_jid_from_message & DIVERT_TO_PRIVATE message from MUC (groupchat)

Open apophys opened this issue 14 years ago • 8 comments

When I try to execute a command from MUC while the command is in the DIVERT_TO_PRIVATE tuple, get_jid_from_message resolves only resource (in this context the nickname) and the response is addressed to that resource only resulting in invalid stanza.

Correct addressing, according to XEP-0045 would be to reply to 'from' attribute of groupchat message, if the idea is to reply with private message in the chatroom.

DEBUG:deduced the jid from the chatroom to apophys DEBUG:Message filtered thru JabberClient :

apophys avatar Oct 09 '12 22:10 apophys

pull request #83

apophys avatar Oct 09 '12 22:10 apophys

I tried to reproduce it on Hipchat. If I put ('help',) in DIVERT_TO_PRIVATE and chat with err in a MUC, it actually calls correctly get_jid_from_message because build_reply is called with private = True there. It is the intended behavior and it works for me, I receive a pure private message from Err with the To correctly put to the original sender (me) in the MUC.

Now I didn't know that private messages in a MUC was possible which is a separate issue and possibly an improvement.

gbin avatar Oct 14 '12 19:10 gbin

This issue isn't about sending a command from DIVERT_TO_PRIVATE in private message in a MUC. It's about reply generated by err when I send '!' to MUC directly.

What happens is that err founds the command to be in DIVERT_TO_PRIVATE, therefore is trying to extract JID from the current message stanza. The thing is, in from attribute of this stanza is sender listed as muc@conference/nick. When get_jid_from_muc is called, it splits the bare JID and returns 'resource' which is in this case nickname of the MUC participant who sent this message.

Err at this point is trying to send reply to 'resource' as I wrote in the comment when I opened this issue. Resulting in remote-server-not-found error.

I do not know what additional information the hipchat server is sending, however based on the code I guess err is able to resolve the real JID of participant and response directly as

However it is possible to address MUC participants directly, given that certain requirements are met.

Generally, when an user, let's call him P, joins MUC room, several things happen:

  • P sends presence stanza to [email protected]
    • server distributes this stanza to every participant
  • all participants are responding with presence stanza to P
    • part of this presence is node x
    • if P has affiliation of 'owner' or 'admin', x node contains also the attribute jid

Nodes:

<x xmlns="http://jabber.org/protocol/muc#user">
    <item affiliation="owner" role="moderator"/>
</x>

<x xmlns="http://jabber.org/protocol/muc#user">
    <item affiliation="owner" jid="[email protected]/resource" role="moderator"/>
</x>

The problem is those presence stanzas are not handled in any useful way and they are not redirected to plugins or wherever else.

The fix I made is intended as a form of fallback to respond by private message as an participant in MUC and not directly to sender's real JID.

apophys avatar Oct 14 '12 21:10 apophys

Wait, first I don't reproduce your bug on hipchat, I put the real message I received from hipchat for a MUC message in a testcase : 7bdeab4a84dca5e49121b4d5d0b093efdad23d11 can you check if it looks like that also on your side ?

gbin avatar Oct 14 '12 22:10 gbin

I was able to reproduce this on my own jabber server. Err indeed tries to send to the resource of the MUC, which isn't correct. This does work on HipChat, which is why I didn't catch this when I implemented this feature, probably because HipChat accounts have their resource set to "firstname lastname" which HipChat is able to interpret again and route correctly.

I've tested apophys' commit and it indeed fixes the issue without any adverse effects as far as I could see (I didn't check HipChat in hipchat mode, we're connecting to HipChat in regular jabber mode at work), so I'm in favor of merging this in for now while we investigate further.

zoni avatar Oct 15 '12 18:10 zoni

It works on hipchat because hipchat gives the sender as a non standard Node. Then I do agree, we can merge that. Sorry for the misunderstanding on the reproduction.

gbin avatar Oct 15 '12 18:10 gbin

I've merged #83 for now, but I still believe we need to delve into this a little deeper. I'm probably not going to get a chance to look at this again myself until Sunday though, just as an FYI.

zoni avatar Oct 15 '12 20:10 zoni

This area completely changed because we dropped the xmpp conventions, please retest and open a different bug if it still fails.

gbin avatar Jul 10 '15 05:07 gbin