 HTTPS = require 'https'
 
 class Slack extends Adapter
+  log: console.log.bind console
+  logError: console.error.bind console
+
   send: (params, strings...) ->
-    console.log "Sending message"
+    @log "Sending message"
 
     user = @userFromParams(params)
 
     strings.forEach (str) =>
-      # Escape this
-      str = str.replace(/&/g, '&amp;')
-      str = str.replace(/</g, '&lt;')
-      str = str.replace(/>/g, '&gt;')
-
-      # Linkify. We assume that the bot is well-behaved and
-      # consistently sending links with the protocol part
-      str = str.replace(/((\bhttp)\S+)/g, '<$1>')
+      str = @escapeHtml str
 
       args = JSON.stringify({"channel": user.reply_to, "text": str, username: @robot.name})
       @post "/services/hooks/hubot", args
 
   reply: (params, strings...) ->
-    console.log "Sending reply"
+    @log "Sending reply"
 
     user = @userFromParams(params)
     strings.forEach (str) =>

    self.robot.name = @options.name

    # Tell Hubot we're connected so it can load scripts
    console.log "Successfully 'connected' as", self.robot.name
    self.emit "connected"

  # Convenience HTTP Methods for sending data back to slack

    @request "POST", path, body, callback

  request: (method, path, body, callback) ->
    self = @

    #console.log method, path, body
    host = @options.team + '.slack.com'
    headers = "Host": host
