 fuzzy = require 'fuzzy'
 
 module.exports = (robot) ->
+  users = robot.brain.users() or @robot.adapter.client.rtm.dataStore.users
   url = process.env.HUBOT_VICTOROPS_POST_URL
   teams = JSON.parse process.env.HUBOT_VICTOROPS_TEAMS_MAP
   calendars = JSON.parse process.env.HUBOT_VICTOROPS_TEAMS_ICAL
+
+  getRoom = (context) ->
+    room = robot.adapter.client.rtm.dataStore.getChannelOrGroupByName context.message.room
+    room = robot.adapter.client.rtm.dataStore.getChannelGroupOrDMById context.message.room unless room
+    room
 
   parseJSON = (response) ->
     return response.json()

          body: JSON.stringify
           entity_id: "slack-ops"
           message_type: "critical"
           entity_display_name: "Paged by @#{msg.message.user.name} in ##{room}"
           state_message: message
        .then (res) ->
          checkStatus res

      else
        msg.reply "I can't determine who is on call, please contact your friendly administrator"

  robot.respond /who\s?is on\s?call/, (msg) ->
    room = getRoom msg
    team = teams[room.name]
    return invalidChannel msg unless team

    whoIsOncall team, (person) ->
