Skip to content

Commit 747d007

Browse files
committed
use generic send message
1 parent 581975a commit 747d007

File tree

2 files changed

+26
-10
lines changed

2 files changed

+26
-10
lines changed

vapi_python/daily_call.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -166,9 +166,12 @@ def send_app_message(self, message):
166166
"""
167167
Send an application message to the assistant.
168168
169-
:param message: The message to send.
169+
:param message: The message to send (expects a dictionary).
170170
"""
171171
try:
172+
if not isinstance(message, dict):
173+
raise ValueError("Message must be a dictionary.")
174+
172175
serialized_message = json.dumps(message)
173176
self.__call_client.send_app_message(serialized_message)
174177
except Exception as e:

vapi_python/vapi_python.py

Lines changed: 22 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -63,20 +63,33 @@ def stop(self):
6363
self.__client.leave()
6464
self.__client = None
6565

66-
def send(self, message_type, message_content):
66+
def send(self, message):
6767
"""
68-
Send a message to the assistant.
68+
Send a generic message to the assistant.
6969
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.
7271
"""
7372
if not self.__client:
7473
raise Exception("Call not started. Please start the call first.")
7574

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+
"""
7688
message = {
77-
"type": message_type,
78-
"message": message_content
89+
'type': 'add-message',
90+
'message': {
91+
'role': role,
92+
'content': content
93+
}
7994
}
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)

0 commit comments

Comments
 (0)