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:

{
  "transcriber":{
    "provider": "deepgram",
    "keywords": ["iPhone:1", "MacBook:1.5", "iPad:1", "iMac:0.8", "Watch:1", "TV:1", "Apple:2"],
  },
  "model": {
    "provider": "openai",
    "model": "gpt-4",
    "messages": [
      {
          "role": "system",
          "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: ..."
      }
    ]
  },
  "forwardingPhoneNumber": "+16054440129",
  "firstMessage": "Hey, I'm an A.I. assistant for Apple. I can help you troubleshoot your Apple device. What's the issue?",
  "recordingEnabled": true,
}

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.

{
  "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",
}
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:

{
    "message": {
        "type": "end-of-call-report",
        "endedReason": "hangup",
        "call": { Call Object },
        "recordingUrl": "https://vapi-public.s3.amazonaws.com/recordings/1234.wav",
        "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.",
        "transcript": "Hey, I'm an A.I. assistant for Apple...",
        "messages":[
        {
            "role": "assistant",
            "message": "Hey, I'm an A.I. assistant for Apple. I can help you troubleshoot your Apple device. What's the issue?",
        },
        {
            "role": "user",
            "message": "Yeah I'm having an issue with my iPhone restarting randomly.",
        },
        ...
        ]
    }
}

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:

{
    "message": {
        "type": "assistant-request",
        "call": { Call Object },
    }
}

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:

{
    "assistant": {
        ...
        "model": {
            "provider": "openai",
            "model": "gpt-4",
            "messages": [
              {
                "role": "system",
                "content": "You're a technical support assistant. Here's where we left off: ..."
              }
            ]
        },
        ...
    }
}

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.