Tencent/WeKnora · error

unsupported telegram mode: %s

Error message

unsupported telegram mode: %s

What it means

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.

Source

Thrown at internal/im/telegram/factory.go:44

			secretToken := im.GetString(creds, "secret_token")
			adapter := NewWebhookAdapter(botToken, secretToken)
			return adapter, nil, nil

		case "websocket":
			client := NewLongConnClient(botToken, msgHandler)

			wsCtx, wsCancel := context.WithCancel(context.Background())
			go func() {
				if err := client.Start(wsCtx); err != nil && wsCtx.Err() == nil {
					logger.Errorf(context.Background(), "[IM] Telegram long polling stopped for channel %s: %v", channel.ID, err)
				}
			}()

			adapter := NewAdapter(client, botToken)
			return adapter, wsCancel, nil

		default:
			return nil, nil, fmt.Errorf("unsupported telegram mode: %s", mode)
		}
	}
}

View on GitHub (pinned to 988cbb0330)

Solutions

  1. Check the IMChannel.mode value for the Telegram channel and correct it to a supported constant (e.g. polling).
  2. Inspect internal/im/telegram/factory.go:44 for the exact set of supported mode constants and use one verbatim.
  3. If the mode came from user input, validate it against the supported set before persisting the channel.

Example fix

// before
channel.Mode = "webhook"
// after
channel.Mode = im.TelegramModePolling
Defensive patterns

Strategy: validation

Validate before calling

var supportedModes = map[string]bool{"polling": true /* see factory.go for full set */}
if !supportedModes[channel.Mode] {
    return fmt.Errorf("telegram mode %q not supported; must be one of the im.TelegramMode* constants", channel.Mode)
}

Type guard

func isSupportedTelegramMode(mode string) bool {
    switch im.TelegramMode(mode) {
    case im.TelegramModePolling /*, others from factory.go */:
        return true
    }
    return false
}

Try / catch

adapter, cancel, err := factory(ctx, ch, handler)
if err != nil {
    var cfgErr = err // contains "unsupported telegram mode"
    log.Errorf("channel %d misconfigured: %v — fix mode and re-create adapter", ch.ID, cfgErr)
    return ErrChannelMisconfigured
}

Prevention

When it happens

Trigger: 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.

Common situations: 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.

Related errors


AI-assisted analysis of Tencent/WeKnora@988cbb0330 (2026-09-02). Data as JSON: /api/errors/c3754d8719e7b3b4. Report an issue: GitHub.