RocketChat/Rocket.Chat · error · Error

Invalid agentId

Error message

Invalid agentId

What it means

Error "Invalid agentId" thrown in RocketChat/Rocket.Chat.

Solutions

  1. Pass a non-empty agentId string when looking up open rooms by agent.
  2. Check the caller supplies a valid agent id before invoking findOpenRoomsByAgentId.

Example fix

Guard the agentId parameter: if (!agentId || typeof agentId !== 'string') { throw new Error('Invalid agentId'); }

When it happens

Trigger: Thrown at apps/meteor/app/apps/server/bridges/livechat.ts:164 when the library encounters an invalid state.

Common situations: See trigger scenarios.


AI-assisted analysis of RocketChat/Rocket.Chat@2a7de45707 (2026-08-18). Data as JSON: /api/errors/170cabe35a072b8c. Report an issue: GitHub.

Appendix: source

Thrown at apps/meteor/app/apps/server/bridges/livechat.ts:164

		const visitor = this.orch.getConverters()?.get('visitors').convertAppVisitor(room.visitor);

		const closeData: any = {
			room: await this.orch.getConverters()?.get('rooms').convertAppRoom(room),
			comment,
			...(user && { user }),
			...(visitor && { visitor }),
		};

		await closeRoom(closeData);

		return true;
	}

	protected async findOpenRoomsByAgentId(agentId: string, appId: string): Promise<ILivechatRoom[]> {
		this.orch.debugLog(`The App ${appId} is looking for livechat rooms associated with agent ${agentId}`);

		if (!agentId) {
			throw new Error('Invalid agentId');
		}

		const rooms = await LivechatRooms.findOpenByAgent(agentId).toArray();
		return Promise.all(rooms.map((room) => this.orch.getConverters()?.get('rooms').convertRoom(room) as Promise<ILivechatRoom>));
	}

	protected async countOpenRoomsByAgentId(agentId: string, appId: string): Promise<number> {
		this.orch.debugLog(`The App ${appId} is counting livechat rooms associated with agent ${agentId}`);

		if (!agentId) {
			throw new Error('Invalid agentId');
		}

		return LivechatRooms.countOpenByAgent(agentId);
	}

	protected async findRooms(visitor: IVisitor, departmentId: string | null, appId: string): Promise<Array<ILivechatRoom>> {
		this.orch.debugLog(`The App ${appId} is looking for livechat visitors.`);

View on GitHub (pinned to 2a7de45707)