Inbound Support Example ⚙️

Let’s build a technical support assistant that remembers where we left off.

We want a phone number we can call to get technical support. We want the assistant to use a provided set of troubleshooting guides to help walk the caller through solving their issue.

As a bonus, we also want the assistant to remember by the phone number of the caller where we left off if we get disconnected.

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": ["iPhone:1", "MacBook:1.5", "iPad:1", "iMac:0.8", "Watch:1", "TV:1", "Apple:2"],
5 },
6 "model": {
7 "provider": "openai",
8 "model": "gpt-4",
9 "messages": [
10 {
11 "role": "system",
12 "content": "You're a technical support assistant. You're helping a customer troubleshoot their Apple device. You can ask the customer questions, and you can use the following troubleshooting guides to help the customer solve their issue: ..."
13 }
14 ]
15 },
16 "forwardingPhoneNumber": "+16054440129",
17 "firstMessage": "Hey, I'm an A.I. assistant for Apple. I can help you troubleshoot your Apple device. What's the issue?",
18 "recordingEnabled": true,
19}
Let's break this down
  • transcriber - We’re defining this to make sure the transcriber picks up the custom words related to our devices.
  • model - We’re using the OpenAI GPT-3.5-turbo model. It’s much faster and preferred if we don’t need GPT-4.
  • messages - We’re defining the assistant’s instructions for how to run the call.
  • forwardingPhoneNumber - Since we’ve added this, the assistant will be provided the transferCall function to use if the caller asks to be transferred to a person.
  • firstMessage - This is the first message the assistant will say when the user picks up.
  • recordingEnabled - We’re recording the call so we can hear the conversation later.

Since we want the assistant to remember where we left off, its configuration is going to change based on the caller. So, we’re not going to use temporary assistants.

For this example, we’re going to store the conversation on our server between calls and use the Server URL’s assistant-request to fetch a new configuration based on the caller every time someone calls.

2

Buy a phone number

We’ll buy a phone number for inbound 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}
3

Configure your Server URL

When someone calls our number, we want to fetch the assistant configuration from our server. We’ll use the Server URL’s assistant-request to do this.

First, we’ll create an endpoint on our server for Vapi to hit. It’ll receive messages as shown in the Assistant Request docs. Once created, we’ll add that endpoint URL to the Server URL field in the Account page on the Vapi Dashboard.

4

Save the conversation at the end of the call

We’ll want to save the conversation at the end of the call for the next time they call. We’ll use the Server URL’s end-of-call-report message to do this.

At the end of each call, we’ll get a message like this:

1{
2 "message": {
3 "type": "end-of-call-report",
4 "endedReason": "hangup",
5 "call": { Call Object },
6 "recordingUrl": "https://vapi-public.s3.amazonaws.com/recordings/1234.wav",
7 "summary": "The user mentioned they were having an issue with their iPhone restarting randomly. They restarted their phone, but the issue persisted. They mentioned they were using an iPhone 12 Pro Max. They mentioned they were using iOS 15.",
8 "transcript": "Hey, I'm an A.I. assistant for Apple...",
9 "messages":[
10 {
11 "role": "assistant",
12 "message": "Hey, I'm an A.I. assistant for Apple. I can help you troubleshoot your Apple device. What's the issue?",
13 },
14 {
15 "role": "user",
16 "message": "Yeah I'm having an issue with my iPhone restarting randomly.",
17 },
18 ...
19 ]
20 }
21}

We’ll save the call.customer.number and summary fields to our database for the next time they call.

5

Handle assistant requests.

When our number receives a call, Vapi will also hit our server’s endpoint with a message like this:

1{
2 "message": {
3 "type": "assistant-request",
4 "call": { Call Object },
5 }
6}

We’ll check our database to see if we have a conversation for this caller. If we do, we’ll create an assistant configuration like in Step 1 and respond with it:

1{
2 "assistant": {
3 ...
4 "model": {
5 "provider": "openai",
6 "model": "gpt-4",
7 "messages": [
8 {
9 "role": "system",
10 "content": "You're a technical support assistant. Here's where we left off: ..."
11 }
12 ]
13 },
14 ...
15 }
16}

If we don’t, we’ll just respond with the assistant configuration from Step 1.

6

Try calling it!

We’ll call our number and see if it works. Give it a call, and tell it you’re having an issue with your iPhone restarting randomly.

Hang up, and call back. Then ask what the issue was. The assistant should remember where we left off.