End the call through a tool response
# support
i
I want to have the ability to end the call within a function call. I see a property for that --
messageResponse.results.message.endCallAfterSpokenEnabled
in the API Reference -- https://docs.vapi.ai/api-reference/messages/server-message-response. But when my server response:
Copy code
{
  "results": [
    {
      "toolCallId": "call_NAFDN6PoLKFDIZ4x7q7woSo6",
      "name": "sayAndEndCall",
      "message": [
        {
          "type": "request-complete",
          "role": "assistant",
          "endCallAfterSpokenEnabled": true,
          "content": "See you later!"
        }
      ]
    }
  ]
}
the call is not ending and Vapi log says:
Copy code
{
  "name": "sayAndEndCall",
  "role": "tool_call_result",
  "time": 1724858330445,
  "result": "No result returned for call_NAFDN6PoLKFDIZ4x7q7woSo6.",
  "toolCallId": "call_NAFDN6PoLKFDIZ4x7q7woSo6",
  "secondsFromStart": 5.806
}
When I add
result
property as mentioned at https://docs.vapi.ai/tools-calling#server-response-format-providing-results-and-context:
Copy code
{
  "results": [
    {
      "toolCallId": "call_7NaRwuEMR9J7IMdfO1KLteU0",
      "name": "sayAndEndCall",
      "result": "test",
      "message": [
        {
          "type": "request-complete",
          "role": "assistant",
          "endCallAfterSpokenEnabled": true,
          "content": "See you later!"
        }
      ]
    }
  ]
}
The call is also not ending and logs:
Copy code
{
  "name": "sayAndEndCall",
  "role": "tool_call_result",
  "time": 1724859397412,
  "result": "Success.",
  "toolCallId": "call_7NaRwuEMR9J7IMdfO1KLteU0",
  "secondsFromStart": 12.731
}
What am I doing wrong? How do I activate this function? Is it implemented on the Vapi side, or is it just outdated documentation?
v
@Ivan It seems like you're on the right track with using the
endCallAfterSpokenEnabled
property to end the call after the message is spoken. However, the issue might be with the structure of your server response. The
message
property should be an object, not an array. Here's how you can correct it:
Copy code
json
{
  "results": [
    {
      "toolCallId": "call_NAFDN6PoLKFDIZ4x7q7woSo6",
      "name": "sayAndEndCall",
      "message": {
        "type": "request-complete",
        "role": "assistant",
        "endCallAfterSpokenEnabled": true,
        "content": "See you later!"
      }
    }
  ]
}
Make sure that your server response matches the expected format as per the VAPI documentation. If you've already tried this and it's still not working, it could be an issue on the VAPI side, or there might be additional context required that's not included in your message. If you're still experiencing issues after making the above adjustment, please ask support for more info on this. They will be able to provide you with the most up-to-date information and assistance.
You can continue this conversation by mentioning me in the message.
i
I've tried just now to response with an object for `message`:
Copy code
{
  "results": [
    {
      "toolCallId": "call_NuJd0VIpuTyzt4Cpdr6v6SWo",
      "name": "sayAndEndCall",
      "message": {
        "type": "request-complete",
        "role": "assistant",
        "endCallAfterSpokenEnabled": true,
        "content": "See you later!"
      }
    }
  ]
}
Still negative result:
Copy code
{
  "name": "sayAndEndCall",
  "role": "tool_call_result",
  "time": 1724861862090,
  "result": "No result returned for call_NuJd0VIpuTyzt4Cpdr6v6SWo.",
  "toolCallId": "call_NuJd0VIpuTyzt4Cpdr6v6SWo",
  "secondsFromStart": 9.124
}
I’ve also added
result
property, and now it works! Thanks! However, I noticed that the documentation says
message
is an array and that
result
is not required.
Copy code
{
  "results": [
    {
      "toolCallId": "call_v4rvcZo1VMW6DxzipcQ2x288",
      "name": "sayAndEndCall",
      "result": "Success.",
      "message": {
        "type": "request-complete",
        "role": "assistant",
        "endCallAfterSpokenEnabled": true,
        "content": "See you later!"
      }
    }
  ]
}
https://cdn.discordapp.com/attachments/1278387163586625650/1278390646188671120/image.png?ex=66d0a191&is=66cf5011&hm=21c6427bcb6de3319f473268ca2173456d7ec0369634e229661461e1d81934f0&
8 Views