]> git.giacomolli.uk - onechat/blob - whatsapp_voice.go
Separate commands from the entry point
[onechat] / whatsapp_voice.go
1 package main
2
3 import (
4 "context"
5 "time"
6
7 "go.mau.fi/whatsmeow/proto/waE2E"
8 )
9
10 // whatsappVoiceDownloadTimeout bounds one voice-note media download.
11 const whatsappVoiceDownloadTimeout = 2 * time.Minute
12
13 // whatsappVoice stores and transcribes accepted voice notes before their batch
14 // is acknowledged. Failure markers reveal no URLs, keys, or process output.
15 func whatsappVoice(ctx context.Context, client WhatsAppClient, store *VoiceStore, transcriber *VoiceTranscriber, audio *waE2E.AudioMessage) string {
16 if audio.GetFileLength() > voiceMaxBytes || client == nil {
17 return "(voice not downloaded)"
18 }
19
20 downloadCtx, cancel := context.WithTimeout(ctx, whatsappVoiceDownloadTimeout)
21 defer cancel()
22
23 data, err := client.Download(downloadCtx, audio)
24 if err != nil {
25 return "(voice not downloaded)"
26 }
27
28 return transcriber.Text(ctx, store, data)
29 }