Merged with upstream
This commit is contained in:
parent
88c77ebe7c
commit
80961b32b1
12
README.md
12
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 tdjson functions: Send(), Execute(), Receive(), Destroy(), SetFilePath(), SetLogVerbosityLevel()
|
||||||
* Supports all tdlib functions and types
|
* Supports all tdlib functions and types
|
||||||
|
|
||||||
## Installtion
|
## Installation
|
||||||
|
|
||||||
First of all you need to clone the Tdlib repo and build it:
|
First of all you need to clone the Tdlib repo and build it:
|
||||||
```bash
|
```bash
|
||||||
git clone git@github.com:tdlib/td.git
|
git clone git@github.com:tdlib/td.git
|
||||||
cd tdlib
|
cd td
|
||||||
mkdir build
|
mkdir build
|
||||||
cd build
|
cd build
|
||||||
cmake -DCMAKE_BUILD_TYPE=Release ..
|
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)
|
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.
|
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
|
## Example
|
||||||
Here is a simple example for authorization and fetching updates:
|
Here is a simple example for authorization and fetching updates:
|
||||||
```golang
|
```golang
|
||||||
|
|
|
@ -66,5 +66,4 @@ func main() {
|
||||||
fmt.Println(update.Data)
|
fmt.Println(update.Data)
|
||||||
fmt.Print("\n\n")
|
fmt.Print("\n\n")
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -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")
|
||||||
|
}
|
||||||
|
}
|
|
@ -64,7 +64,7 @@ func main() {
|
||||||
for newMsg := range receiver.Chan {
|
for newMsg := range receiver.Chan {
|
||||||
fmt.Println(newMsg)
|
fmt.Println(newMsg)
|
||||||
updateMsg := (newMsg).(*tdlib.UpdateNewMessage)
|
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)
|
msgText := updateMsg.Message.Content.(*tdlib.MessageText)
|
||||||
fmt.Println("MsgText: ", msgText.Text)
|
fmt.Println("MsgText: ", msgText.Text)
|
||||||
fmt.Print("\n\n")
|
fmt.Print("\n\n")
|
||||||
|
|
2
tdlib.go
2
tdlib.go
|
@ -1,8 +1,10 @@
|
||||||
package tdlib
|
package tdlib
|
||||||
|
|
||||||
//#cgo linux CFLAGS: -I/usr/local/include
|
//#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 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 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
|
//#cgo windows LDFLAGS: -LC:/src/td/build/Debug -ltdjson
|
||||||
//#include <stdlib.h>
|
//#include <stdlib.h>
|
||||||
//#include <td/telegram/td_json_client.h>
|
//#include <td/telegram/td_json_client.h>
|
||||||
|
|
Loading…
Reference in New Issue