{"record":{"id":"7cd9503c9cbf6f1d","repo":"RocketChat/Rocket.Chat","slug":"error-invalid-inquiry","errorCode":null,"errorMessage":"error-invalid-inquiry","messagePattern":"error-invalid-inquiry","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"apps/meteor/ee/server/api/v1/omnichannel/lib/inquiries.ts","lineNumber":8,"sourceCode":"import { LivechatInquiry, Users, OmnichannelServiceLevelAgreements } from '@rocket.chat/models';\n\nimport { updateRoomSLA } from './sla';\n\nexport async function setSLAToInquiry({ userId, roomId, sla }: { userId: string; roomId: string; sla?: string }): Promise<void> {\n\tconst inquiry = await LivechatInquiry.findOneByRoomId(roomId, { projection: { status: 1 } });\n\tif (!inquiry || inquiry.status !== 'queued') {\n\t\tthrow new Error('error-invalid-inquiry');\n\t}\n\n\tconst slaData = sla && (await OmnichannelServiceLevelAgreements.findOneByIdOrName(sla));\n\tif (!slaData) {\n\t\tthrow new Error('error-invalid-sla');\n\t}\n\n\tconst user = await Users.findOneById(userId, { projection: { _id: 1, username: 1, name: 1 } });\n\tif (!user?.username) {\n\t\tthrow new Error('error-invalid-user');\n\t}\n\n\tawait updateRoomSLA(\n\t\troomId,\n\t\t{\n\t\t\t_id: user._id,\n\t\t\tname: user.name || '',\n\t\t\tusername: user.username,","sourceCodeStart":1,"sourceCodeEnd":26,"githubUrl":"https://github.com/RocketChat/Rocket.Chat/blob/f9d3ec372bb580fa8d036f94cf03925a478ef768/apps/meteor/ee/server/api/v1/omnichannel/lib/inquiries.ts#L1-L26","documentation":"Thrown by setSLAToInquiry when no LivechatInquiry is found for the roomId, or when the inquiry's status is not 'queued'. SLA can only be attached to an inquiry that is still queued (not yet taken/processed); once it leaves that state the SLA assignment is rejected. Plain Error, code 'error-invalid-inquiry'.","triggerScenarios":"Calling setSLAToInquiry for a roomId whose inquiry was already taken/closed, or that has no inquiry record at all; passing the room ID of a non-omnichannel room; retrying after the inquiry was dispatched.","commonSituations":"Agent took the chat between the SLA selection and the assignment; SLA set attempted on an already-closed conversation; race between queue dispatch and SLA config; wrong roomId passed.","solutions":["Fetch the inquiry and confirm status === 'queued' before calling setSLAToInquiry.","Ensure the SLA is set while the conversation is still in the queue (e.g. via a queue entry hook).","Retry only if the inquiry can be re-queued; otherwise abandon the SLA assignment.","Verify the roomId belongs to a livechat inquiry (not a regular channel)."],"exampleFix":"// before: assign SLA blindly\nawait setSLAToInquiry({ userId, roomId, sla });\n\n// after: confirm queued state\nconst inquiry = await LivechatInquiry.findOneByRoomId(roomId, { projection: { status: 1 } });\nif (!inquiry || inquiry.status !== 'queued') {\n  throw new ClientError('Room inquiry is not queued; SLA cannot be set.');\n}\nawait setSLAToInquiry({ userId, roomId, sla });","handlingStrategy":"validation","validationCode":"// Confirm the inquiry is queued before setting SLA\nimport { LivechatInquiry } from '@rocket.chat/models';\nconst inquiry = await LivechatInquiry.findOneByRoomId(roomId, { projection: { status: 1 } });\nif (!inquiry || inquiry.status !== 'queued') {\n  throw new ClientError('Inquiry not queued; cannot set SLA');\n}\nawait setSLAToInquiry({ userId, roomId, sla });","typeGuard":"function isInquiryQueued(i: { status?: string } | null | undefined): i is { status: 'queued' } {\n  return !!i && i.status === 'queued';\n}","tryCatchPattern":"try {\n  await setSLAToInquiry({ userId, roomId, sla });\n} catch (e) {\n  if (e.message === 'error-invalid-inquiry') {\n    // inquiry no longer queued; abandon SLA assignment\n    return { ok: false, reason: 'not-queued' };\n  }\n  throw e;\n}","preventionTips":["Set SLAs via a queue-entry hook, not after the chat is dispatched.","Treat SLA assignment as best-effort when racing with agent dispatch."],"tags":["omnichannel","sla","livechat","state-validation"],"backgroundTag":null,"analyzedSha":"f9d3ec372bb580fa8d036f94cf03925a478ef768","analyzedAt":"2026-08-12T19:07:17.372Z","schemaVersion":2},"datasetVersion":"2026-08-12T23:17:12.415Z"}