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.

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

Owner
Rostislav Krivets
backend разработчик php golang Закончил ВКИ ( Высший Колледж Информатики)
Rostislav Krivets
Similar Resources

Parr(B)ot is a Telegram bot framework based on top of Echotron

Parr(B)ot framework A just born Telegram bot framework in Go based on top of the echotron library. You can call it Parrot, Parr-Bot, Parrot Bot, is up

Aug 22, 2022

The serverless OTP telegram service use telegram as OTP service, and send OTP through webhook

Setup OTP First thing, you need prepare API(webhook) with POST method, the payload format as below { "first_name": "Nolan", "last_name": "Nguyen",

Jul 24, 2022

Telegram bot written in Golang using gotgbot library

go_tgbot Telegram bot written in Golang using gotgbot library. How to run go get -u github.com/itsLuuke/go_tgbot rename sample.env to .env and fill in

Nov 4, 2022

Telego is Telegram Bot API library for Golang with full API implementation (one-to-one)

Telego is Telegram Bot API library for Golang with full API implementation (one-to-one)

Telego • Go Telegram Bot API Telego is Telegram Bot API library for Golang with full API implementation (one-to-one) The goal of this library was to c

Jan 5, 2023

RaspChecker - A Telegram bot that allows you to monitor your Raspberry Pi's temperature and shut it down. Written in Golang.

RaspChecker Remotely monitor your Raspberry Pi's temperature and shut it down if you want. All through Telegram. How to set up In order to run the bot

Jan 2, 2022

Go library for Telegram Bot API

Go library for Telegram Bot API

tbot - Telegram Bot Server Features Full Telegram Bot API 4.7 support Zero dependency Type-safe API client with functional options Capture messages by

Nov 30, 2022

Flexible message router add-on for go-telegram-bot-api library.

Flexible message router add-on for go-telegram-bot-api library.

telemux Flexible message router add-on for go-telegram-bot-api library. Table of contents Motivation Features Minimal example Documentation Changelog

Oct 24, 2022

Our library to interact with a telegram bot.

gotelegrambot Here you can find our library for telegram bot's. We develop the API endpoints according to our demand and need. You are welcome to help

Dec 18, 2021

A Telegram bot hook for Logrus logging library in Go

logrus2telegram logrus2telegram is a Telegram bot hook for Logrus logging librar

Nov 15, 2022
Comments
  • Can the time of a Telegram message be obtained

    Can the time of a Telegram message be obtained

    Dear @KaoriEl,

    I'm using a program for getting message from a Telegram channel using: https://github.com/KaoriEl/go-tdlib/blob/9da5185fbd457e08f25e1a7e3179f1bc62c3e438/examples/getChats/getChats.go

    To avoid receiving multiple messages at the start of running the program, I need to compare if the time of massages is after the lunch of the run or not. In case, can I add a function to GetChats.go sample to do this comparison?

    Thanks in advance Cheers

  • No such file or directory td/telegram/td_json_client.h

    No such file or directory td/telegram/td_json_client.h

    Hallow. Error: go get -u github.com/kaoriEl/go-tdlib " fatal error: td/telegram/td_json_client.h: No such file or directory 10 | //#include <td/telegram/td_json_client.h> | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ compilation terminated. "

A bot based on Telegram Bot API written in Golang allows users to download public Instagram photos, videos, and albums without receiving the user's credentials.

InstagramRobot InstagramRobot is a bot based on Telegram Bot API written in Golang that allows users to download public Instagram photos, videos, and

Dec 16, 2021
Dlercloud-telegram-bot - A Telegram bot for managing your Dler Cloud account

Dler Cloud Telegram Bot A Telegram bot for managing your Dler Cloud account. Usa

Dec 30, 2021
Pro-bot - A telegram bot to play around with the community telegram channels

pro-bot ?? Pro Bot A Telegram Bot to Play Around With The Community Telegram Cha

Jan 24, 2022
Signum Explorer Telegram Bot - it's a simplified version of the web Signum Explorer
Signum Explorer Telegram Bot - it's a simplified version of the web Signum Explorer

Signum Explorer Telegram Bot - it's a simplified version of the web Signum Explorer. Bot allows you to easily monitor the status of your account and to receive notifications about new transactions and blocks.

Nov 9, 2022
This repository will guide you to steal whatever the user copies and send content to telegram bot.

copy-clipboard-stealer-with-telegram This repository will guide you to steal whatever the user copies and send content to telegram bot. Setting Envior

Oct 4, 2022
Bot - Telegram Music Bot in Go

Telegram Music Bot in Go An example bot using gotgcalls. Setup Install the serve

Jun 28, 2022
Golang telegram bot API wrapper, session-based router and middleware

go-tgbot Pure Golang telegram bot API wrapper generated from swagger definition, session-based routing and middlewares. Usage benefits No need to lear

Nov 16, 2022
Golang Based Account Generator Telegram Bot

Account Generator Bot Account Generator Bot, written in GoLang via gotgbot library. Variables Env Vars - BOT_TOKEN - Get it from @BotFather CHANNEL_ID

Nov 21, 2022
Bot-template - A simple bot template for creating a bot which includes a config, postgresql database

bot-template This is a simple bot template for creating a bot which includes a c

Sep 9, 2022
Client lib for Telegram bot api

Micha Client lib for Telegram bot api. Supports Bot API v2.3.1 (of 4th Dec 2016). Simple echo bot example: package main import ( "log" "git

Nov 10, 2022