From ac09edab26288d33114b42dd081d327a9d70b69c Mon Sep 17 00:00:00 2001
From: Chad Bailey <chadbailey@gmail.com>
Date: Mon, 16 Sep 2024 20:55:19 +0000
Subject: [PATCH] added RTVIActionFrame

---
 src/pipecat/processors/frameworks/rtvi.py | 13 +++++++++++++
 1 file changed, 13 insertions(+)

diff --git a/src/pipecat/processors/frameworks/rtvi.py b/src/pipecat/processors/frameworks/rtvi.py
index dd28e7252..a4368ab64 100644
--- a/src/pipecat/processors/frameworks/rtvi.py
+++ b/src/pipecat/processors/frameworks/rtvi.py
@@ -8,12 +8,14 @@
 
 from typing import Any, Awaitable, Callable, Dict, List, Literal, Optional, Union
 from pydantic import BaseModel, Field, PrivateAttr, ValidationError
+from dataclasses import dataclass
 
 from pipecat.frames.frames import (
     BotInterruptionFrame,
     BotStartedSpeakingFrame,
     BotStoppedSpeakingFrame,
     CancelFrame,
+    DataFrame,
     EndFrame,
     ErrorFrame,
     Frame,
@@ -116,6 +118,12 @@ class RTVIActionRun(BaseModel):
     arguments: Optional[List[RTVIActionRunArgument]] = None
 
 
+@dataclass
+class RTVIActionFrame(DataFrame):
+    rtvi_action_run: RTVIActionRun
+    message_id: Optional[str] = "webhook"
+
+
 class RTVIMessage(BaseModel):
     label: Literal["rtvi-ai"] = "rtvi-ai"
     type: str
@@ -377,6 +385,11 @@ async def process_frame(self, frame: Frame, direction: FrameDirection):
             await self.push_frame(frame, direction)
         elif isinstance(frame, TransportMessageFrame):
             await self._message_queue.put(frame)
+        elif isinstance(frame, RTVIActionFrame):
+            if not frame.message_id:
+                # The response isn't going anywhere anyway
+                frame.message_id = "webhook"
+            await self._handle_action(frame.message_id, frame.rtvi_action_run)
         # Other frames
         else:
             await self.push_frame(frame, direction)