teled

package module
v0.5.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jun 14, 2026 License: Apache-2.0 Imports: 3 Imported by: 0

README

teled

WIP Testing Telegram (MTProto) Server in Go, based on gotd.

Documentation is in progress.

Do not use Telegram name or branding for custom clients.

Private keys

Generate new RSA private key and save armored keys to some file. You will need to vendor public keys to your clients.

Testing key
-----BEGIN RSA PRIVATE KEY-----
MIIEpQIBAAKCAQEAwX3W9oxq8FdwkMOA/HNeeDJOx8pF6fIw4MrtbfsYPhc5yTs0
lg6H3ia4SmUTnpbJ+NhGxQX2nhDR6911SETBIq1Iz0OUuOPyDVhVhyZzF+vzBukU
E75slPy3UzAzAyruOT5iCoX7mCDhRHWh9Rhm2HHVC02LAKM7RYx6u3WyjI4LV1a1
FplaD0wTh1ElJQcHkRsCVJzfD2fCSrkO/F2QNuOdEe9uoyIFGZjTX82GJNd/H6DX
KB4XQ158yJifZBwZohH9q/7IYrTEGUreQyMjeL1CiROwYKSEmHOaDnLWqq4u8KSm
jhqNeQnhbTFuwG958vSX1zJOqkDkXlue/1XeMQIDAQABAoIBAQCzEzIV8JMwaNyn
Pilse6HdAEJlKdFW2W1fPrBLb25aWMiEcyUSE9SvR4qcX7uutMOsaQ3mXsSGOe7u
qoFXJzrQSyvtlxBXpa9ppm1RrcYrR5YeuSx5sW1w3gsVFLDBp8Peetvl/WaCvzt9
Tplb6v+UJpYT5epV5rx+e6tDP4TGCzr8aWqM+dA1Pz6eahu9YgRQCUrKogRGqKoM
187Mf5r7IpM0YdXgSnFQ8Pk2+JGYuqR8cjbf+KO/NSfxDWrzNY5jtz1sB7oUhzSV
5ySV1cLNNvrSViiZ/lMjaNd5IclLsJogKdQX6zFJY4uZUuvXi7WY4mJMAudRjcMl
HpQtLAABAoGBAMxDwCfWhGvR3KTl9N4AxmzQfSru7leq+DKFGlwqiQAmCm8SHPsH
ZMLUgOy1nVIP4ZsmSuPCou36CI4EVLHg0ODIeLpp5XHxcnITGNaTajji2ZBK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JzfD2fCSrkO/F2QNuOdEe9uoyIFGZjTX82GJNd/H6DXKB4X\n\
Q158yJifZBwZohH9q/7IYrTEGUreQyMjeL1CiROwYKSEmHOaDnLWqq4u8KSmjhqN\n\
eQnhbTFuwG958vSX1zJOqkDkXlue/1XeMQIDAQAB\n\
-----END RSA PUBLIC KEY-----" };
go install ./cmd/teled
teled --key _testdata/test.key.pem
tdesktop

Update following files:

  • Telegram/SourceFiles/mtproto/details/mtproto_domain_resolver.cpp
  • Telegram/SourceFiles/mtproto/mtp_instance.cpp
  • Telegram/SourceFiles/mtproto/mtp_instance.h
  • Telegram/SourceFiles/mtproto/mtproto_dc_options.cpp

Instead, you can use gotd/tdesktop fork.

Building docker image for fork
pip install poetry

git clone --recursive https://github.com/gotd/tdesktop.git
cd tdesktop/Telegram/build/docker/centos_env
poetry install
poetry run gen_dockerfile | docker build -t tdesktop:centos_env -
Building fork

From tdesktop root directory:

docker run --user $(id -u "$USER") --rm -it \
    -v $PWD:/usr/src/tdesktop \
    -e DEBUG=1 \
    tdesktop:centos_env \
    /usr/src/tdesktop/Telegram/build/docker/centos_env/build.sh \
    -D TDESKTOP_API_ID=17349 \
    -D TDESKTOP_API_HASH=344583e45741c457fe1862106095a5eb \
    -D DESKTOP_APP_USE_PACKAGED=OFF

Documentation

Overview

Package teled implements Telegram Server in Go.

Index

Constants

View Source
const (
	BotFatherStepNewBotName     = "newbot_name"     // awaiting the new bot's display name
	BotFatherStepNewBotUsername = "newbot_username" // awaiting the new bot's username
	BotFatherStepRevokeSelect   = "revoke_select"   // awaiting which bot's token to revoke
)

BotFather conversation steps. An empty step means no flow is in progress.

View Source
const BotFatherID int64 = 93372553

BotFatherID is the fixed user id of the built-in BotFather account. It mirrors real Telegram's BotFather id and is seeded by migration.

Variables

This section is empty.

Functions

This section is empty.

Types

type BotCommand added in v0.4.0

type BotCommand struct {
	Command     string `json:"command"`
	Description string `json:"description"`
}

BotCommand is one entry in a bot's published command list.

type BotFatherState added in v0.4.0

type BotFatherState struct {
	Step      string
	DraftName string // the pending bot name captured during /newbot
}

BotFatherState is a user's position in a multi-step BotFather flow.

type DeleteResult

type DeleteResult struct {
	Pts      int
	PtsCount int
	LocalIDs []int64 // the caller's local ids actually deleted
}

DeleteResult is the outcome of deleting messages.

type Dialog

type Dialog struct {
	PeerUserID     int64
	TopMessageID   int64
	ReadInboxMaxID int64
	UnreadCount    int
}

Dialog is one conversation in an account's dialog list.

type EditResult

type EditResult struct {
	SelfLocalID int64
	SelfPts     int
	PeerUserID  int64
	PeerLocalID int64 // 0 when the peer has no copy (self-chat)
	PeerPts     int
	Date        time.Time
	EditDate    time.Time
}

EditResult is the outcome of editing a message.

type File

type File struct {
	ID            int64
	OwnerUserID   int64
	AccessHash    int64
	ObjectKey     string
	Size          int64
	Mime          string
	SHA256        []byte
	FileReference []byte
	Kind          string // "photo" or "document"
	CreatedAt     time.Time
}

File is stored media metadata. The blob lives in the ObjectStore at ObjectKey.

type Message

type Message struct {
	GlobalID   int64     // canonical id, shared by both participants
	LocalID    int64     // viewer's per-account message id
	FromUserID int64     // sender
	PeerUserID int64     // the other party in the conversation
	Out        bool      // true if the viewer is the sender
	Text       string    // message text
	Date       time.Time // sent time
	EditDate   time.Time // zero if never edited
	RandomID   int64     // sender-provided dedup id
	Media      *File     // attached media, nil when text-only
}

Message is a DM message from the perspective of one account (the viewer).

type ObjectInfo

type ObjectInfo struct {
	// Size is the object size in bytes.
	Size int64
}

ObjectInfo describes a stored object.

type ObjectStore

type ObjectStore interface {
	// Put stores r under key. size is the exact number of bytes in r.
	Put(ctx context.Context, key string, r io.Reader, size int64, opt PutOptions) error
	// Get returns the full object. The caller must Close the reader.
	Get(ctx context.Context, key string) (io.ReadCloser, error)
	// GetRange returns length bytes starting at offset. It is the primitive
	// behind upload.getFile chunking. The caller must Close the reader.
	GetRange(ctx context.Context, key string, offset, length int64) (io.ReadCloser, error)
	// Stat returns object metadata.
	Stat(ctx context.Context, key string) (ObjectInfo, error)
	// Delete removes the object. Deleting a missing object is not an error.
	Delete(ctx context.Context, key string) error
}

ObjectStore is an S3-shaped blob store for media (photos, documents, video). Keys are opaque; callers use content-addressed keys. The local-filesystem implementation lives in internal/objstore; an S3-compatible backend can be added behind the same interface.

type PutOptions

type PutOptions struct {
	// ContentType is an advisory MIME type. Backends may ignore it; the
	// authoritative MIME is tracked in the files table.
	ContentType string
}

PutOptions are optional parameters for ObjectStore.Put.

type SentMessage

type SentMessage struct {
	GlobalID         int64
	Date             time.Time
	SenderLocalID    int64
	SenderPts        int
	RecipientLocalID int64
	RecipientPts     int
	SelfChat         bool // true when sender == peer (no separate recipient copy)
}

SentMessage is the result of persisting a DM: the per-account local ids and pts allocated for each participant.

type State

type State struct {
	Pts         int
	Qts         int
	Seq         int
	Date        time.Time
	UnreadCount int
}

State is an account's update sequence state.

type UpdateLogEntry

type UpdateLogEntry struct {
	Pts      int
	PtsCount int
	Type     string
	GlobalID *int64
	Extra    []byte
	Date     time.Time
}

UpdateLogEntry is one durable update in an account's log, used to build updates.getDifference responses.

type User

type User struct {
	ID         int64
	AccessHash int64
	Phone      string
	Username   string
	FirstName  string
	LastName   string
	About      string
	IsBot      bool   // true for bot accounts authenticated by token
	BotToken   string // bot auth token, empty for human accounts
	CreatedAt  time.Time
}

User is a teled account.

Directories

Path Synopsis
cmd
teled command
Binary teled implements Telegram Server in Go.
Binary teled implements Telegram Server in Go.
Package gorules contains ruleguard linter rules.
Package gorules contains ruleguard linter rules.
internal
cmd
Package cmd implements commands of teled binary.
Package cmd implements commands of teled binary.
db
Package db implements PostgreSQL-backed storage for teled.
Package db implements PostgreSQL-backed storage for teled.
key
Package key implements RSA private key management.
Package key implements RSA private key management.
mtproto
Package mtproto implements a custom MTProto server for teled.
Package mtproto implements a custom MTProto server for teled.
objstore
Package objstore provides ObjectStore implementations.
Package objstore provides ObjectStore implementations.
obs
Package obs holds small helpers shared by the OpenTelemetry instrumentation across teled's internal packages.
Package obs holds small helpers shared by the OpenTelemetry instrumentation across teled's internal packages.
pgtest
Package pgtest provides a throwaway PostgreSQL container for tests.
Package pgtest provides a throwaway PostgreSQL container for tests.
queue
Package queue wires the River background job queue over PostgreSQL.
Package queue wires the River background job queue over PostgreSQL.
rpc
Package rpc implements teled's Telegram RPC handlers over tg.ServerDispatcher.
Package rpc implements teled's Telegram RPC handlers over tg.ServerDispatcher.
Package server assembles teled's storage, RPC handlers and MTProto transport into a single embeddable Telegram server.
Package server assembles teled's storage, RPC handlers and MTProto transport into a single embeddable Telegram server.
Package teledtest runs a real teled Telegram server in-process for tests.
Package teledtest runs a real teled Telegram server in-process for tests.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL