2024-06-25 14:37:26 +00:00
|
|
|
package telegram
|
|
|
|
|
|
|
|
import (
|
2024-06-30 18:02:23 +00:00
|
|
|
"context"
|
2024-06-25 14:37:26 +00:00
|
|
|
"fmt"
|
2024-06-30 18:02:23 +00:00
|
|
|
"penahub.gitlab.yandexcloud.net/backend/quiz/common.git/dal"
|
|
|
|
"penahub.gitlab.yandexcloud.net/backend/tdlib/client"
|
2024-06-25 14:37:26 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
type TelegramClient struct {
|
2024-06-30 18:02:23 +00:00
|
|
|
repo *dal.DAL
|
|
|
|
TgClients []*client.Client
|
|
|
|
WaitingClients map[string]WaitingClient
|
|
|
|
}
|
2024-06-25 14:37:26 +00:00
|
|
|
|
2024-06-30 18:02:23 +00:00
|
|
|
type WaitingClient struct {
|
|
|
|
TdLibClient *client.Client
|
|
|
|
PreviousReq AuthTgUserReq
|
|
|
|
Authorizer *client.ClientAuthorizer
|
|
|
|
}
|
2024-06-27 09:24:23 +00:00
|
|
|
|
2024-06-30 18:02:23 +00:00
|
|
|
// todo come back saved tg accs to slice for check this status
|
|
|
|
func NewTelegramClient(ctx context.Context, repo *dal.DAL) (*TelegramClient, error) {
|
|
|
|
return &TelegramClient{
|
|
|
|
repo: repo,
|
|
|
|
TgClients: make([]*client.Client, 0),
|
|
|
|
WaitingClients: make(map[string]WaitingClient),
|
|
|
|
}, nil
|
|
|
|
}
|
2024-06-25 14:37:26 +00:00
|
|
|
|
2024-06-30 18:02:23 +00:00
|
|
|
type AuthTgUserReq struct {
|
|
|
|
ApiID int32 `json:"api_id"`
|
|
|
|
ApiHash string `json:"api_hash"`
|
|
|
|
PhoneNumber string `json:"phone_number"`
|
|
|
|
Password string `json:"password"`
|
|
|
|
}
|
|
|
|
|
|
|
|
func (tg *TelegramClient) AddedToMap(data WaitingClient, id string) {
|
|
|
|
fmt.Println("AddedToMap")
|
|
|
|
tg.WaitingClients[id] = data
|
|
|
|
}
|
|
|
|
|
|
|
|
func (tg *TelegramClient) GetFromMap(id string) (WaitingClient, bool) {
|
|
|
|
fmt.Println("GetFromMap")
|
|
|
|
if data, ok := tg.WaitingClients[id]; ok {
|
|
|
|
return data, true
|
2024-06-25 14:37:26 +00:00
|
|
|
}
|
2024-06-30 18:02:23 +00:00
|
|
|
return WaitingClient{}, false
|
|
|
|
}
|
|
|
|
|
|
|
|
func (tg *TelegramClient) SaveTgAccount() {
|
2024-06-25 14:37:26 +00:00
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
func (tg *TelegramClient) CreateChannel(channelName string, botID int64) (string, error) {
|
|
|
|
return "", nil
|
|
|
|
}
|