Merged with upstream

This commit is contained in:
Arman 2018-05-26 15:26:09 +04:30
parent 88c77ebe7c
commit 80961b32b1
5 changed files with 66 additions and 4 deletions

View File

@ -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

View File

@ -66,5 +66,4 @@ func main() {
fmt.Println(update.Data)
fmt.Print("\n\n")
}
}

View File

@ -0,0 +1,53 @@
package main
import (
"fmt"
"github.com/Arman92/go-tdlib"
)
const botToken = "<your bot token>"
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")
}
}

View File

@ -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")

View File

@ -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 <stdlib.h>
//#include <td/telegram/td_json_client.h>