Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 22 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,23 @@

### Changed

- Require Go 1.26 or newer for the Bubble Tea v2 terminal interface.
- Open the interactive workspace when `ta` runs without arguments in a terminal;
piped invocations and `ta --help` continue to display command help.
- **Breaking:** replace the Python application with the Go `ta` CLI. Build with
Go 1.25.8 or newer and log in again when moving from a Python/Telethon session.
Go 1.26 or newer and log in again when moving from a Python/Telethon session.
- Use command flags and optional exported `TA_*` settings for configuration.

### Added

- `ta tui`: a responsive Bubble Tea workspace covering public commands and their
options, including installed extensions. Includes quick-start presets,
command and option search, common/advanced forms, inline validation, command
previews, path completion and keyboard help. Tasks stay in the TUI with
retained results, live progress, input prompts and cancellation. Native account,
chat and schedule browsers provide searchable lists, details and action
buttons; offline statistics show summary cards. Mouse and keyboard navigation
preserve list selection when opening follow-up workflows.
- Install ta with `go install github.com/mo1ein/TelegramArchive/cmd/ta@latest`
or `make install` from a local checkout.
- Incremental JSON and offline HTML chat exports with local media, checkpoints,
Expand All @@ -25,6 +36,16 @@

### Fixed

- Stream chat-browser pages into the TUI before loading finishes, with visible
connection stages, bounded requests, proxy fallback support and partial
results retained when loading is stopped. Avoid fetching every forum's topics
before showing chats.
- Import native Telegram for macOS sessions, including the website-installed
client, with read-only SQLCipher/Postbox readers, local passcode support and
committed WAL snapshots. Preserve the native API profile and the Desktop
default. `ta login --check` verifies data without saving a login or connecting.
- Recognize sandboxed Telegram Desktop data on macOS and report access errors
with macOS permission guidance.
- Convert poll answer variants from gotd v0.145.1 so the CLI builds with the
updated Telegram dependency.
- Continue backups after repeated Telegram timeouts for an optional thumbnail,
Expand Down
2 changes: 1 addition & 1 deletion CONTRIBUTING.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Contributing

ta is a Go CLI. Building requires Go 1.25.8 or newer.
ta is a Go CLI with a Bubble Tea v2 workspace. Building requires Go 1.26 or newer.

Create a short-lived branch from `main` and keep each commit focused on one
change. Describe the problem, resulting behavior and verification in your pull
Expand Down
19 changes: 17 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,15 @@ Inspired by [tdl](https://github.com/iyear/tdl), ta uses its transfer and sessio
- Incremental sync, refresh and cron schedules.
- Multiple saved Telegram accounts with separate cron backups.
- Offline rendering, statistics, uploads and forwarding.
- Interactive Bubble Tea workspace with chat/account browsers, action buttons and live task results.

## Installation

With Go 1.25.8 or newer installed, run:
With Go 1.26 or newer installed, run:

```sh
go install github.com/mo1ein/TelegramArchive/cmd/ta@latest
ta --help
ta
```

Run the same `go install` command to update ta. Go installs the binary into
Expand All @@ -46,11 +47,23 @@ To install a local checkout, including unpublished changes, run

## Quick start

Run `ta` or `ta tui` in a terminal to open the interactive workspace. Choose a
quick-start workflow or search every command with `/`. Edit options, press
`Ctrl+R` to review, then `Enter` to run. Login prompts and transfer progress
stay inside the workspace. Browse chats, switch accounts and manage schedules
from selectable lists with action buttons. [Workspace guide and shortcuts](docs/tui.md).

The commands below also work directly:

```sh
ta login -T qr # use -T code for phone/code login
ta archive --all --types channels --media all --format both
```

On macOS, you can also import the login from your existing native Telegram app,
including the website download. See [macOS login setup](docs/macos.md) for Full
Disk Access, local passcodes, verification and import commands.

This exports every joined channel, including private channels and archived dialogs.
Files go to `./data`. Open `data/export_results.html` to browse them.
Resume is on by default. Rerun the same command to continue or fetch new messages.
Expand Down Expand Up @@ -101,9 +114,11 @@ Click a preview to enlarge it.

| Guide | Covers |
| --- | --- |
| [Interactive workspace](docs/tui.md) | Search, guided forms, presets, advanced options, review and keyboard shortcuts |
| [Archiving](docs/archiving.md) | Chat selection, media/date/size filters, custom names, resume, refresh, progress, JSON/HTML, offline rendering and statistics |
| [Backups](docs/backups.md) | Account sections, Saved Messages, one-time sync, recurring sync, cron jobs and logs |
| [Accounts and settings](docs/configuration.md) | Login, multiple terminals, proxies, storage, environment settings, transfer commands and build checks |
| [macOS login setup](docs/macos.md) | Native website client, data paths, Full Disk Access, passcodes, import and troubleshooting |
| [Transfers and tools](docs/README.md#transfers-and-tools) | Downloads, uploads, forwarding, chat tools, templates, session tools, extensions and shell completion |
| [Desktop export coverage](docs/desktop-compatibility.md) | Supported formats, fields and API limits |
| [Contributing](CONTRIBUTING.md) | Development workflow and privacy checks |
Expand Down
1 change: 1 addition & 0 deletions cmd/branding.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import (
)

func configureProductPaths() {
configureNativeApp()
upstreamconsts.DataDir = consts.DataDir
upstreamconsts.LogPath = consts.LogPath
upstreamconsts.ExtensionsPath = filepath.Join(consts.DataDir, "extensions")
Expand Down
10 changes: 10 additions & 0 deletions cmd/cron.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package cmd

import (
"context"
"encoding/json"
"fmt"
"io"
"os"
Expand Down Expand Up @@ -78,11 +79,19 @@ func newCron(manager managedcron.Manager, execute managedcron.Runner) *cobra.Com
add.Flags().MarkHidden("runs")
add.Flags().MarkHidden("stop-on-error")

var listJSON bool
list := &cobra.Command{Use: "list", Short: "List ta's cron backups", Args: cobra.NoArgs, Annotations: map[string]string{"offline": "true"}, RunE: func(cmd *cobra.Command, _ []string) error {
jobs, err := manager.List(cmd.Context())
if err != nil {
return err
}
if listJSON {
rows := make([]map[string]any, 0, len(jobs))
for _, job := range jobs {
rows = append(rows, map[string]any{"name": job.Name, "schedule": job.Schedule, "installed": job.Installed, "log": job.Log})
}
return json.NewEncoder(cmd.OutOrStdout()).Encode(rows)
}
if len(jobs) == 0 {
fmt.Fprintln(cmd.OutOrStdout(), "No ta cron jobs. Add one with: ta cron add NAME --chat channel_username --every 6h")
return nil
Expand All @@ -102,6 +111,7 @@ func newCron(manager managedcron.Manager, execute managedcron.Runner) *cobra.Com
}
return out.Flush()
}}
list.Flags().BoolVar(&listJSON, "json", false, "output scheduled backups as JSON")
remove := &cobra.Command{Use: "remove NAME", Aliases: []string{"rm"}, Short: "Remove a cron backup; keep its archives and logs", Args: cobra.ExactArgs(1), Annotations: map[string]string{"offline": "true"}, RunE: func(cmd *cobra.Command, args []string) error {
if err := manager.Remove(cmd.Context(), args[0]); err != nil {
return err
Expand Down
27 changes: 27 additions & 0 deletions cmd/cron_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package cmd
import (
"bytes"
"context"
"encoding/json"
"errors"
"io"
"path/filepath"
Expand Down Expand Up @@ -200,3 +201,29 @@ func TestCronInitialFailureKeepsInstalledSchedule(t *testing.T) {
t.Fatal("initial failure removed retries", jobs, err)
}
}

func TestCronJSONListDoesNotExposeExecutionCredentials(t *testing.T) {
viper.Reset()
defer viper.Reset()
dir := t.TempDir()
table := &testCronTable{}
manager := managedcron.Manager{Directory: filepath.Join(dir, "jobs"), Table: table}
job := managedcron.Job{Name: "synthetic", Schedule: "0 */6 * * *", Executable: "/usr/bin/true", Directory: dir, Arguments: []string{"sync", "--proxy=socks5://private-password@invalid"}, Environment: map[string]string{"TA_PROXY": "private-password"}, Log: filepath.Join(dir, "synthetic.log")}
if err := manager.Install(context.Background(), job); err != nil {
t.Fatal(err)
}
root := cronRoot(manager, nil)
root.SetArgs([]string{"cron", "list", "--json"})
var output bytes.Buffer
root.SetOut(&output)
if err := root.ExecuteContext(context.Background()); err != nil {
t.Fatal(err)
}
var rows []map[string]any
if err := json.Unmarshal(output.Bytes(), &rows); err != nil {
t.Fatal(err)
}
if len(rows) != 1 || rows[0]["name"] != "synthetic" || strings.Contains(output.String(), "private-password") || rows[0]["environment"] != nil || rows[0]["arguments"] != nil {
t.Fatal("unsafe schedule summary")
}
}
110 changes: 110 additions & 0 deletions cmd/desktop_login.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,110 @@
package cmd

import (
"fmt"
"os"
"path/filepath"
"runtime"

"github.com/mo1ein/TelegramArchive/consts"
"github.com/spf13/cobra"
)

// Resolve macOS data locations before calling the transfer core's importer.
// The core only searches the unsandboxed Desktop location on macOS.
func prepareDesktopLogin(cmd *cobra.Command) (bool, error) {
if runtime.GOOS != "darwin" {
return false, nil
}
mode := cmd.Flags().Lookup("type")
if mode == nil || mode.Value.String() != "desktop" {
return false, nil
}
// The deprecated --code flag still bypasses Desktop import upstream.
if legacy := cmd.Flags().Lookup("code"); legacy != nil && legacy.Value.String() == "true" {
return false, nil
}
desktop := cmd.Flags().Lookup("desktop")
if desktop == nil {
return false, nil
}
source, err := findMacLoginSource(consts.HomeDir, desktop.Value.String())
if err != nil {
return false, err
}
// This updates the actual options bound to the inherited login handler.
// Leave Changed intact: automatic discovery is not a user-supplied flag.
return source.native, desktop.Value.Set(source.path)
}

type desktopSource struct {
path string
native bool
}

// Only inspect directory metadata here, never session keys or message data.
func findMacDesktopData(home, explicit string) (string, error) {
source, err := findMacLoginSource(home, explicit)
return source.path, err
}

func findMacLoginSource(home, explicit string) (desktopSource, error) {
candidates := []string{
filepath.Join(home, "Library", "Application Support", "Telegram Desktop"),
filepath.Join(home, "Library", "Containers", "org.telegram.desktop", "Data", "Library", "Application Support", "Telegram Desktop"),
}
if explicit != "" {
candidates = []string{explicit}
}
var inaccessible error
for _, candidate := range candidates {
path := candidate
if filepath.Base(path) != "tdata" {
path = filepath.Join(path, "tdata")
}
info, err := os.Stat(path)
if err == nil && info.IsDir() {
return desktopSource{path: path}, nil
}
if err != nil && !os.IsNotExist(err) && inaccessible == nil {
inaccessible = fmt.Errorf("cannot access Telegram Desktop data at %q: %w", path, err)
}
}
if inaccessible != nil {
return desktopSource{}, inaccessible
}
native := []string{
filepath.Join(home, "Library", "Group Containers", "6N38VWS5BX.ru.keepcoder.Telegram"),
filepath.Join(home, "Library", "Containers", "ru.keepcoder.Telegram"),
}
if explicit != "" {
root := explicit
if filepath.Base(root) == "atomic-state" {
root = filepath.Dir(filepath.Dir(root))
} else if filepath.Base(root) == "accounts-metadata" {
root = filepath.Dir(root)
}
native = []string{root}
}
for _, root := range native {
for _, channel := range []string{"", "stable", "appstore", "beta"} {
path := filepath.Join(root, channel)
info, err := os.Stat(filepath.Join(path, "accounts-metadata", "atomic-state"))
if err == nil && info.Mode().IsRegular() {
return desktopSource{path: path, native: true}, nil
}
if err != nil && !os.IsNotExist(err) {
return desktopSource{}, fmt.Errorf("cannot read native Telegram metadata; give the app running ta Full Disk Access in macOS Privacy & Security, reopen it and retry: %w", err)
}
}
}
if explicit != "" {
return desktopSource{}, fmt.Errorf("no Telegram session data found at %q; -d must point to tdata, its parent data directory, or the native client's stable/appstore data directory, not the application bundle", explicit)
}
for _, path := range native {
if _, err := os.Stat(path); err == nil {
return desktopSource{}, fmt.Errorf("native Telegram for macOS was found but has no signed-in account metadata; open Telegram and sign in, then retry ta login")
}
}
return desktopSource{}, fmt.Errorf("no Telegram session data found in the standard or sandboxed macOS data locations; open Telegram and sign in, or specify its data directory with -d (not the application bundle)")
}
Loading
Loading