       return
     if !p.text
       return
+    # ignore offline messages
+    if p.timestamp
+      return
 
     @robot.logger.debug "Received message: #{p.text} from: #{p.user}"
 
-    user = @robot.brain.userForId p.user,
-      name: p.name || p.user
-      user: p.user
+    user = @robot.brain.userForId p.user
+    user.name = p.name or p.user
 
-    # hack to avoid having to prepand commands with hubot
-    if p.text.toLowerCase().indexOf @robot.name.toLowerCase() != 0
-      p.text = 'hubot ' + p.text
+    if p.group
+      user.room = p.group
+    else
+      delete user.room
+      #hack to avoid having to prepand commands with hubot name
+      if p.text.toLowerCase().indexOf @robot.name.toLowerCase() != 0
+        p.text = 'hubot ' + p.text
 
     @receive new TextMessage(user, p.text, p.id)
 

  chat: (user, text) ->
    lines = text.split '\n'
    for line in lines
      @client.exec 'chat',
        text: line
        id: Math.random().toString()
        receipt: false
        user: user

  send: (envelope, messages...) ->
    for msg in messages
      @chat envelope.user.id, msg

  reply: (envelope, messages...) ->
    for msg in messages
      @chat envelope.user.id, msg
    # for msg in messages
    #   # ltx.Element?
    #   if msg.attrs?

    @makeClient()

  reconnect: () ->
    @reconnectTryCount += 1
    if @reconnectTryCount > 5
      @robot.logger.error 'Unable to reconnect to UppTalk server.'
      process.exit 1

    setTimeout () =>
      @robot.logger.info 'Hubot UppTalk reconnecting.'
      @client.open()
    , 5000

  makeClient: () ->
    options = @options
