Skip to content

Add Telnyx media streaming plugin#594

Merged
Nash0x7E2 merged 13 commits into
GetStream:mainfrom
a692570:codex/add-telnyx-phone-plugin
Jun 24, 2026
Merged

Add Telnyx media streaming plugin#594
Nash0x7E2 merged 13 commits into
GetStream:mainfrom
a692570:codex/add-telnyx-phone-plugin

Conversation

@a692570

@a692570 a692570 commented Jun 3, 2026

Copy link
Copy Markdown
Contributor

Why

Vision Agents already has a Twilio phone plugin and phone examples. Telnyx also supports WebSocket media streaming with PCMU, PCMA, L16, and bidirectional RTP, so this adds a parallel carrier media bridge without changing core agent APIs.

Reference: https://developers.telnyx.com/docs/voice/programmable-voice/media-streaming

Changes

  • Add vision-agents-plugins-telnyx as a workspace package and optional vision-agents[telnyx] extra
  • Add Telnyx media stream WebSocket handling for connected, start, media, stop, error, mark, and dtmf events
  • Add PCMU, PCMA, and L16 RTP payload conversion helpers using Vision Agents PcmData
  • Add a Telnyx call registry and attach_phone_to_call bridge matching the existing Twilio plugin shape
  • Add tests for audio conversion, registry behavior, media stream receive, and bidirectional audio send

Testing

  • uv run ruff check plugins/telnyx agents-core/pyproject.toml pyproject.toml README.md
  • uv run ruff format --check plugins/telnyx
  • uv run pytest plugins/twilio/tests plugins/telnyx/tests
  • git diff --check
  • secret scan over the diff found no matches

@coderabbitai

coderabbitai Bot commented Jun 3, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: c96ee63a-2931-46c9-8760-5f0961a22cd0

📥 Commits

Reviewing files that changed from the base of the PR and between 0f4f868 and ec49507.

📒 Files selected for processing (2)
  • plugins/telnyx/tests/test_examples.py
  • plugins/telnyx/vision_agents/plugins/telnyx/example_helpers.py
✅ Files skipped from review due to trivial changes (1)
  • plugins/telnyx/tests/test_examples.py
🚧 Files skipped from review as they are similar to previous changes (1)
  • plugins/telnyx/vision_agents/plugins/telnyx/example_helpers.py

📝 Walkthrough

Walkthrough

Telnyx support was added across the repository. The plugin now includes audio conversion, call registry, and media stream APIs, workspace and package metadata were updated, example helpers now handle setup, validation, and webhook verification, inbound and outbound FastAPI examples were added, and the README and test suites were updated.


Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@coderabbitai coderabbitai 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.

Actionable comments posted: 4


ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: 2514d5a1-b09e-4c2e-b410-bff2f77ec127

📥 Commits

Reviewing files that changed from the base of the PR and between 84eb332 and 4ae0467.

⛔ Files ignored due to path filters (1)
  • uv.lock is excluded by !**/*.lock
📒 Files selected for processing (12)
  • README.md
  • agents-core/pyproject.toml
  • plugins/telnyx/README.md
  • plugins/telnyx/py.typed
  • plugins/telnyx/pyproject.toml
  • plugins/telnyx/tests/test_audio.py
  • plugins/telnyx/tests/test_telnyx.py
  • plugins/telnyx/vision_agents/plugins/telnyx/__init__.py
  • plugins/telnyx/vision_agents/plugins/telnyx/audio.py
  • plugins/telnyx/vision_agents/plugins/telnyx/call_registry.py
  • plugins/telnyx/vision_agents/plugins/telnyx/media_stream.py
  • pyproject.toml

Comment thread plugins/telnyx/vision_agents/plugins/telnyx/call_registry.py
Comment thread plugins/telnyx/vision_agents/plugins/telnyx/media_stream.py Outdated
Comment thread plugins/telnyx/vision_agents/plugins/telnyx/media_stream.py Outdated
Comment thread plugins/telnyx/vision_agents/plugins/telnyx/media_stream.py Outdated
@Nash0x7E2 Nash0x7E2 self-assigned this Jun 13, 2026
@Nash0x7E2

Copy link
Copy Markdown
Member

Hi thank you for your PR, our team is reviewing and will follow up.

@Nash0x7E2

Copy link
Copy Markdown
Member

@a692570 - can you have a look at the remarks from Coderabbit?

@coderabbitai coderabbitai 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.

Actionable comments posted: 1

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (2)
plugins/telnyx/vision_agents/plugins/telnyx/call_registry.py (2)

8-8: 🛠️ Refactor suggestion | 🟠 Major | ⚡ Quick win

Adopt modern union syntax per coding guidelines.

Coding guidelines specify modern type syntax including X | Y unions instead of Optional[X]. Update type hints throughout the file.

Example changes
-from typing import Any, Callable, Coroutine, Optional, TYPE_CHECKING
+from typing import Any, Callable, Coroutine, TYPE_CHECKING

-    webhook_data: Optional[dict[str, Any]] = None
+    webhook_data: dict[str, Any] | None = None

-    def from_number(self) -> Optional[str]:
+    def from_number(self) -> str | None:

Also applies to: 24-29, 32-32, 40-45, 48-49, 56-56, 62-62, 82-83, 97-97, 114-114

Source: Coding guidelines


27-27: ⚠️ Potential issue | 🟠 Major

Replace deprecated datetime.utcnow() with datetime.now(timezone.utc) at both sites.

datetime.utcnow() is deprecated as of Python 3.12. Both usages must switch to timezone-aware equivalent.

  • Line 27: Replace datetime.utcnow in started_at field default with lambda: datetime.now(timezone.utc)
  • Line 53: Replace datetime.utcnow() in end() method with datetime.now(timezone.utc)

Add timezone to the import statement (line 7).

Fix
-from datetime import datetime
+from datetime import datetime, timezone
-    started_at: datetime = field(default_factory=datetime.utcnow)
+    started_at: datetime = field(default_factory=lambda: datetime.now(timezone.utc))
-        self.ended_at = datetime.utcnow()
+        self.ended_at = datetime.now(timezone.utc)
🧹 Nitpick comments (1)
plugins/telnyx/vision_agents/plugins/telnyx/call_registry.py (1)

8-8: ⚖️ Poor tradeoff

Minimize use of Any type per coding guidelines.

Guidelines state to avoid Any type. While webhook_data may genuinely be dynamic JSON, consider whether tighter types are possible for stream_call and method return values. If webhook schema is known, use TypedDict.

Also applies to: 24-24, 26-26, 32-32, 62-62, 82-83

Source: Coding guidelines


ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: 6cd7019c-fa6a-47ba-a543-8f0a6e444ece

📥 Commits

Reviewing files that changed from the base of the PR and between 4ae0467 and 851dbaf.

📒 Files selected for processing (3)
  • plugins/telnyx/tests/test_telnyx.py
  • plugins/telnyx/vision_agents/plugins/telnyx/call_registry.py
  • plugins/telnyx/vision_agents/plugins/telnyx/media_stream.py
🚧 Files skipped from review as they are similar to previous changes (1)
  • plugins/telnyx/vision_agents/plugins/telnyx/media_stream.py

Comment thread plugins/telnyx/tests/test_telnyx.py Outdated
@a692570

a692570 commented Jun 15, 2026

Copy link
Copy Markdown
Contributor Author

@Nash0x7E2 thanks for the nudge. I addressed the CodeRabbit remarks in the latest branch updates.

Covered:

  • removed caller and callee phone numbers from info logs
  • gated outbound Telnyx audio until the start frame is parsed
  • recreated the audio track from the negotiated media format
  • added RTC cleanup when the Telnyx media stream closes
  • added tests for negotiation, gated send, and cleanup
  • merged current main to clear the PR conflict

Local checks passed:

  • uv lock --check
  • uv run pytest plugins/telnyx/tests/test_telnyx.py plugins/telnyx/tests/test_audio.py
  • uv run ruff check plugins/telnyx && uv run ruff format --check plugins/telnyx
  • uv run mypy plugins/telnyx

CodeRabbit is passing now and the PR is no longer conflicted. GitHub still shows the PR as blocked because the fork PR CI workflows appear to need maintainer approval/action.

@Nash0x7E2

Copy link
Copy Markdown
Member

@a692570 - Great, running the example and will merge. Can ping you here once it's merged and share a link to an integration page on our docs. Feel free to email me if you'd like to collaborate on the integrations docs/page nash@getstream.io

@Nash0x7E2 Nash0x7E2 marked this pull request as ready for review June 22, 2026 22:43

@coderabbitai coderabbitai 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.

Actionable comments posted: 11

🧹 Nitpick comments (3)
plugins/telnyx/examples/telnyx_helpers.py (2)

207-214: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick win

Narrow the ngrok autodetection exception handling.

This suppresses all runtime errors from the detection block. Catch the expected urllib, timeout, decode, and JSON parsing failures instead.

Proposed change
-    except Exception:
+    except (
+        urllib.error.URLError,
+        TimeoutError,
+        UnicodeDecodeError,
+        json.JSONDecodeError,
+    ):
         return None

As per coding guidelines, "Prefer specific exceptions if they are known."

Source: Coding guidelines


311-314: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick win

Replace broad cleanup catches with known failure types.

The setup and cleanup paths know their likely failures: Telnyx API, urllib, timeout, JSON, and response-shape errors. Catch those explicitly so programmer errors are not treated as recoverable cleanup failures.

As per coding guidelines, "Prefer specific exceptions if they are known; use except Exception as e only when exception type is unclear."

Also applies to: 347-361

Source: Coding guidelines

plugins/telnyx/tests/test_examples.py (1)

42-78: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick win

Assert fake Telnyx state, not recorded call paths.

created_apps, deleted_apps, and updated_connections are call logs. Prefer a fake client that mutates simulated Telnyx resources and assert the resulting app/phone-number state.

As per path instructions, "Assert behavior and outputs, not initialization or call paths."

Also applies to: 199-206, 227-234

Source: Path instructions


ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: e6572ea0-e0e2-4fd5-a8cb-bcdce1d0cec8

📥 Commits

Reviewing files that changed from the base of the PR and between 82aedc7 and 1f55f38.

📒 Files selected for processing (9)
  • README.md
  • TELNYX_EXAMPLE_PLAN.md
  • plugins/telnyx/README.md
  • plugins/telnyx/examples/README.md
  • plugins/telnyx/examples/__init__.py
  • plugins/telnyx/examples/inbound_call.py
  • plugins/telnyx/examples/outbound_call.py
  • plugins/telnyx/examples/telnyx_helpers.py
  • plugins/telnyx/tests/test_examples.py
✅ Files skipped from review due to trivial changes (4)
  • plugins/telnyx/examples/init.py
  • TELNYX_EXAMPLE_PLAN.md
  • README.md
  • plugins/telnyx/examples/README.md

Comment thread plugins/telnyx/examples/inbound_call.py Outdated
Comment thread plugins/telnyx/examples/inbound_call.py Outdated
Comment thread plugins/telnyx/examples/inbound_call.py Outdated
Comment thread plugins/telnyx/examples/inbound_call.py Outdated
Comment thread plugins/telnyx/examples/inbound_call.py Outdated
Comment thread plugins/telnyx/examples/outbound_call.py Outdated
Comment thread plugins/telnyx/examples/outbound_call.py
Comment thread plugins/telnyx/examples/outbound_call.py Outdated
@@ -0,0 +1,464 @@
"""Helpers shared by the minimal Telnyx phone examples."""

from __future__ import annotations

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.

📐 Maintainability & Code Quality | 🟡 Minor | ⚡ Quick win

Remove the future annotations import.

This repository explicitly disallows from __future__ import annotations.

As per coding guidelines, "Never use from __future__ import annotations."

Source: Coding guidelines

Comment thread plugins/telnyx/tests/test_examples.py Outdated
Nash0x7E2 and others added 2 commits June 24, 2026 15:43
Move example helpers into the plugin package, verify Telnyx webhook
signatures, redact PII from logs, and harden async cleanup in the
runnable inbound/outbound examples.

Co-authored-by: Cursor <cursoragent@cursor.com>

@Nash0x7E2 Nash0x7E2 left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Addressed latest CodeRabbit feedback on the phone examples: webhook signature verification, PII-safe logging, async cleanup, package imports for tests, and merged latest main.

@coderabbitai coderabbitai 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.

Actionable comments posted: 1

🧹 Nitpick comments (2)
plugins/telnyx/vision_agents/plugins/telnyx/example_helpers.py (1)

489-504: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick win

Remove Any from the verified webhook parser contract.

dict[str, Any] leaks unchecked JSON through the public helper. Use a concrete JSON payload alias or dict[str, object] with a narrow cast/validation.

As per coding guidelines, "Avoid using Any type."

Source: Coding guidelines

plugins/telnyx/tests/test_examples.py (1)

27-85: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick win

Add annotations to the new test helper and test functions.

FakeTelnyxClient methods and the new tests omit parameter/return annotations; add -> None, parameter types, and concrete dict value types for the fake state.

As per coding guidelines, "Use type annotations everywhere."

Also applies to: 170-192, 207-264

Source: Coding guidelines


ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: c4f5996b-7794-493b-8808-020c13961a4d

📥 Commits

Reviewing files that changed from the base of the PR and between 1f55f38 and 490d21e.

⛔ Files ignored due to path filters (1)
  • uv.lock is excluded by !**/*.lock
📒 Files selected for processing (8)
  • README.md
  • plugins/telnyx/examples/README.md
  • plugins/telnyx/examples/inbound_call.py
  • plugins/telnyx/examples/outbound_call.py
  • plugins/telnyx/pyproject.toml
  • plugins/telnyx/tests/test_examples.py
  • plugins/telnyx/tests/test_telnyx.py
  • plugins/telnyx/vision_agents/plugins/telnyx/example_helpers.py
✅ Files skipped from review due to trivial changes (3)
  • plugins/telnyx/pyproject.toml
  • README.md
  • plugins/telnyx/examples/README.md
🚧 Files skipped from review as they are similar to previous changes (2)
  • plugins/telnyx/examples/outbound_call.py
  • plugins/telnyx/examples/inbound_call.py

Comment thread plugins/telnyx/vision_agents/plugins/telnyx/example_helpers.py Outdated

@Nash0x7E2 Nash0x7E2 left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Re-approved after pushing CodeRabbit fixes and merging main. All unit checks are green.

Map invalid timestamps, payloads, and key material to
TelnyxWebhookVerificationError instead of leaking parse errors.

Co-authored-by: Cursor <cursoragent@cursor.com>

@Nash0x7E2 Nash0x7E2 left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Approved after final webhook verification hardening.

Co-authored-by: Cursor <cursoragent@cursor.com>
@Nash0x7E2 Nash0x7E2 merged commit d93f0b4 into GetStream:main Jun 24, 2026
11 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants