Needs help with javascript code in json structure
# support
e
Reposting here for @Danny I'm developing voice agent using VAPI.But I have some problems, so I hope you help me to find solution. As far as I known that, we can use javascript code in json structure using code property when creating custom tools on dashboard of vapi.ai But i don't know where do i have to write that property. Please let me know the solution. I hope your kindly help. Best Regards!!!
v
Vapi custom tools do not support a "code" property for embedding JavaScript directly in the JSON structure. Instead, you should define your custom logic on your own server and reference it in the "server" property of your tool configuration. For example:
Copy code
json
{
  "type": "function",
  "function": {
    "name": "my_custom_logic",
    "description": "Runs custom JavaScript on my backend"
  },
  "server": {
    "url": "https://your-backend.com/handle-tool"
  }
}
Write your JavaScript code on your backend, not in the Vapi dashboard JSON. [See the official guide for details.](https://docs.vapi.ai/tools/custom-tools) Source: - [Custom Tools Documentation](https://docs.vapi.ai/tools/custom-tools)
k
You can use JavaScript in the code property when creating a custom tool by adding it inside the function object of the tool’s JSON config on the dashboard, like "code": "return { result: \\Hello, ${inputs.name}\` }"\`.
e
@Danny
v
Vapi does not support embedding JavaScript code directly in the JSON structure using a "code" property. Instead, write your JavaScript logic on your own backend server and reference it in the "server" property of your custom tool configuration. For example:
Copy code
json
{
  "type": "function",
  "function": {
    "name": "my_custom_logic",
    "description": "Runs custom JavaScript on my backend"
  },
  "server": {
    "url": "https://your-backend.com/handle-tool"
  }
}
Write your code on your backend, not in the Vapi dashboard JSON. [See the official guide for details.](https://docs.vapi.ai/tools/custom-tools) Source: - [Custom Tools Documentation](https://docs.vapi.ai/tools/custom-tools)
k
@danny_86713, a gentle reminder to continue this thread.