 
   constructor: ( robot ) ->
     @robot = robot
+    @reconnectTryCount = 0
 
   run: ->
     options =

    @makeClient()

  reconnect: () ->
    console.log 'reconnect'

  makeClient: () ->
    options = @options

  chat: (user, text) ->
    lines = text.split '\n'
    for line in lines
      @robot.logger.debug "Sending message: #{line} to user: #{user}"
      @client.notify 'chat',
        text: line
        id: Math.random().toString()
        receipt: false
        user: user

  group: (group, text) ->
    lines = text.split '\n'
    for line in lines
      @robot.logger.debug "Sending message: #{line} to group: #{group}"
      @client.notify 'chat',
        text: line
        id: Math.random().toString()
        receipt: false
        group: group

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

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