2024-06-25 14:37:26 +00:00
|
|
|
package telegram
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
"github.com/zelenin/go-tdlib/client"
|
2024-06-27 09:24:23 +00:00
|
|
|
"path/filepath"
|
2024-06-25 14:37:26 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
type TelegramClient struct {
|
|
|
|
Client *client.Client
|
|
|
|
}
|
|
|
|
|
|
|
|
func NewTelegramClient(apiID int32, apiHash string) (*TelegramClient, error) {
|
|
|
|
authorizer := client.ClientAuthorizer()
|
|
|
|
go client.CliInteractor(authorizer)
|
|
|
|
|
|
|
|
authorizer.TdlibParameters <- &client.SetTdlibParametersRequest{
|
2024-06-27 09:24:23 +00:00
|
|
|
UseTestDc: false,
|
|
|
|
DatabaseDirectory: filepath.Join(".tdlib", "database"),
|
|
|
|
FilesDirectory: filepath.Join(".tdlib", "files"),
|
2024-06-25 14:37:26 +00:00
|
|
|
UseFileDatabase: false,
|
|
|
|
UseChatInfoDatabase: false,
|
|
|
|
UseMessageDatabase: false,
|
2024-06-27 09:24:23 +00:00
|
|
|
UseSecretChats: false,
|
2024-06-25 14:37:26 +00:00
|
|
|
ApiId: apiID,
|
|
|
|
ApiHash: apiHash,
|
|
|
|
SystemLanguageCode: "en",
|
|
|
|
DeviceModel: "Server",
|
|
|
|
SystemVersion: "1.0.0",
|
|
|
|
ApplicationVersion: "1.0.0",
|
|
|
|
}
|
|
|
|
|
2024-06-27 09:24:23 +00:00
|
|
|
_, err := client.SetLogVerbosityLevel(&client.SetLogVerbosityLevelRequest{
|
|
|
|
NewVerbosityLevel: 1,
|
|
|
|
})
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
2024-06-25 14:37:26 +00:00
|
|
|
tdlibClient, err := client.NewClient(authorizer)
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
|
|
|
me, err := tdlibClient.GetMe()
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
fmt.Printf("Me: %s %s [%v]", me.FirstName, me.LastName, me.Usernames)
|
|
|
|
|
|
|
|
return &TelegramClient{
|
|
|
|
Client: tdlibClient,
|
|
|
|
}, nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func (tg *TelegramClient) CreateChannel(channelName string, botID int64) (string, error) {
|
|
|
|
return "", nil
|
|
|
|
}
|