Skip to content

feat(whatsapp): add voice note transcription and video understanding - #719

Closed
tristanmanchester wants to merge 14 commits into
openclaw:mainfrom
tristanmanchester:feat/voice-note-transcription
Closed

tristanmanchester wants to merge 14 commits into
openclaw:mainfrom
tristanmanchester:feat/voice-note-transcription

Conversation

@tristanmanchester

@tristanmanchester tristanmanchester commented Jan 11, 2026 •

Copy link
Copy Markdown
Contributor

Summary

Adds two media understanding features to the WhatsApp inbound pipeline:

Voice Note Transcription (Groq Whisper)

  • Transcribe voice notes via Groq Whisper API (default: whisper-large-v3-turbo)
  • Replace audio placeholder with [Voice Note]\n<transcript>

Video Understanding (Gemini 3 Flash)

  • Analyze videos via Google Gemini 3 Flash API
  • Replace video placeholder with description + context for natural responses

⚡ Performance

Both APIs are fast:

  • Groq Whisper: ~1-2 seconds for voice notes
  • Gemini 3 Flash: ~3-5 seconds for video analysis

Configuration

{
  "voiceNotes": {
    "transcription": {
      "enabled": true,
      "provider": "groq",
      "dmEnabled": true,
      "groupEnabled": false
    }
  },
  "video": {
    "understanding": {
      "enabled": true,
      "provider": "gemini",
      "dmEnabled": true,
      "groupEnabled": false
    }
  },
  "skills": {
    "entries": {
      "groq": { "apiKey": "..." },
      "gemini": { "apiKey": "..." }
    }
  }
}

Files Changed

Transcription module:

  • src/transcription/groq.ts - Groq Whisper API driver
  • src/transcription/index.ts - Service with per-chat gating
  • src/transcription/index.test.ts - 18 unit tests

Video understanding module:

  • src/video-understanding/gemini.ts - Gemini 3 Flash API driver
  • src/video-understanding/index.ts - Service with per-chat gating
  • src/video-understanding/index.test.ts - 19 unit tests

Config & integration:

  • src/config/types.ts - VoiceNotesConfig, VideoConfig types
  • src/config/zod-schema.ts - Zod validation schemas
  • src/web/inbound.ts - Integration in WhatsApp pipeline
  • package.json - Include modules in published package

Test plan

  • Unit tests: 37 tests passing (18 transcription + 19 video)
  • Live test: voice note transcription via Groq Whisper
  • Live test: video understanding via Gemini 3 Flash
  • Sidecar files saved (.transcript.txt, .description.txt)
  • Build and lint pass

🤖 Generated with Claude Code

@tristanmanchester
tristanmanchester force-pushed the feat/voice-note-transcription branch from 5d0a048 to b8541b2 Compare January 11, 2026 13:10
@tristanmanchester
tristanmanchester marked this pull request as ready for review January 11, 2026 13:55
@tristanmanchester tristanmanchester changed the title feat(whatsapp): add built-in voice note transcription via Groq Whisper feat(whatsapp): add voice note transcription and video understanding Jan 12, 2026
@tristanmanchester
tristanmanchester marked this pull request as draft January 12, 2026 09:40
@tristanmanchester
tristanmanchester force-pushed the feat/voice-note-transcription branch from a92879e to 9a0d9eb Compare January 12, 2026 10:17
@tristanmanchester
tristanmanchester marked this pull request as ready for review January 12, 2026 10:27
@tristanmanchester

Copy link
Copy Markdown
Contributor Author

@codex if you can see this pls review lol

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 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".

Comment thread src/web/inbound.ts Outdated
Comment on lines +432 to +435
if (result?.text) {
// Replace video placeholder with description
body = result.text;
if (shouldLogVerbose()) {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge 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 👍 / 👎.

Comment on lines +54 to +61
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;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge 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 👍 / 👎.

@tristanmanchester

Copy link
Copy Markdown
Contributor Author

@codex Both suggestions implemented in 5c44517e:

  1. GROQ_API_KEY fallback - resolveApiKey now falls back to process.env.GROQ_API_KEY for the groq provider

  2. Caption preservation - Both voice notes and videos now check if body is a media placeholder before replacing. If the user included a caption, it's preserved alongside the transcript/description.

@chatgpt-codex-connector

Copy link
Copy Markdown
Contributor

Codex Review: Didn't find any major issues. More of your lovely PRs please.

ℹ️ 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".

@tristanmanchester
tristanmanchester force-pushed the feat/voice-note-transcription branch from 5c44517 to fb43b94 Compare January 12, 2026 11:37
@tristanmanchester
tristanmanchester marked this pull request as draft January 13, 2026 04:57
@mukhtharcm

mukhtharcm commented Jan 13, 2026 •

Copy link
Copy Markdown
Member

I thought we already has conf options for audio transcription?

I'm using my own cli powered by gemini for that

https://github.com/mukhtharcm/gemini-transcribe

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

@tristanmanchester
tristanmanchester force-pushed the feat/voice-note-transcription branch from b304fb0 to 7085cbd Compare January 13, 2026 05:08
@tristanmanchester

Copy link
Copy Markdown
Contributor Author

I thought we already has conf options for audio transcription?

I'm using my own cli powered by gemini for that

https://github.com/mukhtharcm/gemini-transcribe

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

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.

@tristanmanchester

Copy link
Copy Markdown
Contributor Author

@mukhtharcm

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:

  1. Zero-dependency option - no external binary needed, just an API key
  2. Per-chat gating - dmEnabled, groupEnabled, groupAllowFrom so you can enable for DMs but not groups (or specific groups only)
  3. Earlier pipeline integration - transcription happens in the WhatsApp inbound step, so by the time the agent sees the message it's already text

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.

@steipete

Copy link
Copy Markdown
Contributor

Very cool! Will look at this after the next release.

@tristanmanchester
tristanmanchester marked this pull request as ready for review January 13, 2026 07:10
@mukhtharcm

Copy link
Copy Markdown
Member

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 💌

@steipete

Copy link
Copy Markdown
Contributor

Defo! I'll look into that today/tomorrow!

tristanmanchester and others added 10 commits January 15, 2026 08:02
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]>
tristanmanchester and others added 4 commits January 15, 2026 13:01
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]>
@tristanmanchester
tristanmanchester marked this pull request as draft January 15, 2026 12:37
@tristanmanchester
tristanmanchester force-pushed the feat/voice-note-transcription branch from 31c3e87 to 01382b7 Compare January 15, 2026 12:37
@tristanmanchester

Copy link
Copy Markdown
Contributor Author

@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

@tristanmanchester

Copy link
Copy Markdown
Contributor Author

Closing, the oracle proposed a far more elegant solution than Opus. Will work on it :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants