Sending ad-hoc messages to the ClientSDK
# support
j
I've been trying to find information on the correct way to send ad-hoc messages to the ClientSDK. I want my voice assistant to be able to navigate around my website. I have currently implemented this using a tool, with the server URL set as a dummy URL. Since this server URL is a required parameter, I am concerned this might not be the best way to do this. I've been looking into the ClientMessages documentation, but can find nothing helpful there. I tried instructing the assistant to send metadata messages instead of calling my tool, but this didn't work. Can anyone advise?
v
@John George It sounds like you're looking to have your voice assistant send messages to your client application to navigate around your website. Using the
clientMessages
field to specify the types of messages your assistant should send back to the client is indeed the right approach. When you create your assistant, you can define custom messages that you want to be sent to your client application. These messages can be used to instruct your client-side code to navigate to different parts of your website. Here's how you can set it up: 1. Define the custom messages you want your assistant to send. These could be identifiers like "NAVIGATE_HOME", "NAVIGATE_CONTACT", etc. 2. Configure your assistant to send these messages at the appropriate times during the interaction with the user. 3. On your client-side application, listen for these
message
events from the assistant. 4. When a message is received, use the identifier to determine which action to take, such as navigating to a specific URL or performing a certain action on your website. If you're unsure about how to configure the
clientMessages
field or how to set up the message event listeners on your client application, please ask support for more info on this. They can provide you with specific guidance tailored to your setup and requirements.
You can continue this conversation by mentioning me in the message.
j
@Vapi where do I define custom client messages?
v
@John George Custom client messages are typically defined within your voice application's configuration or codebase, depending on how your system is set up. Here's a general approach to defining and using custom client messages: 1. **Define Custom Message Types**: Decide on the types of custom messages you want to send from your voice assistant to the client SDK. These should be identifiers that your client application can understand and act upon. 2. **Update Client SDK Configuration**: Within your client application, configure the SDK to listen for these custom message types. This usually involves setting up event listeners that can handle the messages when they are received. 3. **Implement Handling Logic**: In your client application, implement the logic to handle the custom messages. This means writing functions or methods that will be triggered when a custom message is received, causing the desired action, such as navigation on your website. 4. **Send Custom Messages from Voice Assistant**: In the logic of your voice assistant, use the appropriate method or function to send the custom messages to the client SDK at the right times. This could be in response to specific user commands or other triggers. 5. **Test the Integration**: After setting up the custom messages and the handling logic, test the entire flow to ensure that when the voice assistant sends a custom message, the client application receives it and performs the correct action. If you need to know the exact method or function to call within your voice assistant to send these custom messages, or if you require assistance with the specific syntax or parameters, please ask support for more info on this. They can provide detailed instructions based on the specifics of your voice assistant platform and SDK.
j
@Vapi for "Send Custom Messages from Voice Assistant" in your previous response, how can I define the format of a custom message I want my assistant to send? Where do I do this? For example, let's say I want the client to send a custom message called navigate-site. How and where would I define that?
r.i.p.
s
from here checkout ClientInboundMessageAddMessage to add messages to context history from client side.
ref: https://api.vapi.ai/api-json# go to: components > schemas > ClientInboundMessage > ClientInboundMessageAddMessage
j
okay but I don't want to add messages from the client, I want to send messages from the assistant to the client who is subscribed to updates on the WebSDK
I am currently doing it via tool calls, but the issue is whether this is the best way, since I set the server URL for this to https://dummy.dummy/toolname
I was looking at ClientInboundMessageAddMessage yesterday as a way of perhaps having a hybrid text & voice chatbox via Vapi
s
if you only require model output you can try using conversation-update or model-output which ever works for you.
j
I'll just keep using tools with the dummy server URL. I think you ought to consider making it optional in the future to support my use case.
3 Views