Files
archie/internal/domain/messaging/transcribe_test.go
T
sam 2c5dfe51a7 feat(messaging): transcribe Telegram voice notes
A Telegram voice note was stored as the placeholder "[voice message]" and
nothing turned its audio into text, so the agent could not read it. Add a
channel-neutral Transcriber capability to the messaging media layer
(internal/domain/messaging), an ai-sdk Whisper implementation behind it
(internal/infrastructure/transcription), and wire it for Telegram.

The capability is config-driven like the other model roles:
models.transcription names a provider/model, the matching [providers.*]
entry carries the credential (api_key_env or an api_key secret ref), and
a missing role, provider, class or credential degrades to today's
behaviour with a log -- never an error that fails the turn.

A transcribed note replaces its placeholder with "[voice transcription]"
followed by the transcript, preserving any caption, so stored history
shows the agent it is reading a machine transcript.
2026-10-02 09:36:48 +10:00

51 lines
1.5 KiB
Go

package messaging
import "testing"
// TestTranscribedTextMarksProvenanceAndKeepsCaption pins the stored shape of
// a transcribed voice note: history is text-only and the original bytes are
// gone, so the marker is the only thing that tells a later reader the words
// came from a machine transcript, and the sender's caption must survive it.
func TestTranscribedTextMarksProvenanceAndKeepsCaption(t *testing.T) {
cases := []struct {
name string
transcript string
caption string
want string
}{
{
name: "transcript alone carries the marker",
transcript: "hello there",
want: "[voice transcription]\nhello there",
},
{
name: "surrounding whitespace is trimmed",
transcript: " spaced ",
want: "[voice transcription]\nspaced",
},
{
name: "caption follows the transcript",
transcript: "what time is it",
caption: "ignore the background noise",
want: "[voice transcription]\nwhat time is it\nignore the background noise",
},
{
name: "caption without a transcript keeps its own line",
caption: "sent by mistake",
want: "[voice transcription]\nsent by mistake",
},
{
name: "empty transcript still marks provenance",
transcript: " ",
want: "[voice transcription]",
},
}
for _, tc := range cases {
t.Run(tc.name, func(t *testing.T) {
if got := TranscribedText(tc.transcript, tc.caption); got != tc.want {
t.Errorf("TranscribedText(%q, %q) = %q, want %q", tc.transcript, tc.caption, got, tc.want)
}
})
}
}