Store information in assistant.
# support
a
Is there a mechanism to store additional information in an assistant created on the fly? Information that I could retrieve when receiving a message such as "end-of-call report"? Right now I guess I can use the name of the assistant to store this additional data but it's not very convenient. Thank you!
v
@AdeB Yes, VAPI provides a feature called "session attributes" or "contextual data" that allows you to store and retrieve additional information during the lifecycle of an assistant session. This data can be used to maintain the state or context between different interactions within the same session. When you create an assistant on the fly, you can include this additional information as part of the session attributes. Later, when you receive a message or need to generate an "end-of-call report," you can access these attributes to retrieve the stored information. This mechanism is more convenient and structured than using the name of the assistant to store data, as it allows for multiple pieces of information to be stored and accessed in an organized manner. If you need more specific instructions on how to implement this in your VAPI setup, please let me know, and I can provide further assistance or direct you to support for more detailed information.
You can continue this conversation by mentioning me in the message.
a
yes, give me more implementation details please
@Vapi
should I use something like
"assistantOverrides": {"metadata": {
?
@Vapi
v
@AdeB Yes, using
assistantOverrides
with
metadata
is indeed the correct approach to store additional information for an assistant session in VAPI. The
metadata
field allows you to include any extra data you want to associate with the session, which can be retrieved later. Here's a general example of how you might structure your payload when creating an assistant on the fly:
Copy code
json
{
  "assistantOverrides": {
    "metadata": {
      "key1": "value1",
      "key2": "value2",
      // ... additional key-value pairs as needed
    }
  }
  // ... other necessary fields for creating the assistant
}
When you need to access this information, for instance, to generate an "end-of-call report," you can retrieve the metadata from the session attributes. The exact method to do this will depend on the specific VAPI implementation and the programming language you are using. If you require further assistance with the implementation or have any more questions, feel free to ask!
a
> When you need to access this information, for instance, to generate an "end-of-call report," you can retrieve the metadata from the session attributes. The exact method to do this will depend on the specific VAPI implementation and the programming language you are using. please show me in python @Vapi
v
@AdeB Certainly! In Python, you would typically handle the retrieval of metadata from a session within a webhook endpoint that VAPI communicates with. When VAPI sends a request to your server, it will include the session data, from which you can extract the metadata. Here's a simple example using Flask, a popular web framework in Python:
Copy code
python
from flask import Flask, request, jsonify

app = Flask(__name__)

@app.route('/webhook', methods=['POST'])
def webhook():
    # Parse the incoming JSON data
    incoming_data = request.json
    
    # Access the metadata from the session
    metadata = incoming_data.get('metadata', {})
    
    # Here you can use the metadata to generate an "end-of-call report"
    # For example, let's just print the metadata
    print("Received metadata:", metadata)
    
    # You would then perform any necessary actions based on the metadata
    # and return a response to VAPI if required
    
    return jsonify(success=True)

if __name__ == '__main__':
    app.run(debug=True)
In this example, when VAPI sends a POST request to the
/webhook
endpoint, the Flask app parses the JSON data, extracts the
metadata
object, and prints it out. You can then use this metadata to perform any logic needed for your "end-of-call report." Make sure to replace the
print
statement with your actual logic for handling the metadata and generating the report. Remember to secure your webhook endpoint and validate incoming requests to ensure they are coming from VAPI.
a
mark as solved
2 Views