 		try	
 			this.response.setTimeout(1000)			
 			return RocketChat.API.v1.success
-				integrations: RocketChat.models.Integrations.find({"channel":decodeURIComponent(@urlParams.channel)}).fetch()
+				integrations: RocketChat.models.Integrations.find({"channel":decodeURIComponent(@urlParams.rid)}).fetch()
 		
 		catch e 
+			return RocketChat.API.v1.failure e.name + ': ' + e.message
+
+
+### Retrieve messages for a specific room
+Requires manage-messages role. The room channel needs to be URL encoded, as the names begin with characters that
+are not URL safe (e.g., '#' and '@'). Example:
+'http://domain.com:3000/api/room/%23testRoom/history'
+###
+RocketChat.API.v1.addRoute 'room/:rid/history', authRequired: true,
+	get: ->
+		if not Meteor.call('canAccessRoom', @urlParams.rid, this.userId)
+			return RocketChat.API.v1.unauthorized()
+
+		try
+
+			rpage = if @queryParams.page then Number(@queryParams.page) else 1
+			ritems = if @queryParams.items then Number(@queryParams.items) else 100
+			msgs = RocketChat.models.Messages.findVisibleByRoomId(@urlParams.rid,
+					sort:
+						ts: -1
+					skip: (rpage-1)*ritems
+					limit: ritems
+				).fetch()
+			return RocketChat.API.v1.success
+				msgs: msgs
+				page: rpage
+				items: msgs.length
+				total: RocketChat.models.Messages.findVisibleByRoomId(@urlParams.rid).count()
+
+		catch e
 			return RocketChat.API.v1.failure e.name + ': ' + e.message
 		
 


			
###
can take these as args to update.
['roomName', 'roomTopic', 'roomDescription', 'roomType', 'readOnly', 'systemMessages', 'default', 'joinCode']
###		
RocketChat.API.v1.addRoute 'admin.updateRoom', authRequired: true, 
	post: ->
	
		if RocketChat.authz.hasRole(@userId, 'admin') is false

		if RocketChat.authz.hasRole(@userId, 'admin') is false
			return RocketChat.API.v1.unauthorized()

		rpage = if @queryParams.page then Number(@queryParams.page) else 1
		ritems = if @queryParams.items then Number(@queryParams.items) else 100
		users = RocketChat.models.Users.find({}, { limit: ritems, skip: (rpage-1)*ritems }).fetch()
		
		return {
			users: users,
			page: rpage,
			items: users.length,
			total: RocketChat.models.Users.find().count(),
		}


# Create user
