cjoudrey / wobot

A plugin-based HipChat bot written in Node.js.
https://github.com/cjoudrey/wobot/blob/master/README.md
MIT License
116 stars 48 forks source link

`from` is different in message and privateMessage #11

Open jakajancar opened 12 years ago

jakajancar commented 12 years ago

In message events, from is the nickname while in privateMessage event's it's the jid.

cjoudrey commented 12 years ago

This is actually caused by the way data is received from HipChat.

To fix this we would need to track the jid's of the users in the channel.

Personally, I think we should return the jid in both cases.

jakajancar commented 12 years ago

For me, both is useful: jid for identification, name for referring to the user by name on channels, when responding.

E.g.:

bot.on 'message', (channel, from, message) ->
    if matches = message.match /^(@cebot:?|cebot\s*:)\s*(.*?)\s*$/i
        bot.emit 'command', matches[2], (reply) =>
            this.message channel, '@' + from + ': ' + reply

bot.on 'privateMessage', (from, message) ->
    bot.emit 'command', message, (reply) =>
        this.message from, reply
cjoudrey commented 12 years ago

True.

It would have to become:

(channel, from, jid, message)

and

(from, jid, message)

What do you think?

jakajancar commented 12 years ago

Looks good to me :)

cjoudrey commented 12 years ago

I'll try to get this done during the week, feel free to open a pull request if you need it sooner. :)

Basically we need to keep track of the jid's when the user listing is updated (i.e. someone connects or disconnects). We can then use this object to resolve the jid when we only have the name of the user.

That being said, if there is 2 users with the same name we won't be able to correctly determine the jid.

jakajancar commented 12 years ago

Are you sure user's jid is not sent in a message / there can be more than 1 person with the same name?

This seems like a pretty huge deficiency of the protocol: how can you then reliably start a private chat with a user that has said something on a channel?

cjoudrey commented 12 years ago

To be honest I haven't looked into the jabber protocol for a few months.

From what I recall, what you said is correct and I agree with you that it is a huge deficiency.

This is why mission-critical commands should be done via privateMessage as you have the jid of the user.

I will contact HipChat to see if they'd be willing to add an attribute to the stanza to provide the jid of the user when he talks in the channel. This isn't in the spec, but it wouldn't break it.

powdahound commented 12 years ago

I'll take a look at getting this added on our end. The way the spec does it is definitely weak sauce, but it's designed to provide anonymity in public chat rooms. But that's not what we do so it'll be OK to add.

powdahound commented 12 years ago

Just deployed an update adding this. Message stanzas from rooms now look like:

<message type='groupchat' from='1_room@conf.hipchat.com/Some Dude' id='message_1' to='1_1@chat.hipchat.com/mac'>
  <body>foo</body>
  <x xmlns='http://hipchat.com'>
    <sender>1_2@chat.hipchat.com</sender>
  </x>
</message>

Hope that makes things easier!