package main import ( "context" "fmt" "path/filepath" ) // ImageShow shows a stored image to the root's user. A configured bot sends it // to its owner, and the tool result gives terminal clients its name and path. type ImageShow struct { store *ImageStore bot *TelegramBot } // Show checks the stored name and bytes before any output. A refused Telegram // photo goes as a document. An uncertain send is not repeated. func (s *ImageShow) Show(ctx context.Context, name, caption string) (string, error) { data, err := s.store.Read(name) if err != nil { return "", fmt.Errorf("read image to show: %w", err) } path, err := filepath.Abs(filepath.Join(s.store.dir, name)) if err != nil { return "", fmt.Errorf("find image path: %w", err) } if s.bot != nil { err = s.bot.api.SendImage(ctx, s.bot.owner, name, data, caption) if err != nil { return "", fmt.Errorf("show Telegram image: %w", err) } } return imageText([]string{name}, caption) + "\n" + path, nil }