     @receive new Robot.TextMessage user, body
 
   send_sms: (message, to, callback) ->
-    # rework to use scoped-http-client here
-    console.log "#{to}: #{message}"
+    auth = new Buffer(@sid + ':' + @token).toString("base64")
+    data = QS.stringify From: @from, To: to, Body: message
+
+    @http("https://api.twilio.com")
+      .path("/2010-04-01/Accounts/#{@sid}/SMS/Messages.json")
+      .header("Authorization", "Basic #{auth}")
+      .header("Content-Type", "application/x-www-form-urlencoded")
+      .post(data) (err, res, body) ->
+        if err
+          callback err
+        else if res.statusCode is 201
+          json = JSON.parse(body)
+          callback null, body
+        else
+          json = JSON.parse(body)
+          callback body.message
 
 module.exports = Twilio
-

Robot = require '../robot'
HTTP  = require 'http'
Qs    = require 'querystring'

class Twilio extends Robot
  constructor: ->


  run: ->
    server = HTTP.createServer (request, response) =>
      payload = QS.parse(request.url)

      if payload.Body? and payload.From?
        console.log "Received SMS: #{payload.Body} from #{payload.From}"
