Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/kaoriel/go-tdlib

Library for working with golang telegram client + bot based on tdlib. This library was taken from the user Arman92 and changed for the current version of tdlib.
https://github.com/kaoriel/go-tdlib

awesome go golang golang-library php tdlib tdlib-go telegram telegram-bot telegram-cli-bot telegram-client telegram-desktop

Last synced: about 20 hours ago
JSON representation

Library for working with golang telegram client + bot based on tdlib. This library was taken from the user Arman92 and changed for the current version of tdlib.

Awesome Lists containing this project

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](https://github.com/L11R/go-tdjson)

All the classes and functions declared in [Tdlib TypeLanguage schema](https://github.com/tdlib/td/blob/master/td/generate/scheme/td_api.tl)
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:***
``` shell
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:
```golang
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](https://github.com/KaoriEl/go-tdlib/tree/master/examples)