soumyadeep/TgDocsXBotPublic · Bot Template
TgDocsXBot is a Telegram bot template designed to help developers instantly look up Telegram Bot API documentation directly inside any chat using Inline Queries.
7 commands3 envUpdated 5d agoCreated Jun 10, 2026
commands/errorUtils.js
javascript · 833 lines · click line # to share
1/**#command2name: errorUtils3answer: 4keyboard: 5parse_mode: markdown6aliases: 7allow_only_group: false8need_reply: false9is_web: 010#command**/11 12const errorCodes = {13 // 4xx Client Errors14 400: {15 code: "BAD_REQUEST",16 description: "The request was malformed or contained invalid parameters",17 common_causes: [18 "Invalid parameter type",19 "Missing required field",20 "Parameter value out of range",21 "Malformed JSON",22 "Wrong data format"23 ],24 examples: [25 "chat_id must be an integer",26 "text parameter is required",27 "Invalid JSON format"28 ],29 solution: "Check request parameters and format"30 },31 32 401: {33 code: "UNAUTHORIZED",34 description: "Invalid bot token or bot was blocked by user",35 common_causes: [36 "Wrong bot token",37 "Bot token revoked",38 "User blocked the bot",39 "Bot kicked from chat"40 ],41 examples: [42 "Invalid token",43 "Forbidden: bot was blocked by the user"44 ],45 solution: "Verify bot token and check if user blocked the bot"46 },47 48 402: {49 code: "PAYMENT_REQUIRED",50 description: "Payment required for premium features",51 common_causes: [52 "Trying to use premium features without payment",53 "Insufficient bot funds",54 "Payment method required"55 ],56 examples: [57 "Payment required for this feature",58 "Premium subscription needed"59 ],60 solution: "Upgrade to premium or use alternative methods"61 },62 63 403: {64 code: "FORBIDDEN",65 description: "Bot doesn't have permission to perform the action",66 common_causes: [67 "Bot is not admin in group/channel",68 "Bot can't send messages in chat",69 "Bot can't delete messages",70 "Insufficient permissions",71 "Restricted by chat settings"72 ],73 examples: [74 "Forbidden: bot is not a member of the channel",75 "Forbidden: bot was kicked from the group",76 "Forbidden: can't send messages in this chat"77 ],78 solution: "Check bot permissions and chat role"79 },80 81 404: {82 code: "NOT_FOUND",83 description: "Requested resource was not found",84 common_causes: [85 "Invalid chat ID",86 "Message not found",87 "User not found",88 "File not found",89 "Sticker set not found"90 ],91 examples: [92 "Chat not found",93 "Message to delete not found",94 "User not found"95 ],96 solution: "Verify resource IDs and existence"97 },98 99 405: {100 code: "METHOD_NOT_ALLOWED",101 description: "HTTP method not supported for this endpoint",102 common_causes: [103 "Using GET instead of POST",104 "Wrong HTTP method",105 "Endpoint doesn't support requested method"106 ],107 examples: [108 "Method not allowed",109 "This endpoint requires POST requests"110 ],111 solution: "Use correct HTTP method for the endpoint"112 },113 114 406: {115 code: "NOT_ACCEPTABLE",116 description: "Request format not acceptable",117 common_causes: [118 "Unsupported content type",119 "Invalid encoding",120 "Language/locale not supported"121 ],122 examples: [123 "Content type not supported",124 "Language not available"125 ],126 solution: "Check request headers and content type"127 },128 129 409: {130 code: "CONFLICT",131 description: "Conflict with existing resource or operation",132 common_causes: [133 "Terminating other polls",134 "Duplicate request",135 "Race condition",136 "Webhook already set"137 ],138 examples: [139 "Conflict: terminated by other poll",140 "Conflict: webhook was already set"141 ],142 solution: "Wait for operation to complete or check resource state"143 },144 145 413: {146 code: "REQUEST_ENTITY_TOO_LARGE",147 description: "Request payload too large",148 common_causes: [149 "File too big for upload",150 "Message text too long",151 "Too many entities in message",152 "Caption too long"153 ],154 examples: [155 "File too large: max 50MB",156 "Message text is too long",157 "Caption exceeds 1024 characters"158 ],159 solution: "Reduce file size or split content"160 },161 162 414: {163 code: "REQUEST_URI_TOO_LONG",164 description: "Request URI too long",165 common_causes: [166 "Too many query parameters",167 "URL length exceeded",168 "Deep linking parameters too long"169 ],170 examples: [171 "Request URI too long",172 "Too many parameters in deep link"173 ],174 solution: "Reduce parameters or use POST instead"175 },176 177 415: {178 code: "UNSUPPORTED_MEDIA_TYPE",179 description: "Unsupported media type",180 common_causes: [181 "Unsupported file format",182 "Invalid MIME type",183 "Media type not allowed for this method"184 ],185 examples: [186 "Unsupported media type",187 "File format not supported"188 ],189 solution: "Check supported formats and MIME types"190 },191 192 422: {193 code: "UNPROCESSABLE_ENTITY",194 description: "Request well-formed but semantically incorrect",195 common_causes: [196 "Invalid inline query data",197 "Malformed callback data",198 "Invalid webhook configuration",199 "Wrong parameter combination"200 ],201 examples: [202 "Invalid inline_query_id",203 "Callback data too long",204 "Webhook URL is invalid"205 ],206 solution: "Validate business logic and parameter combinations"207 },208 209 // 429 Rate Limiting210 429: {211 code: "FLOOD_WAIT",212 description: "Too many requests - rate limiting",213 common_causes: [214 "Sending messages too fast",215 "Too many API calls",216 "Spam protection triggered",217 "Too many inline queries"218 ],219 examples: [220 "Flood control: retry after 10 seconds",221 "Too many requests: retry later"222 ],223 solution: "Wait for the specified time before retrying, implement exponential backoff"224 },225 226 // 5xx Server Errors227 500: {228 code: "INTERNAL_SERVER_ERROR",229 description: "Internal server error from Telegram",230 common_causes: [231 "Telegram server issues",232 "Temporary API problems",233 "Maintenance periods",234 "Backend service failures"235 ],236 examples: [237 "Internal server error",238 "Server unavailable"239 ],240 solution: "Retry after some time, check Telegram status"241 },242 243 502: {244 code: "BAD_GATEWAY",245 description: "Invalid response from upstream server",246 common_causes: [247 "Telegram API gateway issues",248 "Proxy server problems",249 "Network routing issues"250 ],251 examples: [252 "Bad Gateway",253 "Invalid response from upstream"254 ],255 solution: "Retry later, check network connectivity"256 },257 258 503: {259 code: "SERVICE_UNAVAILABLE",260 description: "Service temporarily unavailable",261 common_causes: [262 "Telegram API maintenance",263 "Server overload",264 "Temporary outage"265 ],266 examples: [267 "Service unavailable",268 "Server overloaded"269 ],270 solution: "Wait and retry, check Telegram status page"271 },272 273 504: {274 code: "GATEWAY_TIMEOUT",275 description: "Upstream server timeout",276 common_causes: [277 "Telegram API timeout",278 "Slow response from servers",279 "Network latency"280 ],281 examples: [282 "Gateway timeout",283 "Upstream server timed out"284 ],285 solution: "Retry with backoff, check network conditions"286 },287 288 // Telegram-specific Bot API Errors289 "BOT_BLOCKED": {290 code: "BOT_BLOCKED",291 description: "Bot was blocked by the user",292 common_causes: [293 "User manually blocked the bot",294 "Bot was removed from chat",295 "User deleted chat with bot"296 ],297 examples: [298 "Forbidden: bot was blocked by the user",299 "User is deactivated"300 ],301 solution: "Cannot send messages to blocked users"302 },303 304 "BOT_KICKED": {305 code: "BOT_KICKED",306 description: "Bot was kicked from group or channel",307 common_causes: [308 "Admin removed bot from group",309 "Bot lost admin privileges",310 "Channel owner removed bot"311 ],312 examples: [313 "Forbidden: bot was kicked from the group chat",314 "Forbidden: bot is not a member of the channel"315 ],316 solution: "Re-add bot to the chat or request admin permissions"317 },318 319 "CHAT_NOT_FOUND": {320 code: "CHAT_NOT_FOUND",321 description: "Chat does not exist or bot has no access",322 common_causes: [323 "Invalid chat ID",324 "Chat was deleted",325 "Bot never joined the chat",326 "Private chat not started"327 ],328 examples: [329 "Chat not found",330 "Invalid chat_id"331 ],332 solution: "Verify chat ID and ensure bot has access"333 },334 335 "MESSAGE_NOT_FOUND": {336 code: "MESSAGE_NOT_FOUND",337 description: "Message does not exist or not accessible",338 common_causes: [339 "Message was deleted",340 "Invalid message ID",341 "Bot can't access the message",342 "Message from another chat"343 ],344 examples: [345 "Message to delete not found",346 "Message to edit not found",347 "Message to pin not found"348 ],349 solution: "Check message ID and bot permissions"350 },351 352 "USER_NOT_FOUND": {353 code: "USER_NOT_FOUND",354 description: "User does not exist or not accessible",355 common_causes: [356 "Invalid user ID",357 "User deactivated account",358 "User never interacted with bot",359 "Privacy restrictions"360 ],361 examples: [362 "User not found",363 "User is deactivated"364 ],365 solution: "Verify user ID and ensure user exists"366 },367 368 "MESSAGE_TOO_LONG": {369 code: "MESSAGE_TOO_LONG",370 description: "Message text exceeds maximum length",371 common_causes: [372 "Text message over 4096 characters",373 "Caption over 1024 characters",374 "Too many formatting entities"375 ],376 examples: [377 "Message is too long",378 "Caption exceeds maximum length"379 ],380 solution: "Split message into multiple parts or shorten text"381 },382 383 "INVALID_FILE_ID": {384 code: "INVALID_FILE_ID",385 description: "Provided file ID is invalid or expired",386 common_causes: [387 "File ID expired",388 "Wrong file ID format",389 "File no longer available",390 "Using file ID from different bot"391 ],392 examples: [393 "Invalid file_id",394 "Wrong file identifier"395 ],396 solution: "Re-upload file or get fresh file ID"397 },398 399 "NETWORK_ERROR": {400 code: "NETWORK_ERROR",401 description: "Network connectivity issues",402 common_causes: [403 "Internet connection lost",404 "DNS resolution failed",405 "Proxy issues",406 "Telegram server unreachable"407 ],408 examples: [409 "Network error",410 "Connection timeout",411 "Failed to connect to Telegram API"412 ],413 solution: "Check internet connection and retry"414 },415 416 "FLOOD_CONTROL": {417 code: "FLOOD_CONTROL",418 description: "Too many requests to Telegram API",419 common_causes: [420 "Sending messages too frequently",421 "Exceeding API rate limits",422 "Spam-like behavior detected",423 "Too many inline queries"424 ],425 examples: [426 "Flood control: retry after 3600 seconds",427 "Too many requests: retry later"428 ],429 solution: "Implement exponential backoff and respect retry_after parameter"430 },431 432 "MIGRATE_TO_CHAT_ID": {433 code: "MIGRATE_TO_CHAT_ID",434 description: "Group migrated to supergroup",435 common_causes: [436 "Group upgraded to supergroup",437 "Chat ID changed after migration"438 ],439 examples: [440 "Migrate to chat id 123456789"441 ],442 solution: "Use the new chat ID provided in the error response"443 },444 445 "QUERY_TOO_OLD": {446 code: "QUERY_TOO_OLD",447 description: "Inline query is too old to answer",448 common_causes: [449 "User took too long to select result",450 "Inline query expired",451 "Server timeout for inline query"452 ],453 examples: [454 "Query is too old",455 "Inline query expired"456 ],457 solution: "Answer inline queries promptly within the time limit"458 },459 460 "CANNOT_PARSE_ENTITIES": {461 code: "CANNOT_PARSE_ENTITIES",462 description: "Failed to parse message entities",463 common_causes: [464 "Invalid Markdown formatting",465 "Malformed HTML tags",466 "Unclosed formatting tags",467 "Invalid entity offsets"468 ],469 examples: [470 "Can't parse entities",471 "Invalid entity format"472 ],473 solution: "Validate message formatting before sending"474 },475 476 "BUTTON_DATA_INVALID": {477 code: "BUTTON_DATA_INVALID",478 description: "Invalid inline keyboard button data",479 common_causes: [480 "Callback data too long (max 64 bytes)",481 "Invalid URL format",482 "Wrong button type",483 "Malformed switch inline query"484 ],485 examples: [486 "Button data invalid",487 "Callback data is too long"488 ],489 solution: "Check button data length and format"490 },491 492 "WEBHOOK_NOT_SET": {493 code: "WEBHOOK_NOT_SET",494 description: "Webhook is not set but required for this operation",495 common_causes: [496 "Trying to use webhook methods without setting webhook",497 "Webhook was removed",498 "getUpdates method being used instead of webhook"499 ],500 examples: [501 "Webhook is not set"502 ],503 solution: "Set webhook first or use getUpdates method"504 },505 506 "WEBHOOK_CONFLICT": {507 code: "WEBHOOK_CONFLICT",508 description: "Conflict between webhook and getUpdates method",509 common_causes: [510 "Using both webhook and getUpdates simultaneously",511 "Another instance using webhook",512 "getUpdates called while webhook is active"513 ],514 examples: [515 "Conflict: webhook and getUpdates cannot be used together"516 ],517 solution: "Use either webhook or getUpdates, not both"518 },519 520 // Additional Common Telegram Bot Errors521 "PEER_ID_INVALID": {522 code: "PEER_ID_INVALID",523 description: "Invalid peer/chat/user ID provided",524 common_causes: [525 "Wrong ID format",526 "Non-existent ID",527 "Using username instead of ID",528 "ID from different context"529 ],530 examples: [531 "Invalid peer id",532 "Chat id is invalid"533 ],534 solution: "Verify ID format and context"535 },536 537 "PHONE_NUMBER_INVALID": {538 code: "PHONE_NUMBER_INVALID",539 description: "Invalid phone number format",540 common_causes: [541 "Wrong number format",542 "Missing country code",543 "Non-existent number",544 "Number not on Telegram"545 ],546 examples: [547 "Phone number invalid",548 "Invalid phone number format"549 ],550 solution: "Check phone number format with country code"551 },552 553 "PHOTO_INVALID_DIMENSIONS": {554 code: "PHOTO_INVALID_DIMENSIONS",555 description: "Photo dimensions are invalid",556 common_causes: [557 "Photo too small",558 "Wrong aspect ratio",559 "Dimensions out of allowed range"560 ],561 examples: [562 "Photo dimensions invalid",563 "Photo too small for profile"564 ],565 solution: "Use photo with proper dimensions and aspect ratio"566 },567 568 "STICKER_SET_INVALID": {569 code: "STICKER_SET_INVALID",570 description: "Sticker set not found or invalid",571 common_causes: [572 "Wrong sticker set name",573 "Sticker set deleted",574 "Bot doesn't own the sticker set"575 ],576 examples: [577 "Sticker set not found",578 "Invalid sticker set name"579 ],580 solution: "Verify sticker set name and ownership"581 },582 583 "REPLY_MESSAGE_NOT_FOUND": {584 code: "REPLY_MESSAGE_NOT_FOUND",585 description: "Message to reply to not found",586 common_causes: [587 "Reply message deleted",588 "Invalid reply_to_message_id",589 "Reply message in different chat"590 ],591 examples: [592 "Reply message not found",593 "Invalid reply message id"594 ],595 solution: "Check reply message ID and chat context"596 },597 598 "MESSAGE_ID_INVALID": {599 code: "MESSAGE_ID_INVALID",600 description: "Invalid message identifier",601 common_causes: [602 "Wrong message ID format",603 "Message ID out of range",604 "Non-existent message ID"605 ],606 examples: [607 "Invalid message id",608 "Message identifier invalid"609 ],610 solution: "Verify message ID format and existence"611 },612 613 "CHAT_ADMIN_REQUIRED": {614 code: "CHAT_ADMIN_REQUIRED",615 description: "Bot requires admin privileges for this action",616 common_causes: [617 "Trying to ban users without admin rights",618 "Attempting to pin messages as non-admin",619 "Changing chat info without permissions"620 ],621 examples: [622 "Chat admin required",623 "Not enough rights to perform this action"624 ],625 solution: "Make bot admin in the chat or request permissions"626 },627 628 "INLINE_RESULT_EXPIRED": {629 code: "INLINE_RESULT_EXPIRED",630 description: "Inline result cache expired",631 common_causes: [632 "Inline result too old",633 "Cache timeout reached",634 "Server cleared inline cache"635 ],636 examples: [637 "Inline result expired",638 "Cached result no longer available"639 ],640 solution: "Regenerate inline query results"641 },642 643 "CANNOT_INITIATE_CONVERSATION": {644 code: "CANNOT_INITIATE_CONVERSATION",645 description: "Bot cannot start conversation with user first",646 common_causes: [647 "User never started chat with bot",648 "Privacy settings prevent bot from messaging first",649 "User blocked bot before conversation started"650 ],651 examples: [652 "Cannot initiate conversation with user",653 "Bot can't send first message to user"654 ],655 solution: "User must start conversation with /start command first"656 },657 658 "TOO_MANY_REQUESTS": {659 code: "TOO_MANY_REQUESTS",660 description: "Rate limit exceeded for specific method",661 common_causes: [662 "Sending messages too fast to same chat",663 "Too many API calls in short period",664 "Exceeding per-chat rate limits"665 ],666 examples: [667 "Too many requests",668 "Rate limit exceeded"669 ],670 solution: "Implement rate limiting and backoff in your bot"671 },672 673 "GROUP_CHAT_MIGRATED": {674 code: "GROUP_CHAT_MIGRATED",675 description: "Group chat was upgraded to supergroup",676 common_causes: [677 "Group reached member limit",678 "Admin enabled supergroup features",679 "Automatic migration"680 ],681 examples: [682 "Group chat migrated to supergroup"683 ],684 solution: "Use the new supergroup chat ID"685 },686 687 "BUTTON_URL_INVALID": {688 code: "BUTTON_URL_INVALID",689 description: "Invalid URL in inline keyboard button",690 common_causes: [691 "Malformed URL",692 "Unsupported URL scheme",693 "URL too long",694 "Invalid domain"695 ],696 examples: [697 "Button URL invalid",698 "Invalid URL format"699 ],700 solution: "Check URL format and validity"701 }702};703// Search errors by code, name, or description704function searchErrors(query) {705 const results = [];706 const q = query.toLowerCase().trim();707 708 // Search by error code (numeric or string)709 if (q.match(/^\d{3}$/)) {710 // Numeric code search711 const code = parseInt(q);712 if (errorCodes[code]) {713 results.push({714 ...errorCodes[code],715 httpCode: code,716 type: 'http'717 });718 }719 } else if (errorCodes[q.toUpperCase()]) {720 // String code search (like "BOT_BLOCKED")721 const code = q.toUpperCase();722 results.push({723 ...errorCodes[code],724 errorCode: code,725 type: 'telegram'726 });727 }728 729 // If we found exact matches, return them730 if (results.length > 0) {731 return results;732 }733 734 // Search by code name or description735 Object.entries(errorCodes).forEach(([code, data]) => {736 const searchText = `${code} ${data.code} ${data.description} ${data.common_causes?.join(' ')} ${data.examples?.join(' ')}`.toLowerCase();737 738 if (searchText.includes(q)) {739 // Determine if it's an HTTP code or Telegram error code740 const isHttpCode = !isNaN(code) && code.length === 3;741 if (isHttpCode) {742 results.push({743 ...data,744 httpCode: parseInt(code),745 type: 'http'746 });747 } else {748 results.push({749 ...data,750 errorCode: code,751 type: 'telegram'752 });753 }754 }755 });756 757 return results;758}759 760// Get specific error by code761function getErrorByCode(code) {762 // Handle both string and number codes763 if (typeof code === 'number' || (typeof code === 'string' && !isNaN(code))) {764 const numericCode = parseInt(code);765 return errorCodes[numericCode] ? {766 ...errorCodes[numericCode],767 httpCode: numericCode,768 type: 'http'769 } : null;770 } else if (typeof code === 'string') {771 const stringCode = code.toUpperCase();772 return errorCodes[stringCode] ? {773 ...errorCodes[stringCode],774 errorCode: stringCode,775 type: 'telegram'776 } : null;777 }778 return null;779}780 781// Get all errors starting with specific letter782function getErrorsByLetter(letter) {783 const results = [];784 Object.entries(errorCodes).forEach(([code, data]) => {785 if (data.code.toLowerCase().startsWith(letter.toLowerCase())) {786 // Determine if it's an HTTP code or Telegram error code787 const isHttpCode = !isNaN(code) && code.length === 3;788 if (isHttpCode) {789 results.push({790 ...data,791 httpCode: parseInt(code),792 type: 'http'793 });794 } else {795 results.push({796 ...data,797 errorCode: code,798 type: 'telegram'799 });800 }801 }802 });803 return results;804}805 806// Get all errors for listing807function getAllErrors() {808 return Object.entries(errorCodes).map(([code, data]) => {809 // Determine if it's an HTTP code or Telegram error code810 const isHttpCode = !isNaN(code) && code.length === 3;811 if (isHttpCode) {812 return {813 ...data,814 httpCode: parseInt(code),815 type: 'http'816 };817 } else {818 return {819 ...data,820 errorCode: code,821 type: 'telegram'822 };823 }824 });825}826 827module.exports = {828 errorCodes,829 searchErrors,830 getErrorByCode,831 getErrorsByLetter,832 getAllErrors833};