{"record":{"id":"c5252fcbcda7cc23","repo":"Mintplex-Labs/anything-llm","slug":"chatid-is-required","errorCode":null,"errorMessage":"chatId is required.","messagePattern":"chatId is required\\.","errorType":"http","errorClass":null,"httpStatus":400,"severity":"error","filePath":"server/endpoints/telegram.js","lineNumber":235,"sourceCode":"        const connector = await ExternalCommunicationConnector.get(\"telegram\");\n        const approved = connector?.config?.approved_users || [];\n        return response.status(200).json({ users: approved });\n      } catch (e) {\n        console.error(e.message, e);\n        response.sendStatus(500);\n      }\n    }\n  );\n\n  app.post(\n    \"/telegram/approve-user\",\n    [validatedRequest, isSingleUserMode],\n    async (request, response) => {\n      try {\n        const { chatId } = reqBody(request);\n        if (!chatId)\n          return response\n            .status(400)\n            .json({ success: false, error: \"chatId is required.\" });\n\n        const service = new TelegramBotService();\n        await service.approvePendingUser(chatId);\n        await EventLogs.logEvent(\"telegram_user_approved\", { chatId });\n        return response.status(200).json({ success: true });\n      } catch (e) {\n        console.error(e.message, e);\n        response.sendStatus(500);\n      }\n    }\n  );\n\n  app.post(\n    \"/telegram/deny-user\",\n    [validatedRequest, isSingleUserMode],\n    async (request, response) => {\n      try {","sourceCodeStart":217,"sourceCodeEnd":253,"githubUrl":"https://github.com/Mintplex-Labs/anything-llm/blob/3aec848f2885144aa8f1e53b9731a04310d5d558/server/endpoints/telegram.js#L217-L253","documentation":"The 400 reply from POST /telegram/approve-user when the JSON body contains no chatId. The endpoint approves a pending Telegram user by chat id; chatId is the only required field and reqBody(request) returned an object without it (missing, empty string, null, or a body that failed to parse).","triggerScenarios":"POST /telegram/approve-user with an empty body, with Content-Type not application/json so the body never parses, or with a differently-cased key (chat_id, chatID). The chatId to send is the numeric Telegram chat id shown in the telegram_pending_user event log entry.","commonSituations":"Frontend integration sending snake_case chat_id instead of chatId; curl without -H 'Content-Type: application/json'; approving a user after the pending entry expired and guessing the field name.","solutions":["Send {\"chatId\": \"<numeric telegram chat id>\"} with Content-Type: application/json to /telegram/approve-user.","Get the correct chatId from EventLogs entry telegram_pending_user (logged when the unknown user first messages the bot).","Confirm the request reaches the API with a parsed body (auth cookies attached, validatedRequest passing) - an unauthenticated body still parses but an empty payload will not."],"exampleFix":"// before\ncurl -X POST /api/telegram/approve-user -d '{\"chat_id\": 12345}'\n\n// after\ncurl -X POST /api/telegram/approve-user \\\n  -H 'Content-Type: application/json' \\\n  -d '{\"chatId\": \"12345\"}'","handlingStrategy":"validation","validationCode":"function approveUser(chatId) {\n  if (!chatId || typeof chatId !== \"string\" || !/^\\-?\\d+$/.test(chatId)) {\n    throw new Error(\"chatId must be a numeric Telegram chat id\");\n  }\n  return fetch(\"/api/telegram/approve-user\", {\n    method: \"POST\", headers: { \"Content-Type\": \"application/json\" },\n    body: JSON.stringify({ chatId }),\n  });\n}","typeGuard":"const isChatId = (v) => typeof v === \"string\" && /^-?\\d+$/.test(v);","tryCatchPattern":null,"preventionTips":["Always send Content-Type: application/json with these endpoints.","Source chatId from the telegram_pending_user event log, never hand-type it.","Share one helper for approve/deny/revoke so the chatId key name cannot drift."],"tags":["telegram","validation","missing-parameter","request-body"],"backgroundTag":"missing-required-parameter","analyzedSha":"3aec848f2885144aa8f1e53b9731a04310d5d558","analyzedAt":"2026-08-18T10:02:21.017Z","schemaVersion":2},"datasetVersion":"2026-08-23T13:39:53.451Z"}