Attach images to posts and return the Telegram message id

The adapter response now carries telegram_message_id and a t.me/c link.
compose visual resolves a post's image: own visual_url, else the entry's
rendered portrait, else hold an entry with only a visual prompt, else the
HelixForge main image. send-post.sh resolves before touching credentials,
requires an image on public posts and runs the adapter with ATTACH_VISUAL.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

Assistant: claude-code
Assistant-Model: opus
Assistant-Process: 5457@bnt-lap001
Assistant-Session: 792bf84a-3783-4f5d-a811-cded61dd2012
This commit is contained in:
tegwick 2026-10-08 10:20:09 +02:00
parent b61261d042
commit 4861dd994b
7 changed files with 342 additions and 12 deletions

View file

@ -7,10 +7,12 @@ package main
import (
"context"
"encoding/json"
"errors"
"flag"
"fmt"
"os"
"path/filepath"
"github.com/tegwick/fluid-telegram/internal/compose"
)
@ -20,6 +22,10 @@ const usage = `compose — temporary quoted-remembrance drafts
compose draft --entry <file> --queue <dir> (--source-url <url> | --base-url <url>)
compose approve --queue <dir> --post <id> --reviewer <name> --consent explicit|standing|not-required
compose publish --queue <dir> --post <id> --adapter <base>
compose visual [--entry <file>] --hall-dir <dir> --hall-raw-base <url> --fallback <url>
visual prints the image a post should carry as JSON: the entry's rendered
portrait, else "needs-render" with its prompt, else (no prompt) the fallback.
Consent is never defaulted. A draft is not published until approve has
recorded a reviewer and a consent basis the caller supplied.
@ -43,6 +49,8 @@ func run(args []string) error {
return cmdApprove(args[1:])
case "publish":
return cmdPublish(args[1:])
case "visual":
return cmdVisual(args[1:])
case "-h", "--help", "help":
fmt.Fprint(os.Stderr, usage)
return nil
@ -133,3 +141,38 @@ func cmdPublish(args []string) error {
fmt.Printf("published %s %d\n", d.PostID, d.Publication.StatusCode)
return nil
}
func cmdVisual(args []string) error {
fs := flag.NewFlagSet("visual", flag.ContinueOnError)
fs.SetOutput(os.Stderr)
entry := fs.String("entry", "", "hall entry markdown; omit for a post with no source entry")
hallDir := fs.String("hall-dir", "", "hall-of-helix checkout, to confirm a portrait file exists")
rawBase := fs.String("hall-raw-base", "", "public raw URL of the hall repository root")
fallback := fs.String("fallback", "", "public URL of the campaign's main image")
if err := fs.Parse(args); err != nil {
return err
}
var markdown string
if *entry != "" {
raw, err := os.ReadFile(*entry)
if err != nil {
return err
}
markdown = string(raw)
}
v, err := compose.ResolveVisual(markdown, *rawBase, *fallback)
if err != nil {
return err
}
if v.Kind == compose.VisualPortrait {
if *hallDir == "" {
return errors.New("visual: --hall-dir is required to confirm the portrait exists")
}
if _, err := os.Stat(filepath.Join(*hallDir, v.Path)); err != nil {
return fmt.Errorf("visual: entry links %s, which is not in the hall checkout", v.Path)
}
}
enc := json.NewEncoder(os.Stdout)
enc.SetIndent("", " ")
return enc.Encode(v)
}