-
Notifications
You must be signed in to change notification settings - Fork 42
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add support for logging in using tdesktop session data (TDATA) (#58)
* Added TDATA session support * Added example to authenticate with TDATA
- Loading branch information
cynicalwork
authored
Feb 21, 2024
1 parent
3858369
commit 39fd696
Showing
2 changed files
with
91 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
package main | ||
|
||
import ( | ||
"fmt" | ||
"log" | ||
"os" | ||
"path/filepath" | ||
|
||
"github.com/celestix/gotgproto" | ||
"github.com/celestix/gotgproto/sessionMaker" | ||
"github.com/gotd/td/session/tdesktop" | ||
) | ||
|
||
func main() { | ||
home, err := os.UserHomeDir() | ||
if err != nil { | ||
log.Fatalln(err) | ||
} | ||
telegramDir := filepath.Join(home, ".local/share/TelegramDesktop") | ||
accounts, err := tdesktop.Read(telegramDir, nil) | ||
if err != nil { | ||
log.Fatalln(err) | ||
} | ||
|
||
// Type of client to login to, can be of 2 types: | ||
// 1.) Bot (Fill BotToken in this case) | ||
// 2.) User (Fill Phone in this case) | ||
clientType := gotgproto.ClientType{ | ||
Phone: "PHONE_NUMBER_HERE", | ||
} | ||
|
||
client, err := gotgproto.NewClient( | ||
// Get AppID from https://my.telegram.org/apps | ||
123456, | ||
// Get ApiHash from https://my.telegram.org/apps | ||
"API_HASH_HERE", | ||
// ClientType, as we defined above | ||
clientType, | ||
// Optional parameters of client | ||
&gotgproto.ClientOpts{ | ||
// There can be up to 3 tdesktop.Account, we consider here there is | ||
// at least a single on, you can loop through them with | ||
// for _, account := range accounts {// your code} | ||
Session: sessionMaker.TdataSession(accounts[0]).Name("tdata"), | ||
}, | ||
) | ||
if err != nil { | ||
log.Fatalln("failed to start client:", err) | ||
} | ||
|
||
fmt.Printf("client (@%s) has been started...\n", client.Self.Username) | ||
|
||
client.Idle() | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters