 
   constructor: (robot) ->
     super robot
-    @robot.logger.info "Constructed!"
 
   send: (envelope, strings...) ->
     console.log("**** send ****")
-    @robot.logger.info("**** send ****")
+    console.log(envelope)
+    console.log(strings)
+    console.log("**** send ****")
     @wss.clients.forEach (client) =>
       client.send(JSON.stringify(strings))
 


  reply: (envelope, strings...) ->
    console.log("**** reply ****")
    @robot.logger.info("**** reply ****")
    strings = strings.map (s) -> "#{envelope.user.name}: #{s}"
    @send envelope, strings...

  on_message: (e) =>
    console.log("**** on_message ****")
    @robot.logger.info("**** on_message #{e} ****")
    e = JSON.parse e
    @robot.logger.info("**** on_message now e = #{e} ****")
    @robot.logger.info("**** on_message now e.message = #{e.message} ****")
    user = @robot.brain.userForId(e.user, {name: e.user, room: e.room})
    @receive new TextMessage(user, e.message, 'messageId')

  on_heartbeat: (e) =>
    console.log("**** on_heartbeat ****")
    @robot.logger.info("**** on_heartbeat ****")

  run: ->
    # Hack robot to inject proxy settings


    @wss = new WebSocketServer {port: 4773}
    @wss.on 'connection', (ws) =>
      @robot.logger.info("Websocket connection opened")
      ws.on 'message', @on_message
      ws.on 'heartbeat', @on_heartbeat

    @robot.logger.info("Connected to hubot")
    @emit "connected"

exports.use = (robot) ->
