Additional Capabilities for Your Voicebots Using Call Functions

Additional Capabilities for Your Voicebots Using Call Functions

Vapi goes far beyond just the creation of voicebots via our dashboard and API. In this post, we’re discussing additional functions we provide to developers as you create and implement voice assistants on our platform. 

We’ve enabled three functions for our voice assistants: transferCall, endCall, and dialKeypad, as well as custom functions. Let’s take a closer look.

Note: You do not need to add these functions to your model’s functions array.

transferCall Function

This function is useful for any number of support and secretarial applications. Here’s how it works. 

When a forwardingPhoneNumber is present on an assistant, the assistant will be given a transferCall function. This function can be used to transfer the call to the forwardingPhoneNumber.


{
  "model": {
    "provider": "openai",
    "model": "gpt-3.5-turbo",
    "messages": [
      {
        "role": "system",
        "content": "You are an assistant at a law firm. When the user asks to be transferred, use the transferCall function."
      }
    ]
  },
  "forwardingPhoneNumber": "+16054440129"
}

End Call

This function can be used in any scenarios where the caller is acting in an inappropriate manner. It’s provided when endCallFunctionEnabled is enabled on the assistant. The assistant can then use this function to end the call.


{
  "model": {
    "provider": "openai",
    "model": "gpt-3.5-turbo",
    "messages": [
      {
        "role": "system",
        "content": "You are an assistant at a law firm. If the user is being mean, use the endCall function."
      }
    ]
  },
  "endCallFunctionEnabled": true
}

Dial Keypad

This function allows the assistant to enter digits after hitting a menu. Simply enable dialKeypadFunctionEnabled on the assistant, and it will be able to enter digits on the keypad.

{
  "model": {
    "provider": "openai",
    "model": "gpt-3.5-turbo",
    "messages": [
      {
        "role": "system",
        "content": "You are an assistant at a law firm. When you hit a menu, use the dialKeypad function to enter the digits."
      }
    ]
  },
  "dialKeypadFunctionEnabled": true
}

Custom Functions

In addition to the above three predefined functions, you can also define your own custom functions. These are similar to OpenAI’s, and the LLM of your choice will trigger these custom functions as needed based on your instructions.

The functions array in the assistant definition allows you to define custom functions that the assistant can call during a conversation. Each function is an object with the following properties:

  • name: The name of the function. It must be a string containing a-z, A-Z, 0-9, underscores, or dashes, with a maximum length of 64.
  • description: A brief description of what the function does. This is used by the AI to decide when and how to call the function.
  • parameters: An object that describes the parameters the function accepts. The type property should be “object”, and the properties property should be an object where each key is a parameter name and each value is an object describing the type and purpose of the parameter.

In this example, the bookAppointment function accepts one parameter, datetime, which is a string representing the date and time of the appointment in ISO format.

{
  "functions": [
    {
      "name": "bookAppointment",
      "description": "Used to book the appointment.",
      "parameters": {
        "type": "object",
        "properties": {
          "datetime": {
            "type": "string",
            "description": "The date and time of the appointment in ISO format."
          }
        }
      }
    }
  ]
}

ServerURL and Custom Functions

In addition to defining custom functions, you can specify a serverUrl where Vapi will send the function call information. This URL can be configured at the account level or at the assistant level. At the account level, the serverURL is set in the Vapi Dashboard. All assistants under the account will use this URL by default for function calls. At the assistant level, the serverURL can be specified in the assistant configuration when creating or updating an assistant. This allows different assistants to use different URLs for function calls. If a serverUrl is specified at the assistant level, it will override the account-level serverURL.

If the serverURL is not defined either at the account level or the assistant level, the function call will simply be added to the chat history. This can be particularly useful when you want a function call to trigger an action on the frontend.

For example, the frontend can listen for specific function calls in the chat history and respond by updating the user interface or performing other actions. This allows for a dynamic and interactive user experience, where the frontend can react to changes in the conversation in real time.

To try our predefined functions, or define your own custom functions, visit the Vapi API and see what you can build. 

Read more