{"record":{"id":"86bc157e3a2b053c","repo":"RocketChat/Rocket.Chat","slug":"invalid-channel","errorCode":"invalid-channel","errorMessage":"invalid-channel","messagePattern":"invalid-channel","errorType":"error_code","errorClass":"Meteor.Error","httpStatus":null,"severity":"error","filePath":"apps/meteor/server/lib/bot-helpers/index.ts","lineNumber":78,"sourceCode":"\t\t\treturn p(...params);\n\t\t}\n\n\t\treturn p;\n\t}\n\n\tasync addUserToRole(userName: string, roleId: string, userId: string): Promise<void> {\n\t\tawait addUserToRole(userId, roleId, userName);\n\t}\n\n\tasync removeUserFromRole(userName: string, roleId: string, userId: string): Promise<void> {\n\t\tawait removeUserFromRole(userId, roleId, userName);\n\t}\n\n\tasync addUserToRoom(userName: string, room: string): Promise<void> {\n\t\tconst foundRoom = await Rooms.findOneByIdOrName(room);\n\n\t\tif (!foundRoom) {\n\t\t\tthrow new Meteor.Error('invalid-channel');\n\t\t}\n\n\t\tconst userId = Meteor.userId();\n\t\tif (!userId) {\n\t\t\tthrow new Meteor.Error('error-invalid-user', 'Invalid user', { method: 'addUserToRoom' });\n\t\t}\n\t\tawait addUsersToRoomMethod(userId, {\n\t\t\trid: foundRoom._id,\n\t\t\tusers: [userName],\n\t\t});\n\t}\n\n\tasync removeUserFromRoom(userName: string, room: string) {\n\t\tconst foundRoom = await Rooms.findOneByIdOrName(room);\n\n\t\tif (!foundRoom) {\n\t\t\tthrow new Meteor.Error('invalid-channel');\n\t\t}","sourceCodeStart":60,"sourceCodeEnd":96,"githubUrl":"https://github.com/RocketChat/Rocket.Chat/blob/b2c16d5842cbe6b69b59bdf6fc5e5f1afcd1f0b0/apps/meteor/server/lib/bot-helpers/index.ts#L60-L96","documentation":"BotHelpers.addUserToRoom resolves its `room` argument via Rooms.findOneByIdOrName and throws a bare 'invalid-channel' Meteor.Error when nothing matches either a room _id or a room name. It is reached through the DDP method 'botRequest' (restricted to authenticated users holding the 'bot' role) and is the surface hubot-style bots use to add users to rooms.","triggerScenarios":"The bot passes a room name with a leading '#', a typo, or wrong case expectations; the room was deleted or renamed; passing the room's display name (fname) that differs from the stored name; passing a topic/description instead of the name.","commonSituations":"Hubot scripts hardcoding channel names that drift over time; multi-lingual workspaces where display names differ from stored names; bots restored onto a fresh workspace without their old channels.","solutions":["Resolve the room first via rooms.info (by roomId or roomName) and pass the canonical name or _id","Strip '#', '@', and whitespace decorations from user-supplied names before calling","Keep bot-usable room names in configuration and validate them at bot startup"],"exampleFix":"// before\nawait call('botRequest', 'addUserToRoom', 'alice', '#general'); // invalid-channel\n\n// after\nconst room = await GET '/api/v1/rooms.info' { roomName: 'general' };\nawait call('botRequest', 'addUserToRoom', 'alice', room.room._id);","handlingStrategy":"validation","validationCode":"const { room } = await GET '/api/v1/rooms.info' { roomName: room.replace(/^#/, '') };\n// fall back to { roomId } lookup if name lookup fails\nif (!room) {\n  // do not call botRequest addUserToRoom with an unresolvable room\n}","typeGuard":"const isRoomRef = (room: unknown): room is { _id: string; name: string } =>\n  typeof room === 'object' && room !== null && '_id' in room && 'name' in room;","tryCatchPattern":"try {\n  await call('botRequest', 'addUserToRoom', username, roomRef);\n} catch (e) {\n  if (e instanceof Meteor.Error && e.error === 'invalid-channel') {\n    // re-resolve the room by id/name and retry once\n  } else {\n    throw e;\n  }\n}","preventionTips":["Resolve rooms via rooms.info and pass the canonical _id","Strip '#'/decorations from names before lookup","Validate configured channel names at bot startup"],"tags":["rocket-chat","bots","rooms","channel-lookup","meteor-methods"],"backgroundTag":"channel-not-found","analyzedSha":"b2c16d5842cbe6b69b59bdf6fc5e5f1afcd1f0b0","analyzedAt":"2026-08-18T15:26:39.429Z","schemaVersion":2},"datasetVersion":"2026-08-21T13:17:26.733Z"}