{"record":{"id":"c3754d8719e7b3b4","repo":"Tencent/WeKnora","slug":"unsupported-telegram-mode-s","errorCode":null,"errorMessage":"unsupported telegram mode: %s","messagePattern":"unsupported telegram mode: (.+?)","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"internal/im/telegram/factory.go","lineNumber":44,"sourceCode":"\t\t\tsecretToken := im.GetString(creds, \"secret_token\")\n\t\t\tadapter := NewWebhookAdapter(botToken, secretToken)\n\t\t\treturn adapter, nil, nil\n\n\t\tcase \"websocket\":\n\t\t\tclient := NewLongConnClient(botToken, msgHandler)\n\n\t\t\twsCtx, wsCancel := context.WithCancel(context.Background())\n\t\t\tgo func() {\n\t\t\t\tif err := client.Start(wsCtx); err != nil && wsCtx.Err() == nil {\n\t\t\t\t\tlogger.Errorf(context.Background(), \"[IM] Telegram long polling stopped for channel %s: %v\", channel.ID, err)\n\t\t\t\t}\n\t\t\t}()\n\n\t\t\tadapter := NewAdapter(client, botToken)\n\t\t\treturn adapter, wsCancel, nil\n\n\t\tdefault:\n\t\t\treturn nil, nil, fmt.Errorf(\"unsupported telegram mode: %s\", mode)\n\t\t}\n\t}\n}\n","sourceCodeStart":26,"sourceCodeEnd":48,"githubUrl":"https://github.com/Tencent/WeKnora/blob/988cbb03305e055d8ebb7d46d9ac6cc0803cd074/internal/im/telegram/factory.go#L26-L48","documentation":"The Telegram adapter factory builds an adapter based on the channel's configured mode (e.g. long-polling or webhook). This error is returned from the switch statement's default branch in NewFactory when the mode string stored on the IMChannel does not match any supported Telegram mode constant. It indicates a configuration/typo problem in the channel record, not a runtime failure.","triggerScenarios":"Calling the Telegram adapter factory (or creating/saving a Telegram IMChannel that the factory later consumes) with a mode string other than the supported Telegram mode constants — e.g. mode set to \"webhook\" when only \"polling\" is defined, or an empty/garbage value.","commonSituations":"Typo in the channel's mode field when creating a Telegram channel in the admin UI or via SQL; seeding scripts using lowercase/uppercase mismatch; copying a mode value from another platform (e.g. Slack/WeChat) that Telegram's factory doesn't support.","solutions":["Check the IMChannel.mode value for the Telegram channel and correct it to a supported constant (e.g. polling).","Inspect internal/im/telegram/factory.go:44 for the exact set of supported mode constants and use one verbatim.","If the mode came from user input, validate it against the supported set before persisting the channel."],"exampleFix":"// before\nchannel.Mode = \"webhook\"\n// after\nchannel.Mode = im.TelegramModePolling","handlingStrategy":"validation","validationCode":"var supportedModes = map[string]bool{\"polling\": true /* see factory.go for full set */}\nif !supportedModes[channel.Mode] {\n    return fmt.Errorf(\"telegram mode %q not supported; must be one of the im.TelegramMode* constants\", channel.Mode)\n}","typeGuard":"func isSupportedTelegramMode(mode string) bool {\n    switch im.TelegramMode(mode) {\n    case im.TelegramModePolling /*, others from factory.go */:\n        return true\n    }\n    return false\n}","tryCatchPattern":"adapter, cancel, err := factory(ctx, ch, handler)\nif err != nil {\n    var cfgErr = err // contains \"unsupported telegram mode\"\n    log.Errorf(\"channel %d misconfigured: %v — fix mode and re-create adapter\", ch.ID, cfgErr)\n    return ErrChannelMisconfigured\n}","preventionTips":["Always build the mode from exported im constants, never raw strings.","Validate mode at the channel-create API boundary before persisting.","Cover the factory switch with a table-driven test enumerating all supported modes."],"tags":["configuration","telegram","im-adapter"],"backgroundTag":"unsupported-config-value","analyzedSha":"988cbb03305e055d8ebb7d46d9ac6cc0803cd074","analyzedAt":"2026-09-02T14:41:08.344Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T10:18:20.063Z"}