A message's attachments persist as metadata (messaging.Message.Media) and
cross the gateway wire, but the dashboard transcript rendered text only, so
a photo was invisible to the operator while the model had seen it.
The transcript view now carries the persisted metadata, and the browser
labels each attachment in the placeholder vocabulary the channels already
write into a message's text ('[photo]', '[document: report.pdf]'), with the
surviving metadata (mime, name, size, dimensions, duration) in the chip's
tooltip.
Bytes are never rendered: they are turn-scoped and stripped before a record
is stored, so there is nothing to fetch and no broken image or 404 link. The
platform file id is deliberately not served either -- it is a download
handle, not an address -- so the chip links out only when the attachment
itself carried a URL. A message with no attachments omits the media key, so
transcripts written before this change keep the payload they had.
51 lines
1.8 KiB
TypeScript
51 lines
1.8 KiB
TypeScript
import type { ChatMedia } from "./state";
|
||
|
||
/**
|
||
* How a transcript renders an attachment whose bytes it does not have.
|
||
*
|
||
* The bytes are turn-scoped and never reach a browser, so the label stands in
|
||
* for the file. It reuses the placeholder vocabulary the channels already
|
||
* write into a message's text (`[photo]`, `[document: report.pdf]` — see the
|
||
* notes in `internal/channels/telegram/inboundmedia.go`), so the same
|
||
* attachment reads the same whether its metadata survived persistence or only
|
||
* the note in its text did.
|
||
*/
|
||
export function mediaLabel(attachment: ChatMedia): string {
|
||
switch (attachment.type) {
|
||
case "image":
|
||
return "[photo]";
|
||
case "video":
|
||
return "[video]";
|
||
case "audio":
|
||
return "[audio]";
|
||
case "document":
|
||
return attachment.file_name
|
||
? `[document: ${attachment.file_name}]`
|
||
: "[document]";
|
||
default:
|
||
return `[${attachment.type || "attachment"}]`;
|
||
}
|
||
}
|
||
|
||
/**
|
||
* The metadata behind the label, for the chip's tooltip: mime type, file name,
|
||
* size, dimensions and duration, in the order a reader asks about them.
|
||
*
|
||
* It reports only what the record actually carried, so an unknown size reads
|
||
* as absent rather than as zero, and it never names the platform file id — a
|
||
* handle is not information about the file.
|
||
*/
|
||
export function mediaDetail(attachment: ChatMedia): string {
|
||
const parts: string[] = [];
|
||
if (attachment.mime_type) parts.push(attachment.mime_type);
|
||
if (attachment.file_name) parts.push(attachment.file_name);
|
||
if (attachment.file_size !== undefined) {
|
||
parts.push(`${attachment.file_size} bytes`);
|
||
}
|
||
if (attachment.width && attachment.height) {
|
||
parts.push(`${attachment.width}×${attachment.height}`);
|
||
}
|
||
if (attachment.duration !== undefined) parts.push(`${attachment.duration} s`);
|
||
return parts.join(" · ");
|
||
}
|