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.

1

Create an assistant

We’ll start by taking a look at the Assistant API reference and define our assistant:

1{
2 "transcriber":{
3 "provider": "deepgram",
4 "keywords": ["Bicky:1"]
5 },
6 "model": {
7 "provider": "openai",
8 "model": "gpt-4",
9 "messages": [
10 {
11 "role": "system",
12 "content": "You're a sales agent for a Bicky Realty. You're calling a list of leads to schedule appointments to show them houses..."
13 }
14 ],
15 "functions": [
16 {
17 "name": "bookAppointment",
18 "description": "Used to book the appointment.",
19 "parameters": {
20 "type": "object",
21 "properties": {
22 "datetime": {
23 "type": "string",
24 "description": "The date and time of the appointment in ISO format."
25 }
26 }
27 }
28 }
29 ]
30 },
31 "voice": {
32 "provider": "openai",
33 "voiceId": "onyx"
34 },
35 "forwardingPhoneNumber": "+16054440129",
36 "voicemailMessage": "Hi, this is Jennifer from Bicky Realty. We were just calling to let you know...",
37 "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?",
38 "endCallMessage": "Thanks for your time.",
39 "endCallFunctionEnabled": true,
40 "recordingEnabled": false,
41}

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.

2

Buy a phone number

We’ll buy a phone number for outbound calls using the Phone Numbers API.

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

Great, let’s take note of that id field- we’ll need it later.

3

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.

4

Handle function calls

So now, when the assistant decides to call bookAppointment, our server will get something like this:

1{
2 "message": {
3 "type": "function-call",
4 "call": { Call Object },
5 "functionCall": {
6 "name": "bookAppointment",
7 "parameters": "{ \"datetime\": \"2023-09-29T21:44:37.946Z\"}"
8 }
9 }
10}

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:

1{ "result": "The appointment was booked successfully." }

or, if it failed:

1{ "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!

5

Place a call

We’ll use the Create Phone Call endpoint to place a call to a lead:

1{
2 "phoneNumberId": "c86b5177-5cd8-447f-9013-99e307a8a7bb",
3 "assistantId": "d87b5177-5cd8-447f-9013-99e307a8a7bb",
4 "customer": {
5 "number": "+11234567890"
6 }
7}

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.