custom function
# support
p
I simply don't understand what my custom function is supposed to look like, I've created an endpoint that should process the result of the "City Information: "City Name" post query where the city name is determined by the bot upstream, how do I create this custom function?
v
Hi @plee4722, I'm an AI assistant for Vapi. I'll analyze available sources and get back to your shortly.
----------------------------- **While I generate an answer, here are some sources that might be helpful**: * [Custom LLM]() * [Create Assistant]() * [Outbound Sales Example]() * [Function Calling]() -----------------------------
### Answer To create a custom function in Vapi that processes the result of a "City Information: 'City Name'" post query, you'll have to define a function in your assistant's configuration. This involves specifying the function name, its parameters, and incorporating your endpoint that handles the city information retrieval. Here's an example of how you could structure your custom function:
Copy code
json
{
  "functions": [
    {
      "name": "getCityInfo",
      "description": "Fetches information for a given city.",
      "parameters": {
        "type": "object",
        "properties": {
          "cityName": {
            "type": "string",
            "description": "The name of the city to fetch information for."
          }
        }
      }
    }
  ]
}
[(1)]() You'd also need to ensure your server can handle function calls from Vapi. For this, you have to set up an endpoint that matches the specifications described in the Vapi documentation for function calling. When Vapi triggers the
getCityInfo
function during a conversation, it will send a
POST
request to your server with the specified parameters, in this case, the
cityName
. Your server should process this request, retrieve the city information, and then respond with the result in a format that Vapi can incorporate back into the conversation flow. Here's an example of what the request from Vapi to your server might look like:
Copy code
json
{
  "message": {
    "type": "function-call",
    "call": { /* Call Object */ },
    "functionCall": {
      "name": "getCityInfo",
      "parameters": "{ \"cityName\": \"New York\"}"
    }
  }
}
[(2)]() And your server's response should provide the city information result:
Copy code
json
{ "result": "New York is known for its vibrant arts scene and towering skyscrapers." }
This result will be incorporated into the conversation flow, allowing your assistant to dynamically provide information based on the user's input. Make sure your server endpoint is properly configured to receive and respond to these requests. If your assistant's
serverUrl
is set, Vapi will send function call information to that URL. Remember that custom functions give you the flexibility to extend the capabilities of your assistant, enabling dynamic interactions based on your business logic and external data sources.
Got it. Tagging @User for additional help.
s
Please check community tutorials https://docs.vapi.ai/community/videos