mateuscdantas
# vapigpt
m
@Vapi how do I insert previous context before initiating a call with VAPI?
v
@mateuscdantas To insert previous context before initiating a call with VAPI, you can include this context as custom data within the call setup request. This can be done by using the
metadata
attribute, which allows you to attach key-value pairs that can be passed along with the call. Here's how you can do it: 1. Prepare your call setup request JSON object. 2. Include a
metadata
field in your request. 3. Add the context as key-value pairs within the
metadata
object. For example:
Copy code
json
{
  "to": [
    {
      "type": "phone",
      "number": "1234567890"
    }
  ],
  "from": {
    "type": "phone",
    "number": "0987654321"
  },
  "metadata": {
    "previousConversationId": "abc123",
    "customerSupportTicket": "ticket456"
  }
}
In this example,
previousConversationId
and
customerSupportTicket
are custom keys that hold the context you want to pass along with the call. When the call is initiated, VAPI will carry this metadata, and it can be accessed by your application during the call for reference or to maintain continuity in the conversation. If you need to initiate a call with this context, please provide the necessary details such as the destination number, caller number, and any additional context you wish to include, and I can assist you further.
m
if i add the previousConversationId, will VAPI pull data from that specific conversation as context?
@Vapi if i add the previousConversationId, will VAPI pull data from that specific conversation as context?
v
@mateuscdantas VAPI itself does not automatically pull data from previous conversations. The
previousConversationId
in the metadata is a custom field that you can use to reference past interactions. However, it's up to your application's logic to retrieve and utilize the associated data. When you include
previousConversationId
in the metadata, you should have a mechanism on your server that can recognize this ID and fetch the relevant conversation data. This data can then be used to provide context during the call, such as by informing the agent or guiding the flow of the conversation. If you need to retrieve data based on the
previousConversationId
, you would typically do so from your own databases or storage systems where previous conversations are recorded. If you have any specific functionalities or integrations in mind that you would like to implement using VAPI, please let me know, and I can provide more detailed guidance.
m
@Vapi got it, so if I have saved the context from the previous calls, how do I insert this context before the call starts?
v
@mateuscdantas To insert the saved context from previous calls before a new call starts, you would typically follow these steps: 1. **Retrieve Context**: When a new call is about to be initiated, your system should first retrieve the saved context associated with the
previousConversationId
from your database or storage system. 2. **Prepare Call Setup Request**: Create a call setup request object for VAPI. This object includes details about the call, such as the destination and caller numbers. 3. **Include Context in Metadata**: Add a
metadata
field to the call setup request and include the retrieved context as key-value pairs within this field. This allows you to pass custom data along with the call. 4. **Initiate the Call**: Send the call setup request to VAPI to initiate the call with the included context. Here's an example of how you might structure the call setup request with context included in the metadata:
Copy code
json
{
  "to": [
    {
      "type": "phone",
      "number": "1234567890"
    }
  ],
  "from": {
    "type": "phone",
    "number": "0987654321"
  },
  "metadata": {
    "previousConversationId": "abc123",
    "customerSupportTicket": "ticket456",
    "savedContext": {
      // Include the retrieved context here
      "lastIssueResolved": "Billing Inquiry",
      "customerSatisfaction": "Positive",
      // ... other context data
    }
  }
}
In this example,
savedContext
is a nested object within
metadata
that contains the actual context data from the previous conversation. This data will be attached to the call and can be accessed by your application or agents during the call to provide a seamless experience. If you're ready to initiate a call and need assistance with including the saved context, please provide the necessary details, and I can guide you through the process.
m
@Vapi but how will VAPI use this metadata property to add as context to the call?
v
@mateuscdantas VAPI itself does not inherently understand or use the
metadata
property to add context to the call. Instead, the
metadata
property is a mechanism for you, as the developer, to pass along custom data with the call setup request. It is then your responsibility to handle this data on your server and use it appropriately during the call. Here's how the process typically works: 1. **Attach Metadata**: You include the
metadata
property with relevant context data in the call setup request when initiating a call with VAPI. 2. **VAPI Passes Metadata**: When VAPI initiates the call, it simply passes along the
metadata
as part of the call data. VAPI does not interpret or act on this data itself. 3. **Your Server Receives Metadata**: Your server, which handles the call logic and interacts with VAPI, receives the
metadata
along with the call notification (usually via a webhook). 4. **Use Metadata in Call Logic**: Your server-side application is responsible for interpreting the
metadata
and using it to provide context during the call. This could involve: - Displaying the context data to a human agent. - Using the context to guide an IVR (Interactive Voice Response) system. - Making decisions in a voice bot's conversation flow based on the context. 5. **End-of-Call Actions**: After the call, your server can also use the
metadata
to log the call with the associated context, update records, or trigger post-call workflows. To summarize, VAPI treats the
metadata
as a "carrier" for whatever data you want to include with the call. It is up to your application to make use of this data to enhance the call experience. If you have any specific questions about implementing this on your server or how to structure your application logic to use the
metadata
, please let me know, and I can provide further assistance.
m
@Vapi ok, so once i get the metadata or the context on the server side, what is the best way to provide this context to VAPI so the agent can use to answer user questions? Adding through the system promp is there a better way?
6 Views