 #   HUBOT_AWS_SECRET_ACCESS_KEY - The Amazon secret key for the given id
 #
 #
-# package.json needs to have "aws2js":"0.6.12"
+# package.json needs to have "aws2js":"0.6.12" and "moment":"1.6.2"
 #
 # It's highly recommended to use a read-only IAM account for this purpose
 # https://console.aws.amazon.com/iam/home?#

key = process.env.HUBOT_AWS_ACCESS_KEY_ID
secret = process.env.HUBOT_AWS_SECRET_ACCESS_KEY

sqs = (require 'aws2js')
  .load('sqs')
  .setCredentials key, secret

module.exports = (robot) ->
  robot.respond /(^|\W)sqs status(\z|\W|$)/i, (msg) ->

              if sqsmsg? and sqsmsg.Attribute?
                timestamp = (att for att in sqsmsg.Attribute \
                  when att.Name == 'SentTimestamp')
                timestamp = (moment parseFloat timestamp[0].Value)
                  .format 'ddd, L LT'
              else
                timestamp = 'none available'

            msg.send "#{queueDesc} / oldest msg ~[#{timestamp}] / #{url}"
