From 80961b32b1def10b950c818536c7201949c5e071 Mon Sep 17 00:00:00 2001 From: Arman Date: Sat, 26 May 2018 15:26:09 +0430 Subject: [PATCH] Merged with upstream --- README.md | 12 ++++- examples/authorization/basicAuthorization.go | 1 - examples/authorization/botAuthorization.go | 53 ++++++++++++++++++++ examples/customEvents/getCustomEvents.go | 2 +- tdlib.go | 2 + 5 files changed, 66 insertions(+), 4 deletions(-) create mode 100644 examples/authorization/botAuthorization.go diff --git a/README.md b/README.md index 5ee92c2..8cb4574 100644 --- a/README.md +++ b/README.md @@ -20,12 +20,12 @@ So you can use every single type and method in Tdlib. * Supports all tdjson functions: Send(), Execute(), Receive(), Destroy(), SetFilePath(), SetLogVerbosityLevel() * Supports all tdlib functions and types -## Installtion +## Installation First of all you need to clone the Tdlib repo and build it: ```bash git clone git@github.com:tdlib/td.git -cd tdlib +cd td mkdir build cd build cmake -DCMAKE_BUILD_TYPE=Release .. @@ -38,6 +38,14 @@ make install If hit any build errors, refer to [Tdlib build instructions](https://github.com/tdlib/td#building) I'm using static linking against tdlib so it won't require to build the whole tdlib source files. +## Docker +You can use prebuilt tdlib with following Docker image: + +***Windows:*** +``` shell +docker pull mihaildemidoff/tdlib-go +``` + ## Example Here is a simple example for authorization and fetching updates: ```golang diff --git a/examples/authorization/basicAuthorization.go b/examples/authorization/basicAuthorization.go index bc9d1cd..04c6d0f 100644 --- a/examples/authorization/basicAuthorization.go +++ b/examples/authorization/basicAuthorization.go @@ -66,5 +66,4 @@ func main() { fmt.Println(update.Data) fmt.Print("\n\n") } - } diff --git a/examples/authorization/botAuthorization.go b/examples/authorization/botAuthorization.go new file mode 100644 index 0000000..2ed5614 --- /dev/null +++ b/examples/authorization/botAuthorization.go @@ -0,0 +1,53 @@ +package main + +import ( + "fmt" + + "github.com/Arman92/go-tdlib" +) + +const botToken = "" + +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 { + _, err := client.CheckAuthenticationBotToken(botToken) + if err != nil { + fmt.Printf("Error check bot token: %v", err) + return + } + } else if currentState.GetAuthorizationStateEnum() == tdlib.AuthorizationStateReadyType { + fmt.Println("Authorization Ready! Let's rock") + break + } + } + + // rawUpdates gets all updates comming from tdlib + rawUpdates := client.GetRawUpdatesChannel(100) + for update := range rawUpdates { + // Show all updates + fmt.Println(update.Data) + fmt.Print("\n\n") + } +} diff --git a/examples/customEvents/getCustomEvents.go b/examples/customEvents/getCustomEvents.go index 503267f..26d2b08 100644 --- a/examples/customEvents/getCustomEvents.go +++ b/examples/customEvents/getCustomEvents.go @@ -64,7 +64,7 @@ func main() { for newMsg := range receiver.Chan { fmt.Println(newMsg) updateMsg := (newMsg).(*tdlib.UpdateNewMessage) - // We assume the message content is simple text: (should be more sophosticated for general use) + // We assume the message content is simple text: (should be more sophisticated for general use) msgText := updateMsg.Message.Content.(*tdlib.MessageText) fmt.Println("MsgText: ", msgText.Text) fmt.Print("\n\n") diff --git a/tdlib.go b/tdlib.go index f69e89d..da202db 100644 --- a/tdlib.go +++ b/tdlib.go @@ -1,8 +1,10 @@ package tdlib //#cgo linux CFLAGS: -I/usr/local/include +//#cgo darwin CFLAGS: -I/usr/local/include //#cgo windows CFLAGS: -IC:/src/td -IC:/src/td/build //#cgo linux LDFLAGS: -L/usr/local/lib -ltdjson_static -ltdjson_private -ltdclient -ltdcore -ltdactor -ltddb -ltdsqlite -ltdnet -ltdutils -lstdc++ -lssl -lcrypto -ldl -lz -lm +//#cgo darwin LDFLAGS: -L/usr/local/lib -L/usr/local/opt/openssl/lib -ltdjson_static -ltdjson_private -ltdclient -ltdcore -ltdactor -ltddb -ltdsqlite -ltdnet -ltdutils -lstdc++ -lssl -lcrypto -ldl -lz -lm //#cgo windows LDFLAGS: -LC:/src/td/build/Debug -ltdjson //#include //#include