| title | Outbound Sales Example 📞 |
|---|---|
| subtitle | Let's build an outbound sales agent that can schedule appointments. |
| slug | examples/outbound-sales |
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.
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..."
}
],
"tools": [
{
"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."
}
}
}
}
{
"type": "transferCall",
"destinations": [
{
"type": "number",
"number": "+16054440129",
"message": "I am forwarding your call. Please stay on the line."
}
]
}
]
},
"voice": {
"provider": "openai",
"voiceId": "onyx"
},
"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.
- `bookAppointment` in `model.tools` - We're providing a bookAppointment function with a datetime parameter. The assistant can call this during the conversation to book the appointment.
- `transferCall` in `model.tools` - Since we've added this, the assistant will be provided the [transferCall](/assistants#transfer-call) function to use.
- `voice` - We're using the Onyx voice from OpenAI.
- `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.
```json
{
"id": "c86b5177-5cd8-447f-9013-99e307a8a7bb",
"orgId": "aa4c36ba-db21-4ce0-9c6e-99e307a8a7bb",
"provider": "vapi",
"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.
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).
```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>
```json
{
"phoneNumberId": "c86b5177-5cd8-447f-9013-99e307a8a7bb",
"assistantId": "d87b5177-5cd8-447f-9013-99e307a8a7bb",
"customer": {
"number": "+11234567890"
}
}
```
Since we also defined a `transferCall` tool, 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.