         return
 
     params =
-      channel: msg.item.channel
-      latest: msg.item.ts
-      oldest: msg.item.ts
+      channel: channel
+      latest: ts
+      oldest: ts
       inclusive: 1
       count: 1
       token: process.env.HUBOT_SLACK_TOKEN

    fetch("https://slack.com/api/#{endpoint}.history#{buildQueryString params}")
    .then (json) ->
      message = json.messages?[0]
      return unless message? and message.type is "message"
      attachment = message.attachments?[0]
      return unless attachment?.title_link?
      ticket = attachment.title_link.split "#{jiraUrl}/browse/"
      return unless ticket and ticket.length is 2
      ticket = ticket[1]

      switch msg.reaction
        when "+1", "-1"
          handleRankRequest


  robot.adapter.client.on "raw_message", (msg) ->
    robot.emit "jira_ticket_created_message", msg if msg.type is "message" and msg.user is robot.adapter.self.id and msg.text is TICKET_CREATED_TEXT
    return unless msg.item_user is robot.adapter.self.id
    return unless msg.user isnt robot.adapter.self.id
    if msg.type is "reaction_added"
      handleReactionAdded msg
    else if msg.type is "reaction_removed"
      handleReactionRemoved msg

  getTicketInChannelByTs = (channel, ts) ->
    switch channel[0]
      when "G"
        endpoint = "groups"
      when "C"
