- Core Classes
- Creating and Managing vCons
- Working with Parties
- Managing Dialog
- Attachments and Analysis
- Security and Validation
The main class for creating and managing virtual conversation containers.
from vcon import Vcon
Vcon(vcon_dict={})
: Initialize from a dictionaryVcon.build_new()
: Create a new vCon with default valuesVcon.build_from_json(json_string)
: Create from JSON string
uuid
: Unique identifiervcon
: Version numbercreated_at
: Creation timestampupdated_at
: Last update timestampparties
: List of participantsdialog
: List of dialog entriesattachments
: List of attachmentsanalysis
: List of analysis entriesredacted
: Redaction informationgroup
: Group informationmeta
: Metadatatags
: Tags attachment
Represents a participant in the conversation.
from vcon.party import Party
tel
: Telephone numberstir
: STIR verificationmailto
: Email addressname
: Party namevalidation
: Validation statusgmlpos
: Geographic positioncivicaddress
: Civic addressuuid
: Unique identifierrole
: Party rolecontact_list
: Contact listmeta
: Additional metadata
Represents a conversation entry.
from vcon.dialog import Dialog
text/plain
audio/x-wav
,audio/wav
,audio/wave
audio/mpeg
,audio/mp3
audio/ogg
audio/webm
audio/x-m4a
audio/aac
video/x-mp4
video/ogg
multipart/mixed
# Create empty vCon
vcon = Vcon.build_new()
# Create from dictionary
vcon = Vcon({"uuid": "...", "vcon": "0.0.1"})
# Create from JSON
vcon = Vcon.build_from_json(json_string)
# To JSON string
json_str = vcon.to_json()
# or
json_str = vcon.dumps()
# To dictionary
dict_data = vcon.to_dict()
# Add a tag
vcon.add_tag("category", "support")
# Get a tag value
value = vcon.get_tag("category")
# Get all tags
tags = vcon.tags
# Create and add a party
party = Party(
tel="+1234567890",
name="John Doe",
role="customer"
)
vcon.add_party(party)
# Find party index by attribute
index = vcon.find_party_index("tel", "+1234567890")
# Add a text dialog
dialog = Dialog(
type="text",
start="2024-03-21T10:00:00Z",
parties=[0, 1],
mimetype="text/plain",
body="Hello, how can I help?"
)
vcon.add_dialog(dialog)
# Add inline data
dialog.add_inline_data(
body="base64_encoded_content",
filename="recording.wav",
mimetype="audio/wav"
)
# Check data type
is_external = dialog.is_external_data()
is_inline = dialog.is_inline_data()
# Add an attachment
vcon.add_attachment(
type="document",
body="content",
encoding="none"
)
# Find attachment
attachment = vcon.find_attachment_by_type("document")
# Add analysis
vcon.add_analysis(
type="sentiment",
dialog=[0],
vendor="analyzer",
body={"score": 0.8},
encoding="json"
)
# Find analysis
analysis = vcon.find_analysis_by_type("sentiment")
# Generate key pair
private_key, public_key = Vcon.generate_key_pair()
# Sign vCon
vcon.sign(private_key)
# Verify signature
is_valid = vcon.verify(public_key)
# Validate vCon object
is_valid, errors = vcon.is_valid()
# Validate JSON file
is_valid, errors = Vcon.validate_file("conversation.json")
# Validate JSON string
is_valid, errors = Vcon.validate_json(json_string)
# Generate UUID8 from domain name
uuid = Vcon.uuid8_domain_name("example.com")
# Generate UUID8 with custom bits
uuid = Vcon.uuid8_time(custom_bits)