{"record":{"id":"2bfb4e8b009b0dce","repo":"RocketChat/Rocket.Chat","slug":"invalid-target-agent-cannot-transfer","errorCode":null,"errorMessage":"Invalid target agent, cannot transfer","messagePattern":"Invalid target agent, cannot transfer","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"apps/meteor/app/apps/server/bridges/livechat.ts","lineNumber":288,"sourceCode":"\t\t}\n\t\tconst { _id, username, name, type } = appUser;\n\t\tconst transferredBy = {\n\t\t\t_id,\n\t\t\tusername,\n\t\t\tname,\n\t\t\ttype,\n\t\t\tuserType: 'user',\n\t\t} as const;\n\n\t\tlet userId;\n\t\tlet transferredTo;\n\n\t\tif (targetAgent?.id) {\n\t\t\ttransferredTo = await Users.findOneAgentById(targetAgent.id, {\n\t\t\t\tprojection: { _id: 1, username: 1, name: 1 },\n\t\t\t});\n\t\t\tif (!transferredTo) {\n\t\t\t\tthrow new Error('Invalid target agent, cannot transfer');\n\t\t\t}\n\n\t\t\tuserId = transferredTo._id;\n\t\t}\n\n\t\t// #TODO: #AppsEngineTypes - Remove explicit types and typecasts once the apps-engine definition/implementation mismatch is fixed.\n\t\treturn transfer(\n\t\t\t(await this.orch.getConverters()?.get('rooms').convertAppRoom(currentRoom)) as IOmnichannelRoom,\n\t\t\tthis.orch.getConverters()?.get('visitors').convertAppVisitor(visitor),\n\t\t\t{ userId, departmentId, transferredBy, transferredTo },\n\t\t);\n\t}\n\n\tprotected async findVisitors(query: object, appId: string): Promise<Array<IVisitor>> {\n\t\tthis.orch.debugLog(`The App ${appId} is looking for livechat visitors.`);\n\n\t\tif (this.orch.isDebugging()) {\n\t\t\tconsole.warn('The method AppLivechatBridge.findVisitors is deprecated. Please consider using its alternatives');","sourceCodeStart":270,"sourceCodeEnd":306,"githubUrl":"https://github.com/RocketChat/Rocket.Chat/blob/2a7de457074cbb4d4373fbd9a4e5bea292c9c764/apps/meteor/app/apps/server/bridges/livechat.ts#L270-L306","documentation":"Error \"Invalid target agent, cannot transfer\" thrown in RocketChat/Rocket.Chat.","triggerScenarios":"Thrown at apps/meteor/app/apps/server/bridges/livechat.ts:288 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":["Verify transferData.targetAgent.id refers to an existing agent user (Users.findOneAgentById) before transferring.","Omit targetAgent or pass a valid department id instead if the target agent no longer exists."],"exampleFix":"Verify the target agent is a valid, online agent before transferring: if (!targetAgent) { throw new Error('Invalid target agent, cannot transfer'); }","handlingStrategy":null,"validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"backgroundTag":null,"analyzedSha":"2a7de457074cbb4d4373fbd9a4e5bea292c9c764","analyzedAt":"2026-08-18T15:26:39.429Z","contentChangedAt":"2026-08-18T15:26:39.429Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}