Tencent/WeKnora · error
parse telegram credentials: %w
Error message
parse telegram credentials: %w
What it means
The Telegram adapter factory parses channel.Credentials via im.ParseCredentials before building the bot client; malformed credentials JSON/structure causes construction to fail with this wrapped error, preserving the underlying parse error via %w.
Source
Thrown at internal/im/telegram/factory.go:17
package telegram
import (
"context"
"fmt"
"github.com/Tencent/WeKnora/internal/im"
"github.com/Tencent/WeKnora/internal/logger"
)
// NewFactory returns an im.AdapterFactory for Telegram bot channels.
// Supports "webhook" and "websocket" (long polling, default).
func NewFactory() im.AdapterFactory {
return func(factoryCtx context.Context, channel *im.IMChannel, msgHandler func(context.Context, *im.IncomingMessage) error) (im.Adapter, context.CancelFunc, error) {
creds, err := im.ParseCredentials(channel.Credentials)
if err != nil {
return nil, nil, fmt.Errorf("parse telegram credentials: %w", err)
}
botToken := im.GetString(creds, "bot_token")
mode := im.ResolveMode(channel, "websocket")
switch mode {
case "webhook":
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 {View on GitHub (pinned to 988cbb0330)
Solutions
- Ensure channel.Credentials is valid JSON, e.g. {"bot_token":"123:ABC"}
- Check the wrapped inner error (errors.Unwrap / %v of the cause) for the exact parse failure
- Fix the secret/config source so it emits a JSON object, not a bare token
Example fix
// before
credentials: "123456:ABC-DEF"
// after
credentials: "{\"bot_token\":\"123456:ABC-DEF\"}" Defensive patterns
Strategy: validation
Validate before calling
var creds map[string]string
if err := json.Unmarshal([]byte(channel.Credentials), &creds); err != nil {
return fmt.Errorf("telegram credentials must be a JSON object: %w", err)
}
if creds["bot_token"] == "" {
return errors.New("telegram credentials missing bot_token")
} Try / catch
adapter, cancel, err := telegram.NewFactory()(ctx, ch, handler)
if err != nil {
var perr error
if errors.As(err, &perr) { /* inspect unwrapped parse cause */ }
log.Printf("telegram channel %s: %v", ch.ID, err)
} Prevention
- Store credentials as JSON objects ({"bot_token":"..."}), never bare tokens
- Validate credentials JSON when the channel is created, before saving
- Ensure secret managers emit the full JSON object, not just the token string
When it happens
Trigger: Creating a Telegram channel whose Credentials field is not valid JSON (or not the expected string map) — e.g. empty credentials, single-quoted JSON, or a non-JSON secret value.
Common situations: Pasting a bot token with stray whitespace/newlines into a non-JSON field; storing credentials as YAML instead of JSON; migrating channels where the credentials column was left empty; secrets manager returning a raw token instead of a JSON object.
Related errors
- E2BAPIKey is required for the E2B backend
- failed to generate KS3 presigned URL: %w
- S3 access key and secret key must be provided together
- failed to load AWS config: %w
- failed to generate presigned URL: %w
AI-assisted analysis of Tencent/WeKnora@988cbb0330 (2026-09-02).
Data as JSON: /api/errors/4214bb7dd910b927.
Report an issue: GitHub.