Skip to main content

gotd

Telegram client in Go

A full MTProto 2.0 API client in pure Go for users and bots — the same protocol the official apps and TDLib speak, with batteries-included helpers for auth, uploads, downloads and updates.

go get github.com/gotd/td@latest

Full MTProto 2.0

Every one of the 781 API methods is generated with embedded official docs. Call any of them directly through client.API().

Users and bots

Not just the Bot API. Sign in as a user with code, password, QR or 2FA, or as a bot with a token.

Batteries included

High-level helpers for sending messages, uploads, downloads and pagination.

Fast and lightweight

  • ~150 KB per idle client
  • No runtime reflection
  • Thousands of concurrent clients

Robust

  • Automatic reconnects and DC migration
  • Update recovery engine
  • Rigorously tested against real servers

Secure and capable

Connect in a few lines

package main

import (
"context"

"github.com/gotd/td/telegram"
)

func main() {
// Get api_id and api_hash from https://my.telegram.org/apps.
client := telegram.NewClient(appID, appHash, telegram.Options{})
if err := client.Run(context.Background(), func(ctx context.Context) error {
// The client is connected only while this function runs.
api := client.API()

// Call any of the 781 MTProto methods directly.
dc, err := api.HelpGetNearestDC(ctx)
if err != nil {
return err
}
_ = dc
return nil
}); err != nil {
panic(err)
}
}

See the first-client guide and echo bot tutorial to go further.