{"record":{"id":"2a394b3fb1209598","repo":"RocketChat/Rocket.Chat","slug":"error-user-is-not-agent","errorCode":"error-user-is-not-agent","errorMessage":"error-user-is-not-agent","messagePattern":"error-user-is-not-agent","errorType":"exception","errorClass":"Meteor.Error","httpStatus":null,"severity":"error","filePath":"apps/meteor/server/lib/omnichannel/startup.ts","lineNumber":91,"sourceCode":"\t\t(user, room) => {\n\t\t\tif (!isOmnichannelRoom(room)) {\n\t\t\t\treturn;\n\t\t\t}\n\t\t\tthrow new Meteor.Error(\n\t\t\t\ti18n.t('You_cant_leave_a_livechat_room_Please_use_the_close_button', {\n\t\t\t\t\tlng: user.language || settings.get('Language') || 'en',\n\t\t\t\t}),\n\t\t\t);\n\t\t},\n\t\tcallbacks.priority.LOW,\n\t\t'cant-leave-omnichannel-room',\n\t);\n\n\tcallbacks.add(\n\t\t'beforeJoinRoom',\n\t\tasync (user, room) => {\n\t\t\tif (isOmnichannelRoom(room) && !(await hasPermissionAsync(user, 'view-l-room'))) {\n\t\t\t\tthrow new Meteor.Error('error-user-is-not-agent', 'User is not an Omnichannel Agent', {\n\t\t\t\t\tmethod: 'beforeJoinRoom',\n\t\t\t\t});\n\t\t\t}\n\n\t\t\treturn user;\n\t\t},\n\t\tcallbacks.priority.LOW,\n\t\t'cant-join-omnichannel-room',\n\t);\n\n\tconst monitor = new LivechatAgentActivityMonitor();\n\n\tsettings.watch<boolean>('Troubleshoot_Disable_Livechat_Activity_Monitor', async (value) => {\n\t\tif (value) {\n\t\t\treturn monitor.stop();\n\t\t}\n\n\t\tawait monitor.start();","sourceCodeStart":73,"sourceCodeEnd":109,"githubUrl":"https://github.com/RocketChat/Rocket.Chat/blob/b2c16d5842cbe6b69b59bdf6fc5e5f1afcd1f0b0/apps/meteor/server/lib/omnichannel/startup.ts#L73-L109","documentation":"A 'beforeJoinRoom' callback (registered in omnichannel startup) rejects joining omnichannel rooms unless the user has the 'view-l-room' permission; otherwise it throws Meteor.Error('error-user-is-not-agent', 'User is not an Omnichannel Agent', { method: 'beforeJoinRoom' }). The permission is normally granted via the livechat-agent role, so in practice it means 'this user is not an omnichannel agent'.","triggerScenarios":"Calling joinRoom (Meteor method) for a room with t: 'l' as a user without view-l-room permission — typically a non-agent user, an agent whose role lost the permission, or a bot/app user not registered as an omnichannel agent.","commonSituations":"Admin adds a user to a livechat room without making them an agent, custom roles missing view-l-room after a permission reset, apps-engine bots trying to join omnichannel rooms, or users removed from the omnichannel agents list but still in old UI sessions.","solutions":["Add the user as an Omnichannel agent (Administration > Omnichannel > Agents) — this grants the livechat-agent role and view-l-room","Or grant 'view-l-room' to the user's role manually in Administration > Permissions if they must join without being a routed agent","Verify with a permissions check before joining (see validation below)","Reload the user's session/roles after permission changes"],"exampleFix":"// before\nawait Meteor.callAsync('joinRoom', rid); // throws error-user-is-not-agent\n\n// after\nconst canJoin = await hasPermissionAsync(Meteor.user(), 'view-l-room');\nif (isOmnichannelRoom(room) && !canJoin) {\n  throw new Meteor.Error('error-user-is-not-agent');\n}\nawait Meteor.callAsync('joinRoom', rid);","handlingStrategy":"validation","validationCode":"import { hasPermissionAsync } from '../../authorization/hasPermission';\n\nif (isOmnichannelRoom(room) && !(await hasPermissionAsync(user, 'view-l-room'))) {\n  throw new Meteor.Error('error-user-is-not-agent', 'Grant view-l-room or add as omnichannel agent');\n}\nawait Meteor.callAsync('joinRoom', rid);","typeGuard":"function isOmnichannelRoom(v: { t?: string } | null | undefined): v is { _id: string; t: 'l' } {\n  return v?.t === 'l';\n}","tryCatchPattern":"try {\n  await Meteor.callAsync('joinRoom', rid);\n} catch (err) {\n  if (err instanceof Meteor.Error && err.error === 'error-user-is-not-agent') {\n    // user is not an agent: add them via Omnichannel > Agents, then retry\n  } else {\n    throw err;\n  }\n}","preventionTips":["Make users omnichannel agents before exposing livechat rooms to them","Audit custom roles for view-l-room after permission resets/upgrades","In onboarding flows, link 'join failed' directly to the add-agent admin action"],"tags":["omnichannel","permissions","join-room","agent-role"],"backgroundTag":"permission-denied","analyzedSha":"b2c16d5842cbe6b69b59bdf6fc5e5f1afcd1f0b0","analyzedAt":"2026-08-18T15:26:39.429Z","schemaVersion":2},"datasetVersion":"2026-08-21T13:17:26.733Z"}