RocketChat/Rocket.Chat · error · Error
invalid-room
Error message
invalid-room
What it means
Thrown by GET /api/v1/livechat/agent.info/:rid/:token when findRoom(token, rid) returns null. findRoom queries LivechatRooms by both the visitor token and the room ID — so this error means either the room ID is wrong, the room does not belong to this visitor, or the room no longer exists.
Source
Thrown at apps/meteor/server/api/v1/omnichannel/agent.ts:33
import { findRoom, findGuest, findAgent, findOpenRoom } from './lib/livechat';
import { hasPermissionAsync } from '../../../lib/authorization/hasPermission';
import { hasRoleAsync } from '../../../lib/authorization/hasRole';
import { RoutingManager } from '../../../lib/omnichannel/RoutingManager';
import { getRequiredDepartment } from '../../../lib/omnichannel/departmentsLib';
import { saveAgentInfo } from '../../../lib/omnichannel/omni-users';
import { setUserStatusLivechat, allowAgentChangeServiceStatus } from '../../../lib/omnichannel/utils';
import type { ExtractRoutesFromAPI } from '../../ApiClass';
API.v1.addRoute('livechat/agent.info/:rid/:token', {
async get() {
const visitor = await findGuest(this.urlParams.token);
if (!visitor) {
throw new Error('invalid-token');
}
const room = await findRoom(this.urlParams.token, this.urlParams.rid);
if (!room) {
throw new Error('invalid-room');
}
const agent = room?.servedBy && (await findAgent(room.servedBy._id));
if (!agent) {
throw new Error('invalid-agent');
}
return API.v1.success({ agent });
},
});
API.v1.addRoute(
'livechat/agent.next/:token',
{ validateParams: isGETAgentNextToken },
{
async get() {
const { token } = this.urlParams;
const room = await findOpenRoom(token, undefined, this.userId);View on GitHub (pinned to f9d3ec372b)
Solutions
- Verify the room ID is correct and belongs to the visitor identified by the token.
- Check if the room still exists in LivechatRooms collection.
- If the room was closed, start a new livechat session to get a new room ID.
Defensive patterns
Strategy: validation
Validate before calling
// Verify the room exists and belongs to the visitor before calling agent.info
// Use the livechat room endpoint
async function verifyRoom(baseUrl, token, rid) {
const res = await fetch(`${baseUrl}/api/v1/livechat/room/${rid}?token=${token}`);
return res.ok;
}
if (!(await verifyRoom(baseUrl, token, rid))) {
throw new Error('Room not found or does not belong to this visitor');
} Type guard
function isValidRoomId(rid: unknown): rid is string {
return typeof rid === 'string' && /^[A-Za-z0-9]{17}$/.test(rid);
} Try / catch
try {
await getAgentInfo(rid, token);
} catch (e) {
if (e.message === 'invalid-room') {
console.error('Room not found for this visitor. Start a new livechat session.');
return;
}
throw e;
} Prevention
- Verify the room ID and visitor token are from the same livechat session.
- Handle room closure gracefully by detecting invalid-room and prompting the user to start a new chat.
When it happens
Trigger: Calling agent.info with a valid visitor token but a room ID that doesn't exist or isn't associated with that visitor's token. findRoom uses findOneByIdAndVisitorToken(rid, token), so both must match.
Common situations: Room was closed and removed; room ID from a different conversation; visitor token doesn't own the specified room; room ID typo or copy error.
Related errors
AI-assisted analysis of RocketChat/Rocket.Chat@f9d3ec372b (2026-08-12).
Data as JSON: /api/errors/d2c523610c34d9ac.
Report an issue: GitHub.