{"record":{"id":"ecb071afe5c0e35d","repo":"RocketChat/Rocket.Chat","slug":"error-invalid-username-ecb071","errorCode":"error-invalid-username","errorMessage":"Invalid username","messagePattern":"Invalid username","errorType":"exception","errorClass":"Meteor.Error","httpStatus":null,"severity":"error","filePath":"apps/meteor/server/meteor-methods/integrations/incoming/addIncomingIntegration.ts","lineNumber":76,"sourceCode":"\n\tif (integration.channel.trim() === '') {\n\t\tthrow new Meteor.Error('error-invalid-channel', 'Invalid channel', {\n\t\t\tmethod: 'addIncomingIntegration',\n\t\t});\n\t}\n\n\tconst channels = integration.channel.split(',').map((channel) => channel.trim());\n\n\tfor (const channel of channels) {\n\t\tif (!validChannelChars.includes(channel[0])) {\n\t\t\tthrow new Meteor.Error('error-invalid-channel-start-with-chars', 'Invalid channel. Start with @ or #', {\n\t\t\t\tmethod: 'updateIncomingIntegration',\n\t\t\t});\n\t\t}\n\t}\n\n\tif (!integration.username || typeof integration.username.valueOf() !== 'string' || integration.username.trim() === '') {\n\t\tthrow new Meteor.Error('error-invalid-username', 'Invalid username', {\n\t\t\tmethod: 'addIncomingIntegration',\n\t\t});\n\t}\n\n\tif (integration.script?.trim()) {\n\t\tvalidateScriptEngine(integration.scriptEngine ?? 'isolated-vm');\n\t}\n\n\tconst user = await Users.findOneByUsername(integration.username, { projection: { _id: 1 } });\n\n\tif (!user) {\n\t\tthrow new Meteor.Error('error-invalid-user', 'Invalid user', {\n\t\t\tmethod: 'addIncomingIntegration',\n\t\t});\n\t}\n\n\tif (!(await hasPermissionAsync(user._id, 'message-impersonate'))) {\n\t\tthrow new Meteor.Error(","sourceCodeStart":58,"sourceCodeEnd":94,"githubUrl":"https://github.com/RocketChat/Rocket.Chat/blob/b2c16d5842cbe6b69b59bdf6fc5e5f1afcd1f0b0/apps/meteor/server/meteor-methods/integrations/incoming/addIncomingIntegration.ts#L58-L94","documentation":"Thrown by addIncomingIntegration when integration.username is missing, not a string, or trims to empty. This username is the 'post as' identity: every message delivered by the incoming webhook is attributed to this user, so it is mandatory even when a script is provided. check() at the top of the method already requires username: String, so in practice this fires for whitespace-only values or when the exported helper is called directly with an incomplete object.","triggerScenarios":"Calling addIncomingIntegration with username: '   ' or omitting username when invoking the exported server function directly (bypassing the method wrapper's type definitions).","commonSituations":"Form submits before the 'Post as' field is chosen; payload assembled conditionally and username key skipped; automation scripts that assume the server defaults the username (it does not).","solutions":["Set username to the exact username string of an existing workspace user, e.g. a dedicated bot account","Trim and require a non-empty username in the client form before calling","Migrate to POST /api/v1/integrations.create which validates the same field (removed method in 9.0.0)"],"exampleFix":"// before\nMeteor.callAsync('addIncomingIntegration', { ...integration, username: '   ' });\n// after\nMeteor.callAsync('addIncomingIntegration', { ...integration, username: 'ci-bot' }); // existing workspace user","handlingStrategy":"validation","validationCode":"if (typeof integration.username !== 'string' || integration.username.trim() === '') throw new Error('post-as username is required');\nawait Meteor.callAsync('addIncomingIntegration', integration);","typeGuard":"const isNonBlankUsername = (u: unknown): u is string => typeof u === 'string' && u.trim() !== '';","tryCatchPattern":"try {\n  await Meteor.callAsync('addIncomingIntegration', integration);\n} catch (err) {\n  if (err instanceof Meteor.Error && err.error === 'error-invalid-username') { /* require username field */ }\n}","preventionTips":["Make the post-as user a required dropdown of existing users instead of free text","Trim before submit","Default to a known bot account in provisioning scripts"],"tags":["rocket-chat","incoming-integration","meteor-method","username-validation"],"backgroundTag":"invalid-username","analyzedSha":"b2c16d5842cbe6b69b59bdf6fc5e5f1afcd1f0b0","analyzedAt":"2026-08-18T15:26:39.429Z","schemaVersion":2},"datasetVersion":"2026-08-21T13:17:26.733Z"}