Skip to content

Commit 64410eb

Browse files
committed
Fix parsing issue
1 parent 7d0f970 commit 64410eb

File tree

1 file changed

+15
-7
lines changed

1 file changed

+15
-7
lines changed

coffee_ws/src/coffee_voice_agent/coffee_voice_agent/voice_agent_bridge.py

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@
1010
import json
1111
import asyncio
1212
import threading
13+
import time
14+
import uuid
1315
from typing import Optional
1416

1517
import rclpy
@@ -202,13 +204,19 @@ def handle_virtual_request(self, msg: String):
202204
# Parse the ROS2 message
203205
request_data = json.loads(msg.data)
204206

205-
# Format for voice agent
207+
# Transform ROS2 format to voice agent WebSocket API format
208+
# ROS2 format: {"request_type": "NEW_COFFEE_REQUEST", "content": "Espresso", "priority": "normal"}
209+
# Voice agent expects: {"type": "NEW_COFFEE_REQUEST", "coffee_type": "Espresso", "order_id": "123", "priority": "normal"}
210+
211+
# Generate unique order ID for ROS2 requests
212+
order_id = f"ros2_{int(time.time())}_{str(uuid.uuid4())[:8]}"
213+
214+
# Format for voice agent WebSocket API
206215
command = {
207-
'type': 'VIRTUAL_REQUEST',
208-
'request_type': request_data.get('request_type', 'NEW_COFFEE_REQUEST'),
209-
'content': request_data.get('content', ''),
210-
'priority': request_data.get('priority', 'normal'),
211-
'timestamp': request_data.get('timestamp')
216+
'type': request_data.get('request_type', 'NEW_COFFEE_REQUEST'), # Map request_type → type
217+
'coffee_type': request_data.get('content', 'Coffee'), # Map content → coffee_type
218+
'order_id': order_id, # Generate missing order_id
219+
'priority': request_data.get('priority', 'normal') # Keep priority as-is
212220
}
213221

214222
# Send to voice agent
@@ -220,7 +228,7 @@ def handle_virtual_request(self, msg: String):
220228
else:
221229
self.get_logger().warn("Cannot send virtual request - WebSocket event loop not available")
222230

223-
self.get_logger().info(f"Forwarded virtual request: {request_data.get('request_type')}")
231+
self.get_logger().info(f"Forwarded virtual request: {request_data.get('request_type')} - {request_data.get('content')} (Order: {order_id})")
224232

225233
except json.JSONDecodeError as e:
226234
self.get_logger().error(f"Invalid JSON in virtual request: {e}")

0 commit comments

Comments
 (0)