File tree Expand file tree Collapse file tree 2 files changed +26
-10
lines changed Expand file tree Collapse file tree 2 files changed +26
-10
lines changed Original file line number Diff line number Diff line change @@ -166,9 +166,12 @@ def send_app_message(self, message):
166
166
"""
167
167
Send an application message to the assistant.
168
168
169
- :param message: The message to send.
169
+ :param message: The message to send (expects a dictionary) .
170
170
"""
171
171
try :
172
+ if not isinstance (message , dict ):
173
+ raise ValueError ("Message must be a dictionary." )
174
+
172
175
serialized_message = json .dumps (message )
173
176
self .__call_client .send_app_message (serialized_message )
174
177
except Exception as e :
Original file line number Diff line number Diff line change @@ -63,20 +63,33 @@ def stop(self):
63
63
self .__client .leave ()
64
64
self .__client = None
65
65
66
- def send (self , message_type , message_content ):
66
+ def send (self , message ):
67
67
"""
68
- Send a message to the assistant.
68
+ Send a generic message to the assistant.
69
69
70
- :param message_type: Type of message, such as 'add-message'.
71
- :param message_content: The content of the message.
70
+ :param message: A dictionary containing the message type and content.
72
71
"""
73
72
if not self .__client :
74
73
raise Exception ("Call not started. Please start the call first." )
75
74
75
+ # Check message format here instead of serialization
76
+ if not isinstance (message , dict ) or 'type' not in message :
77
+ raise ValueError ("Invalid message format." )
78
+
79
+ try :
80
+ self .__client .send_app_message (message ) # Send dictionary directly
81
+ except Exception as e :
82
+ print (f"Failed to send message: { e } " )
83
+
84
+ def add_message (self , role , content ):
85
+ """
86
+ method to send text messages with specific parameters.
87
+ """
76
88
message = {
77
- "type" : message_type ,
78
- "message" : message_content
89
+ 'type' : 'add-message' ,
90
+ 'message' : {
91
+ 'role' : role ,
92
+ 'content' : content
93
+ }
79
94
}
80
-
81
- # Simulate sending a message by calling the appropriate method on the client
82
- self .__client .send_app_message (message )
95
+ self .send (message )
You can’t perform that action at this time.
0 commit comments