-
Notifications
You must be signed in to change notification settings - Fork 38
Expand file tree
/
Copy pathauth.go
More file actions
65 lines (56 loc) · 1.47 KB
/
auth.go
File metadata and controls
65 lines (56 loc) · 1.47 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
package main
import (
"context"
"encoding/json"
"strconv"
"github.com/chaindead/telegram-mcp/internal/tg"
"github.com/rs/zerolog/log"
"github.com/urfave/cli/v3"
)
func authCommand(_ context.Context, cmd *cli.Command) error {
phone := cmd.String("phone")
newSession := cmd.Bool("new")
pass := cmd.String("password")
appID := cmd.Root().Int("app-id")
apiHash := cmd.Root().String("api-hash")
sessionPath := cmd.Root().String("session")
log.Info().
Str("phone", phone).
Str("api-hash", apiHash).
Str("session", sessionPath).
Int64("app-id", appID).
Msg("Authenticate with Telegram")
err := tg.Auth(phone, appID, apiHash, sessionPath, pass, newSession)
if err != nil {
log.Fatal().Err(err).Msg("Failed to authenticate with Telegram")
}
c := struct {
Telegram struct {
Command string `json:"command"`
Env struct {
AppID string `json:"TG_APP_ID"`
APIHash string `json:"TG_API_HASH"`
} `json:"env"`
} `json:"telegram"`
}{
Telegram: struct {
Command string `json:"command"`
Env struct {
AppID string `json:"TG_APP_ID"`
APIHash string `json:"TG_API_HASH"`
} `json:"env"`
}{
Command: "telegram-mcp",
Env: struct {
AppID string `json:"TG_APP_ID"`
APIHash string `json:"TG_API_HASH"`
}{
AppID: strconv.FormatInt(appID, 10),
APIHash: apiHash,
},
},
}
data, _ := json.MarshalIndent(c, "", "\t")
log.Info().RawJSON("config", data).Msg("Successfully authenticated with Telegram")
return nil
}