MCPcopy Index your code
hub / github.com/KaoriEl/go-tdlib

github.com/KaoriEl/go-tdlib @v2.0.0

Chat with this repo
repository ↗ · DeepWiki ↗ · release v2.0.0 ↗ · + Follow
8,374 symbols 16,281 edges 437 files 8,025 documented · 96% updated 3y agov2.0.0 · 2021-12-23★ 382 open issues
What it actually does AI analysis from the code graph — generated when you open this
loading…
README

go-tdlib

Golang Telegram TdLib JSON bindings

Install

To install, you need to run inside a docker container (it is given below)

go get -u github.com/kaoriEl/go-tdlib

Introduction

Library for working with golang based on tdlib.

This library was taken from the user Arman92 and changed for the current version of tdlib.

Telegram Tdlib is a complete library for creating telegram clients, it also has a simple tdjson ready-to-use library to ease the integration with different programming languages and platforms.

go-tdlib is a complete tdlib-tdjson binding package to help you create your own Telegram clients.

NOTE: basic tdjson-golang binding is inspired from this package: go-tdjson

All the classes and functions declared in Tdlib TypeLanguage schema So you can use every single type and method in Tdlib.

Key features:

  • Autogenerated golang structs and methods of tdlib .tl schema
  • Custom event receivers defined by user (e.g. get only text messages from a specific user)
  • Supports all tdjson functions: Send(), Execute(), Receive(), Destroy(), SetFilePath(), SetLogVerbosityLevel()
  • Supports all tdlib functions and types

Docker

You can use prebuilt tdlib with following Docker image:

DockerFile with supervisord:

FROM jancimertel/golang-1.16-tdlib AS build

WORKDIR ./var/www

# Updates the repository and installs git
RUN apk update && apk upgrade && \
    apk add --no-cache git supervisor

RUN apk update && apk add --no-cache supervisor

COPY ./%YourPath%/supervisord.conf /etc/supervisord.conf


COPY /%YourGoScript% .
RUN go mod download

# Runs the binary once the container starts
CMD ["/usr/bin/supervisord", "-n"]

Example

Here is a simple example for authorization and fetching updates:

package main

import (
    "fmt"

    "github.com/kaoriEl/go-tdlib"
)

func main() {
    tdlib.SetLogVerbosityLevel(1)
    tdlib.SetFilePath("./errors.txt")

    // Create new instance of client
    client := tdlib.NewClient(tdlib.Config{
        APIID:               "187786",
        APIHash:             "e782045df67ba48e441ccb105da8fc85",
        SystemLanguageCode:  "en",
        DeviceModel:         "Server",
        SystemVersion:       "1.0.0",
        ApplicationVersion:  "1.0.0",
        UseMessageDatabase:  true,
        UseFileDatabase:     true,
        UseChatInfoDatabase: true,
        UseTestDataCenter:   false,
        DatabaseDirectory:   "./tdlib-db",
        FileDirectory:       "./tdlib-files",
        IgnoreFileNames:     false,
    })

    for {
        currentState, _ := client.Authorize()
        if currentState.GetAuthorizationStateEnum() == tdlib.AuthorizationStateWaitPhoneNumberType {
            fmt.Print("Enter phone: ")
            var number string
            fmt.Scanln(&number)
            _, err := client.SendPhoneNumber(number)
            if err != nil {
                fmt.Printf("Error sending phone number: %v", err)
            }
        } else if currentState.GetAuthorizationStateEnum() == tdlib.AuthorizationStateWaitCodeType {
            fmt.Print("Enter code: ")
            var code string
            fmt.Scanln(&code)
            _, err := client.SendAuthCode(code)
            if err != nil {
                fmt.Printf("Error sending auth code : %v", err)
            }
        } else if currentState.GetAuthorizationStateEnum() == tdlib.AuthorizationStateWaitPasswordType {
            fmt.Print("Enter Password: ")
            var password string
            fmt.Scanln(&password)
            _, err := client.SendAuthPassword(password)
            if err != nil {
                fmt.Printf("Error sending auth password: %v", err)
            }
        } else if currentState.GetAuthorizationStateEnum() == tdlib.AuthorizationStateReadyType {
            fmt.Println("Authorization Ready! Let's rock")
            break
        }
    }

    // Main loop
    for update := range client.RawUpdates {
        // Show all updates
        fmt.Println(update.Data)
        fmt.Print("\n\n")
    }

}

More examples can be found on examples folder

Extension points exported contracts — how you extend this code

TdMessage (Interface)
TdMessage is the interface for all messages send and received to/from tdlib [1741 implementers]
types.go
ChatAction (Interface)
ChatAction Describes the different types of activity in a chat [27 implementers]
tdlib/chatAction.go
ChatEventAction (Interface)
ChatEventAction Represents a chat event [54 implementers]
tdlib/chatEventAction.go
LanguagePackStringValue (Interface)
LanguagePackStringValue Represents the value of a string in a language pack [6 implementers]
tdlib/languagePackStringValue.go
TopChatCategory (Interface)
TopChatCategory Represents the categories of chats for which a list of frequently used chats can be retrieved [14 implementers]
tdlib/topChatCategory.go
SuggestedAction (Interface)
SuggestedAction Describes an action suggested to the current user [7 implementers]
tdlib/suggestedAction.go
TextEntityType (Interface)
TextEntityType Represents a part of the text which must be formatted differently [35 implementers]
tdlib/textEntityType.go
ChatMemberStatus (Interface)
ChatMemberStatus Provides information about the status of a member in a chat [12 implementers]
tdlib/chatMemberStatus.go

Core symbols most depended-on inside this repo

SendAndCatch
called by 451
client/client.go
SendAndCatch
called by 381
tdlib.go
unmarshalRichText
called by 33
types.go
unmarshalRichText
called by 32
tdlib/richText.go
GetAuthorizationStateEnum
called by 19
tdlib/authorizationState.go
unmarshalStatisticalGraph
called by 18
tdlib/statisticalGraph.go
unmarshalInputFile
called by 17
types.go
unmarshalStatisticsGraph
called by 17
types.go

Shape

Method 4,359
Function 1,923
Struct 1,754
TypeAlias 169
Interface 167
FuncType 2

Languages

Go100%

Modules by API surface

types.go3,501 symbols
methods.go381 symbols
tdlib/update.go369 symbols
client/ok.go202 symbols
tdlib/messageContent.go195 symbols
tdlib/chatEventAction.go137 symbols
tdlib/pageBlock.go135 symbols
tdlib/pushMessageContent.go112 symbols
tdlib/internalLinkType.go97 symbols
tdlib/richText.go85 symbols
tdlib/inputMessageContent.go81 symbols
tdlib/textEntityType.go76 symbols

For agents

$ claude mcp add go-tdlib \
  -- python -m otcore.mcp_server <graph>

⬇ download graph artifact