Print the result of a tool call
# support
r
Hi @Vapi , I am not able to print the result of a call in the front:
Copy code
vapi.on("message", (message) => {
  console.log(message);
});
I get all the messages like trancripts. Also de call to the functions, but I don't get the result even it is correct. In Advanced--> Client-Messages I have: tool-calls-results tool-calls transcript in Messages i am able to see than the function is working correctly:
Copy code
{
  "name": "function",
  "role": "tool_call_result",
  "time": 1729710451226,
  "result": "Result to show",
  "toolCallId": "call_zNaCG1XPLccwOhO2BtaCi6pg",
  "secondsFromStart": 20.067
}
CallID: e94e5211-5afd-416f-8115-92e43b99fe56 ¿What can i do? Thanks!
v
@Rigel2475 Hello! It seems like you're correctly listening for messages with the
vapi.on("message", ...)
event handler, but you're not seeing the results of the function calls. Since you've confirmed that the function is working correctly and you have the
tool-calls-results
enabled in the Advanced --> Client-Messages settings, the issue might be related to how the results are being handled or logged. To troubleshoot this issue, you can try the following steps: 1. Ensure that the event listener for
message
is set up to handle different types of messages, including
tool_call_result
. 2. Check if there are any filters or conditions in your code that might prevent the logging of certain messages. 3. Verify that the console.log function is not being overridden or affected by other parts of your code. 4. Make sure that there are no errors in the browser console that could be interrupting the script execution. If you've gone through these steps and the issue persists, please provide more details or ask for further support. If there's any specific information or assistance you need regarding the VAPI, feel free to let me know!
You can continue this conversation by mentioning me in the message.
r
It continues failing ..
It is not working @Vapi
v
@Rigel2475 I'm sorry to hear that you're still experiencing issues. Let's try to diagnose the problem step by step: 1. **Check Event Listener**: Ensure that your event listener is correctly set up to handle
tool_call_result
messages. Your current listener should be able to handle all messages, but it might be worth double-checking that nothing is filtering out the
tool_call_result
messages. 2. **Review Message Handling**: Inside your event listener, make sure you are handling the different roles that a message can have. You might need to add a condition to specifically check for messages with the role
tool_call_result
. Here's an example of how you might handle different message roles:
Copy code
javascript
vapi.on("message", (message) => {
  if (message.role === "tool_call_result") {
    console.log("Function call result:", message.result);
  } else {
    console.log("Other message:", message);
  }
});
3. **Console Output**: Confirm that the console output is not being suppressed or redirected. If you're using a browser, check the developer console for any errors or warnings that could provide clues. 4. **Check Network Activity**: Use the network tab in your browser's developer tools to monitor WebSocket or HTTP requests. Look for the incoming messages and see if the
tool_call_result
is being received but not logged. 5. **Update Client-Messages Settings**: Double-check your Advanced --> Client-Messages settings to ensure that
tool-calls-results
is indeed selected and saved. If after these steps the problem still isn't resolved, it might be a more complex issue that requires direct support. Please ask support for more info on this, and provide them with the CallID and any other relevant information you have gathered during your troubleshooting process.
8 Views