> ## Documentation Index
> Fetch the complete documentation index at: https://docs.vapi.ai/llms.txt
> Use this file to discover all available pages before exploring further.

# Outbound Sales Example 📞

> Let's build an outbound sales agent that can schedule appointments.

We want this agent to be able to call a list of leads and schedule appointments. We'll create our assistant, create a phone number for it, then we'll configure our server for function calling to book the appointments.

<Steps>
  <Step title="Create an assistant">
    We'll start by taking a look at the [Assistant API
    reference](/api-reference/assistants/create-assistant) and define our
    assistant:

    ```json
    {
      "transcriber":{
        "provider": "deepgram",
        "keywords": ["Bicky:1"]
      },
      "model": {
        "provider": "openai",
        "model": "gpt-4",
        "messages": [
          {
              "role": "system",
              "content": "You're a sales agent for a Bicky Realty. You're calling a list of leads to schedule appointments to show them houses..."
          }
        ],
        "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."
                }
              }
            }
          }
        ]
      },
      "voice": {
        "provider": "openai",
        "voiceId": "onyx"
      },
      "forwardingPhoneNumber": "+16054440129",
      "voicemailMessage": "Hi, this is Jennifer from Bicky Realty. We were just calling to let you know...",
      "firstMessage": "Hi, this Jennifer from Bicky Realty. We're calling to schedule an appointment to show you a house. When would be a good time for you?",
      "endCallMessage": "Thanks for your time.",
      "endCallFunctionEnabled": true,
      "recordingEnabled": false,
    }
    ```

    Let's break this down:

    * `transcriber` - We're defining this to make sure the transcriber picks up the custom word "Bicky"
    * `model` - We're using the OpenAI GPT-4 model, which is better at function calling.
    * `messages` - We're defining the assistant's instructions for how to run the call.
    * `functions` - We're providing a bookAppointment function with a datetime parameter. The assistant can call this during the conversation to book the appointment.
    * `voice` - We're using the Onyx voice from OpenAI.
    * `forwardingPhoneNumber` - Since we've added this, the assistant will be provided the [transferCall](/assistants#transfer-call) function to use.
    * `voicemailMessage` - If the call goes to voicemail, this message will be played.
    * `firstMessage` - This is the first message the assistant will say when the user picks up.
    * `endCallMessage` - This is the message the assistant will deciding to hang up.
    * `endCallFunctionEnabled` - This will give the assistant the [endCall](/assistants#end-call) function.
    * `recordingEnabled` - We've disabled recording, since we don't have the user's consent to record the call.

    We'll then make a POST request to the [Create Assistant](/api-reference/assistants/create-assistant) endpoint to create the assistant.
  </Step>

  <Step title="Buy a phone number">
    We'll buy a phone number for outbound calls using the [Phone Numbers API](/phone-calling#set-up-a-phone-number).

    ```json
    {
      "id": "c86b5177-5cd8-447f-9013-99e307a8a7bb",
      "orgId": "aa4c36ba-db21-4ce0-9c6e-99e307a8a7bb",
      "number": "+11234567890",
      "createdAt": "2023-09-29T21:44:37.946Z",
      "updatedAt": "2023-12-08T00:57:24.706Z",
    }
    ```

    Great, let's take note of that `id` field- we'll need it later.
  </Step>

  <Step title="Configure your Server URL">
    When the assistant calls that `bookAppointment` function, we'll want to handle that function call and actually book the appointment. We also want to let the user know if booking the appointment was unsuccessful.

    First, we'll create an endpoint on our server for Vapi to hit. It'll receive messages as shown in the [Function Calling](/server-url#function-calling) docs. Once created, we'll add that endpoint URL to the **Server URL** field in the Account page on the [Vapi Dashboard](https://dashboard.vapi.ai).
  </Step>

  <Step title="Handle function calls">
    So now, when the assistant decides to call `bookAppointment`, our server will get something like this:

    ```json
    {
      "message": {
        "type": "function-call",
        "call": { Call Object },
        "functionCall": {
          "name": "bookAppointment",
          "parameters": "{ \"datetime\": \"2023-09-29T21:44:37.946Z\"}"
        }
      }
    }
    ```

    We'll do our own logic to book the appointment, then we'll respond to the request with the result to let the assistant know it was booked:

    ```json
    { "result": "The appointment was booked successfully." }
    ```

    or, if it failed:

    ```json
    { "result": "The appointment time is unavailable, please try another time." }
    ```

    So, when the assistant calls this function, these results will be appended to the conversation, and the assistant will respond to the user knowing the result.

    Great, now we're ready to start calling leads!
  </Step>

  <Step title="Place a call">
    We'll use the [Create Phone Call](/api-reference/calls/create-phone-call) endpoint to place a call to a lead:

    ```json
    {
      "phoneNumberId": "c86b5177-5cd8-447f-9013-99e307a8a7bb",
      "assistantId": "d87b5177-5cd8-447f-9013-99e307a8a7bb",
      "customer": {
        "number": "+11234567890"
      }
    }
    ```

    Since we also defined a `forwardingPhoneNumber`, when the user asks to speak to a human, the assistant will transfer the call to that number automatically.

    We can then check the [Dashboard](https://dashboard.vapi.ai) to see the call logs and read the transcripts.
  </Step>
</Steps>
