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.
Create an assistant
We’ll start by taking a look at the Assistant API reference and define our assistant:
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 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 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 endpoint to create the assistant.
Buy a phone number
We’ll buy a phone number for outbound calls using the Phone Numbers API.
Great, let’s take note of that id
field- we’ll need it later.
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 docs. Once created, we’ll add that endpoint URL to the Server URL field in the Account page on the Vapi Dashboard.
Handle function calls
So now, when the assistant decides to call bookAppointment
, our server will get something like this:
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:
or, if it failed:
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!
Place a call
We’ll use the Create Phone Call endpoint to place a call to a lead:
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 to see the call logs and read the transcripts.
Was this page helpful?