Repository navigation
feat(whatsapp): add voice note transcription and video understanding - #719
tristanmanchester wants to merge 14 commits into
Conversation
5d0a048 to
b8541b2
Compare
a92879e to
9a0d9eb
Compare
|
@codex if you can see this pls review lol |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 3a9dff9e6d
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| if (result?.text) { | ||
| // Replace video placeholder with description | ||
| body = result.text; | ||
| if (shouldLogVerbose()) { |
There was a problem hiding this comment.
Preserve media captions when adding video descriptions
This overwrites body with the generated description even when body already contains a user caption (e.g., a WhatsApp video with a caption text). In that case the original user text is dropped, so downstream reply logic only sees the auto-generated description and ignores the user’s actual message. Consider only replacing when body is the media placeholder (e.g., <media:video>) or appending the description alongside the existing caption.
Useful? React with 👍 / 👎.
| function resolveApiKey(cfg: ClawdbotConfig, provider: string): string | null { | ||
| // Check skills.entries.<provider>.apiKey | ||
| const skillEntry = cfg.skills?.entries?.[provider]; | ||
| if (skillEntry && typeof skillEntry === "object" && "apiKey" in skillEntry) { | ||
| const key = skillEntry.apiKey; | ||
| if (typeof key === "string" && key.length > 0) return key; | ||
| } | ||
| return null; |
There was a problem hiding this comment.
Accept GROQ_API_KEY for voice note transcription
resolveApiKey only checks skills.entries.<provider>.apiKey, so voice note transcription silently disables itself when users rely on the standard GROQ_API_KEY environment variable (which the config loader already supports). This makes the feature fail for existing Groq setups unless they duplicate the key into skills.entries. Consider falling back to process.env.GROQ_API_KEY (and/or the auth profile resolution used elsewhere) to match existing configuration paths.
Useful? React with 👍 / 👎.
|
@codex Both suggestions implemented in 5c44517e:
|
|
Codex Review: Didn't find any major issues. More of your lovely PRs please. ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
If Codex has suggestions, it will comment; otherwise it will react with 👍. Codex can also answer questions or update the PR. Try commenting "@codex address that feedback". |
5c44517 to
fb43b94
Compare
|
I thought we already has conf options for audio transcription? I'm using my own cli powered by gemini for that I'm using it like this "audio": {
"transcription": {
"command": [
"gemini-transcribe",
"-k",
"AIzaSy...FxNo",
"-b",
"https://proxy-url.workers.dev",
"-i",
"{{MediaPath}}"
],
"timeoutSeconds": 60
}
}In config.json |
b304fb0 to
7085cbd
Compare
Thanks, I'll look into those! The benefit with groq is that it's near instant transcription of voice notes, so it feels much more natural. I also have Gemini video understanding set up so the bot just responds naturally, as though it watched the video itself (maybe you do this also, not sure). Clawdbot only sees the voice note or video after transcription, so it doesn't need to manually do anything or get confused about multiple messages, again maybe you have it set up like this too? I'll keep the PR in draft until I check out the other options, this is just how I set it up. |
|
Just had a look at the existing tools.audio.transcription config, it works nicely for CLI-based workflows. The main things this PR adds on top:
The two approaches don't conflict, if someone's using the CLI-based config, that still works. This just adds a simpler path for people who don't want to install/manage external tools. |
|
Very cool! Will look at this after the next release. |
|
sorry, I though the existing implemtation worked like that. I mean, it already transcribed the audio before hit's the agent? but the per chat gating thingy is super cool tbh 💌 |
|
Defo! I'll look into that today/tomorrow! |
Add first-class voice note transcription to the WhatsApp inbound pipeline. When enabled, voice notes are automatically transcribed via Groq Whisper and the transcript replaces the <media:audio> placeholder so the agent responds to text instead of raw audio. Features: - Transcription via Groq Whisper API (whisper-large-v3-turbo default) - Per-chat configuration: DMs enabled by default, groups opt-in - Transcript persistence as sidecar files (.transcript.txt) - Graceful fallback if transcription fails - GROQ_API_KEY env var fallback for API key Co-Authored-By: Claude Opus 4.5 <[email protected]>
Add video understanding to the WhatsApp inbound pipeline. When a video is received, it can be sent to Gemini 3 Flash API for description. The bot receives the description with context to respond naturally. Features: - Video analysis via Gemini 3 Flash API (gemini-3-flash-preview default) - Per-chat configuration: DMs enabled by default, groups opt-in - Description persistence as sidecar files (.description.txt) - Graceful fallback if analysis fails - GEMINI_API_KEY env var fallback for API key Co-Authored-By: Claude Opus 4.5 <[email protected]>
- Add VoiceNotesConfig and VideoConfig types - Add Zod validation schemas for new config sections - Integrate transcription and video understanding into WhatsApp inbound pipeline - Include transcription, video-understanding, and plugins modules in package Co-Authored-By: Claude Opus 4.5 <[email protected]>
Add interactive prompts for configuring voice note transcription (Groq) and video understanding (Gemini) during WhatsApp onboarding flow. Features: - Opt-in confirmation for each media feature - API key setup with 3-tier fallback (existing config → env var → manual) - Chat scope selection (DMs only or DMs + all groups) - Format validation for Groq (gsk_*) and Gemini API keys - Help links and clear skip messages Implementation: - Export upsertSkillEntry() from merge-config for skill API key management - Add validateGroqApiKey() and validateGeminiApiKey() validators - Add promptVoiceTranscription() and promptVideoUnderstanding() functions - Wire media prompts into WhatsApp configure() method Co-Authored-By: Claude Sonnet 4.5 <[email protected]>
The Zod schema and TypeScript types had messaging providers (whatsapp, telegram, discord, etc.) at the root level, but all runtime code expected them under a `channels` wrapper. This mismatch caused 343 type errors and broke WhatsApp config merging in web/accounts.ts and merge-config.ts. Wrapped all provider schemas in a channels object to match runtime usage. Fixes type errors and ensures config validation works correctly. Co-Authored-By: Claude Sonnet 4.5 <[email protected]>
…tions Replaces non-atomic `fs.writeFile()` calls in `persistTranscript()` and `persistDescription()` with atomic temp-file-then-rename pattern. This prevents data corruption when concurrent webhook processing writes to the same sidecar file. Implementation: - Created shared `atomicWriteFile()` utility in `src/utils/atomic-write.ts` - Uses unique temp file with UUID suffix for each write operation - POSIX-guaranteed atomic `fs.rename()` to final location - Automatic cleanup of temp files on error - Comprehensive unit tests covering atomic behavior, concurrent writes, error handling, and edge cases (9 tests, all passing) Fixes: - Race condition when duplicate webhooks process same media file - Data corruption from interrupted writes leaving partial UTF-8 sequences - Last-write-wins now atomic (no partial states visible) Resolves openclaw#5 (todos/005-pending-p1-race-condition-sidecar-files.md) 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Sonnet 4.5 <[email protected]>
Updated todo file status from pending to resolved after implementing atomic write pattern for sidecar file creation. Implemented: - Atomic write utility with comprehensive tests - Applied to both transcription and video sidecar persistence - All acceptance criteria met - 9 unit tests passing Co-Authored-By: Claude Sonnet 4.5 <[email protected]>
Add comprehensive runtime validation to prevent silent failures when API responses are malformed, empty, or contain errors. Changes: - Groq STT (src/transcription/groq.ts): - Validate JSON structure and detect error responses - Check text field exists and is a non-empty string - Throw descriptive errors with response excerpts - Validate both JSON and plain text responses - Gemini video understanding (src/video-understanding/gemini.ts): - Validate candidates array structure - Validate content and parts hierarchy - Check text field exists and is a non-empty string - Throw descriptive errors with response excerpts - Tests (groq.test.ts, gemini.test.ts): - 52 new tests covering all validation branches - Test malformed JSON, missing fields, type mismatches - Test empty responses and API error responses - Test successful cases with valid data Fixes openclaw#6 (todos/006-pending-p1-no-api-response-validation.md) Co-Authored-By: Claude Sonnet 4.5 <[email protected]>
Implement error-level logging for critical filesystem errors when persisting sidecar files. Categorizes errors as critical (ENOSPC, EACCES, EROFS, EDQUOT) vs non-critical. Critical errors are logged at ERROR level for visibility, while non-critical errors remain at verbose level to avoid noise. Changes: - Update persistTranscript() to return Promise<boolean> - Update persistDescription() to return Promise<boolean> - Add getChildLogger imports to both modules - Log critical filesystem errors at ERROR level with structured context - Keep backward compatibility (callers ignore return value) Resolves todos/007-pending-p1-silent-sidecar-persistence-failures.md Co-Authored-By: Claude Sonnet 4.5 <[email protected]>
Consolidate duplicate caption handling logic between voice note and video processing into a shared enrichBodyWithMediaContent helper function. Addresses todos/009-pending-p2-caption-handling-duplication.md
Extracted caption enrichment helper function per Solution 1 recommendation. All tests pass, behavior unchanged.
Implements Solution 1 from todos/010 to prevent orphaned sidecar accumulation: - Add SIDECAR_PATTERNS constant for known sidecar types - Update cleanOldMedia() to delete sidecars with parent media files - Add recursive directory support and directory filtering - Add comprehensive unit tests for sidecar cleanup Resolves issue openclaw#10 (orphaned sidecar files) 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Sonnet 4.5 <[email protected]>
31c3e87 to
01382b7
Compare
|
@steipete I find this really useful, but I realise that it has a few issues, like only supporting Groq for voice, and only supporting the whatsapp channel. Let me know if you want me to continue to work on this for multiple providers/channels, or drop it |
|
Closing, the oracle proposed a far more elegant solution than Opus. Will work on it :) |
Summary
Adds two media understanding features to the WhatsApp inbound pipeline:
Voice Note Transcription (Groq Whisper)
whisper-large-v3-turbo)[Voice Note]\n<transcript>Video Understanding (Gemini 3 Flash)
⚡ Performance
Both APIs are fast:
Configuration
Files Changed
Transcription module:
src/transcription/groq.ts- Groq Whisper API driversrc/transcription/index.ts- Service with per-chat gatingsrc/transcription/index.test.ts- 18 unit testsVideo understanding module:
src/video-understanding/gemini.ts- Gemini 3 Flash API driversrc/video-understanding/index.ts- Service with per-chat gatingsrc/video-understanding/index.test.ts- 19 unit testsConfig & integration:
src/config/types.ts-VoiceNotesConfig,VideoConfigtypessrc/config/zod-schema.ts- Zod validation schemassrc/web/inbound.ts- Integration in WhatsApp pipelinepackage.json- Include modules in published packageTest plan
.transcript.txt,.description.txt)🤖 Generated with Claude Code