v0.3.12 999d53a

config.go RawHistoryFolder

1// Package telegram implements zot's Telegram bot bridge.
2//
3// It runs in-process, polling Telegram for DMs and forwarding them to
4// a core.Agent. Responses stream back as Telegram messages. Images
5// sent by the user are downloaded and attached to the next prompt as
6// provider.ImageBlock, so vision-capable models see them the same way
7// they would via drag-and-drop in the TUI.
8//
9// State (bot token, allowed user id) lives in $ZOT_HOME/bot.json.
10package telegram
11
12import (
13	"encoding/json"
14	"errors"
15	"os"
16	"path/filepath"
17)
18
19// Config is the on-disk state for the telegram bridge.
20type Config struct {
21	BotToken      string `json:"bot_token,omitempty"`
22	BotUsername   string `json:"bot_username,omitempty"`
23	BotID         int64  `json:"bot_id,omitempty"`
24	AllowedUserID int64  `json:"allowed_user_id,omitempty"`
25	LastUpdateID  int64  `json:"last_update_id,omitempty"`
26}
27
28// ConfigPath returns the path to bot.json.
29func ConfigPath(zotHome string) string {
30	return filepath.Join(zotHome, "bot.json")
31}
32
33// LoadConfig reads bot.json, returning a zero Config if it doesn't exist.
34func LoadConfig(zotHome string) (Config, error) {
35	var c Config
36	b, err := os.ReadFile(ConfigPath(zotHome))
37	if errors.Is(err, os.ErrNotExist) {
38		return c, nil
39	}
40	if err != nil {
41		return c, err
42	}
43	if err := json.Unmarshal(b, &c); err != nil {
44		return c, err
45	}
46	return c, nil
47}
48
49// SaveConfig writes bot.json atomically.
50func SaveConfig(zotHome string, c Config) error {
51	if err := os.MkdirAll(zotHome, 0o755); err != nil {
52		return err
53	}
54	b, err := json.MarshalIndent(c, "", "  ")
55	if err != nil {
56		return err
57	}
58	path := ConfigPath(zotHome)
59	tmp := path + ".tmp"
60	if err := os.WriteFile(tmp, b, 0o600); err != nil {
61		return err
62	}
63	return os.Rename(tmp, path)
64}

Keyboard shortcuts

Single-key shortcuts are on. ctrl k and esc work whatever this says.

ctrl k :
go to a section, branch, tag, file or repository
?
this list
j k
move the row cursor down / up
enter
open the row under the cursor; on Files, a directory opens or closes in place
↑ ↓ ← → home end
in the file tree (focus on a row): previous / next row, close / open a directory or go to its parent / first entry, first / last row. They never open a file
l h
on Files: open a directory or a file / close a directory or go up to its parent, then to the parent page. Elsewhere: into the side panel (on a merge request, its files) / back to the content; there j k move between its controls
g g G
first / last row
/
filter the list; on Files, find a file anywhere in the repository (esc clears, enter opens the best match)
b
switch branch or tag
g s g f g c g b g m g i g r g a
tabs: summary, files, commits, branches & tags, merge requests, issues, releases, actions (when available)
g h
home
w
wide mode: use the whole width of the screen, or not (remembered)
y
copy a permalink pinned to the commit
d u x
diff: split / unified / collapse or expand all
e E
diff: the whole file in view / every file, with the lines the hunks hide
n
merge request: next note in the diff
esc
close a dialog, leave a field

Branches 1

Tags 477

↑↓ moveenter openesc close