Skip to content

[Fix] 020-twilio-media-streams-node — update to SDK v5 createConnection/waitForOpen API#84

Merged
lukeocodes merged 2 commits intomainfrom
fix/020-twilio-media-streams-node-regression-2026-03-30
Mar 30, 2026
Merged

[Fix] 020-twilio-media-streams-node — update to SDK v5 createConnection/waitForOpen API#84
lukeocodes merged 2 commits intomainfrom
fix/020-twilio-media-streams-node-regression-2026-03-30

Conversation

@github-actions
Copy link
Copy Markdown
Contributor

Fix: 020-twilio-media-streams-node regression

Root cause: The example used the old listen.v1.connect() pattern which immediately opens a WebSocket, then called dgConnection.connect() again causing a reconnection cycle. It also used the deprecated sendCloseStream() method and manually parsed JSON from the message event (which the SDK v5 already provides as parsed objects).

Changes

  • src/index.js:
    • Use createConnection() + connect() + waitForOpen() pattern per SDK v5 docs
    • Replace sendCloseStream({ type: 'CloseStream' }) with sendFinalize({ type: 'Finalize' })
    • Simplify message handler — SDK v5 already parses JSON before emitting message events

Test plan

  • CI runs the test and passes
  • Deepgram transcription still receives recognizable words from spacewalk audio

Fixed by engineer on 2026-03-30

…et API

Use createConnection/connect/waitForOpen pattern instead of deprecated
connect-then-reconnect flow. Replace sendCloseStream with sendFinalize.
Remove redundant JSON.parse in message handler (SDK provides parsed data).

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>
@github-actions github-actions bot added the type:fix Bug fix label Mar 30, 2026
@github-actions
Copy link
Copy Markdown
Contributor Author

Code Review

Overall: APPROVED

Integration genuineness

Pass — Twilio SDK (twilio ^5.4.0) is a dependency, src/index.js imports it and generates real TwiML with <Connect><Stream> for Twilio Media Streams. .env.example lists TWILIO_ACCOUNT_SID, TWILIO_AUTH_TOKEN, and TWILIO_PHONE_NUMBER. Test exits 2 on missing credentials and makes real Deepgram API calls with Twilio-formatted WebSocket messages.

Code quality

  • Official Deepgram SDK used (@deepgram/sdk ^5.0.0) ✓
  • No hardcoded credentials ✓
  • Error handling covers main failure cases ✓
  • The three changes are correct for SDK v5:
    • connect()createConnection() + connect() + waitForOpen() separates connection creation from opening
    • sendCloseStream()sendFinalize() uses the current API
    • Message handler simplified — SDK v5 already parses JSON before emitting message

Documentation

  • README accurately describes the end result ✓
  • All env vars documented with where-to-find links ✓
  • Run instructions are complete ✓

Tests

  • Credential check runs first, before app import ✓
  • Exit code 2 for missing credentials ✓
  • Real API calls (downloads audio, streams to Deepgram) ✓
  • Asserts meaningful content (checks for spacewalk/astronaut/nasa keywords) ✓

✓ All checks pass. Marking review passed.


Review by Lead on 2026-03-30

@github-actions github-actions bot added the status:review-passed Self-review passed label Mar 30, 2026
@lukeocodes lukeocodes merged commit b7d4cd7 into main Mar 30, 2026
12 checks passed
@lukeocodes lukeocodes deleted the fix/020-twilio-media-streams-node-regression-2026-03-30 branch March 30, 2026 19:36
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

status:review-passed Self-review passed type:fix Bug fix

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant