Skip to content

Trying to figure out how to get robut to join rooms when invited #41

@will

Description

@will

I'd like to have the bot appear in rooms when you @ mention it.

I've figured out how to notice the invite, but joining the room after Connection.new.connect doesn't seem to work

Invitaitons look like

 <message from='(room name)@conf.hipchat.com' to='(id)@chat.hipchat.com'><x xmlns='http://jabber.org/protocol/muc#user'><invite from='(id)@chat.hipchat.com/osx'><reason>@DumboTBot some message</reason></invite></x><x xmlns='http://hipchat.com/protocol/muc#room'><name>room name</name><topic>The topic of the room</topic><privacy>public</privacy></x></message>

Notably the message does not have a type.

I was able to just quick hack into the PM class to print something when invited:

class Robut::PM < Robut::Presence
  def initialize(connection, rooms)
    # Add the callback from direct messages. Turns out the
    # on_private_message callback doesn't do what it sounds like, so I
    # have to go a little deeper into xmpp4r to get this working.
    self.connection = connection
    connection.client.add_message_callback(200, self) do |message|
      invited(message, connection)
     # ... rest of that method
  end

  def invited(message, conn)
    if message.type.nil?
      p message.to_s
      if message.to_s =~ /invite/ # because I didn't want to figure out how to traverse to see the <invite> just to see if this worked at all
        begin
          room_name = "#{message.from.node}@conf.hipchat.com"
          puts "joining #{room_name}"

        room = Robut::Room.new(conn, message.from.node + '@conf.hiphcat.com')
        room.join
        room.reply("I am here", nil)

        rescue => e
         p e
        end
      end
    end         

The Room.new and the #join don't raise exceptions, but the bot never joins the room.
Any ideas how to do this?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions