RocketChat/Rocket.Chat · error · Error

Invalid target agent, cannot transfer

Error message

Invalid target agent, cannot transfer

What it means

Error "Invalid target agent, cannot transfer" thrown in RocketChat/Rocket.Chat.

Solutions

  1. Verify transferData.targetAgent.id refers to an existing agent user (Users.findOneAgentById) before transferring.
  2. Omit targetAgent or pass a valid department id instead if the target agent no longer exists.

Example fix

Verify the target agent is a valid, online agent before transferring: if (!targetAgent) { throw new Error('Invalid target agent, cannot transfer'); }

When it happens

Trigger: Thrown at apps/meteor/app/apps/server/bridges/livechat.ts:288 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/2bfb4e8b009b0dce. Report an issue: GitHub.

Appendix: source

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

		}
		const { _id, username, name, type } = appUser;
		const transferredBy = {
			_id,
			username,
			name,
			type,
			userType: 'user',
		} as const;

		let userId;
		let transferredTo;

		if (targetAgent?.id) {
			transferredTo = await Users.findOneAgentById(targetAgent.id, {
				projection: { _id: 1, username: 1, name: 1 },
			});
			if (!transferredTo) {
				throw new Error('Invalid target agent, cannot transfer');
			}

			userId = transferredTo._id;
		}

		// #TODO: #AppsEngineTypes - Remove explicit types and typecasts once the apps-engine definition/implementation mismatch is fixed.
		return transfer(
			(await this.orch.getConverters()?.get('rooms').convertAppRoom(currentRoom)) as IOmnichannelRoom,
			this.orch.getConverters()?.get('visitors').convertAppVisitor(visitor),
			{ userId, departmentId, transferredBy, transferredTo },
		);
	}

	protected async findVisitors(query: object, appId: string): Promise<Array<IVisitor>> {
		this.orch.debugLog(`The App ${appId} is looking for livechat visitors.`);

		if (this.orch.isDebugging()) {
			console.warn('The method AppLivechatBridge.findVisitors is deprecated. Please consider using its alternatives');

View on GitHub (pinned to 2a7de45707)