|
| 1 | +# vCon Library API Guide |
| 2 | + |
| 3 | +## Table of Contents |
| 4 | +1. [Core Classes](#core-classes) |
| 5 | +2. [Creating and Managing vCons](#creating-and-managing-vcons) |
| 6 | +3. [Working with Parties](#working-with-parties) |
| 7 | +4. [Managing Dialog](#managing-dialog) |
| 8 | +5. [Attachments and Analysis](#attachments-and-analysis) |
| 9 | +6. [Security and Validation](#security-and-validation) |
| 10 | + |
| 11 | +## Core Classes |
| 12 | + |
| 13 | +### Vcon |
| 14 | +The main class for creating and managing virtual conversation containers. |
| 15 | + |
| 16 | +```python |
| 17 | +from vcon import Vcon |
| 18 | +``` |
| 19 | + |
| 20 | +#### Initialization |
| 21 | +- `Vcon(vcon_dict={})`: Initialize from a dictionary |
| 22 | +- `Vcon.build_new()`: Create a new vCon with default values |
| 23 | +- `Vcon.build_from_json(json_string)`: Create from JSON string |
| 24 | + |
| 25 | +#### Properties |
| 26 | +- `uuid`: Unique identifier |
| 27 | +- `vcon`: Version number |
| 28 | +- `created_at`: Creation timestamp |
| 29 | +- `updated_at`: Last update timestamp |
| 30 | +- `parties`: List of participants |
| 31 | +- `dialog`: List of dialog entries |
| 32 | +- `attachments`: List of attachments |
| 33 | +- `analysis`: List of analysis entries |
| 34 | +- `redacted`: Redaction information |
| 35 | +- `group`: Group information |
| 36 | +- `meta`: Metadata |
| 37 | +- `tags`: Tags attachment |
| 38 | + |
| 39 | +### Party |
| 40 | +Represents a participant in the conversation. |
| 41 | + |
| 42 | +```python |
| 43 | +from vcon.party import Party |
| 44 | +``` |
| 45 | + |
| 46 | +#### Initialization Parameters |
| 47 | +- `tel`: Telephone number |
| 48 | +- `stir`: STIR verification |
| 49 | +- `mailto`: Email address |
| 50 | +- `name`: Party name |
| 51 | +- `validation`: Validation status |
| 52 | +- `gmlpos`: Geographic position |
| 53 | +- `civicaddress`: Civic address |
| 54 | +- `uuid`: Unique identifier |
| 55 | +- `role`: Party role |
| 56 | +- `contact_list`: Contact list |
| 57 | +- `meta`: Additional metadata |
| 58 | + |
| 59 | +### Dialog |
| 60 | +Represents a conversation entry. |
| 61 | + |
| 62 | +```python |
| 63 | +from vcon.dialog import Dialog |
| 64 | +``` |
| 65 | + |
| 66 | +#### Supported MIME Types |
| 67 | +- `text/plain` |
| 68 | +- `audio/x-wav`, `audio/wav`, `audio/wave` |
| 69 | +- `audio/mpeg`, `audio/mp3` |
| 70 | +- `audio/ogg` |
| 71 | +- `audio/webm` |
| 72 | +- `audio/x-m4a` |
| 73 | +- `audio/aac` |
| 74 | +- `video/x-mp4` |
| 75 | +- `video/ogg` |
| 76 | +- `multipart/mixed` |
| 77 | + |
| 78 | +## Creating and Managing vCons |
| 79 | + |
| 80 | +### Creating a New vCon |
| 81 | +```python |
| 82 | +# Create empty vCon |
| 83 | +vcon = Vcon.build_new() |
| 84 | + |
| 85 | +# Create from dictionary |
| 86 | +vcon = Vcon({"uuid": "...", "vcon": "0.0.1"}) |
| 87 | + |
| 88 | +# Create from JSON |
| 89 | +vcon = Vcon.build_from_json(json_string) |
| 90 | +``` |
| 91 | + |
| 92 | +### Serialization |
| 93 | +```python |
| 94 | +# To JSON string |
| 95 | +json_str = vcon.to_json() |
| 96 | +# or |
| 97 | +json_str = vcon.dumps() |
| 98 | + |
| 99 | +# To dictionary |
| 100 | +dict_data = vcon.to_dict() |
| 101 | +``` |
| 102 | + |
| 103 | +### Tags |
| 104 | +```python |
| 105 | +# Add a tag |
| 106 | +vcon.add_tag("category", "support") |
| 107 | + |
| 108 | +# Get a tag value |
| 109 | +value = vcon.get_tag("category") |
| 110 | + |
| 111 | +# Get all tags |
| 112 | +tags = vcon.tags |
| 113 | +``` |
| 114 | + |
| 115 | +## Working with Parties |
| 116 | + |
| 117 | +### Adding Parties |
| 118 | +```python |
| 119 | +# Create and add a party |
| 120 | +party = Party( |
| 121 | + tel="+1234567890", |
| 122 | + name="John Doe", |
| 123 | + role="customer" |
| 124 | +) |
| 125 | +vcon.add_party(party) |
| 126 | +``` |
| 127 | + |
| 128 | +### Finding Parties |
| 129 | +```python |
| 130 | +# Find party index by attribute |
| 131 | +index = vcon.find_party_index("tel", "+1234567890") |
| 132 | +``` |
| 133 | + |
| 134 | +## Managing Dialog |
| 135 | + |
| 136 | +### Adding Dialog Entries |
| 137 | +```python |
| 138 | +# Add a text dialog |
| 139 | +dialog = Dialog( |
| 140 | + type="text", |
| 141 | + start="2024-03-21T10:00:00Z", |
| 142 | + parties=[0, 1], |
| 143 | + mimetype="text/plain", |
| 144 | + body="Hello, how can I help?" |
| 145 | +) |
| 146 | +vcon.add_dialog(dialog) |
| 147 | +``` |
| 148 | + |
| 149 | +### Working with Media |
| 150 | +```python |
| 151 | +# Add inline data |
| 152 | +dialog.add_inline_data( |
| 153 | + body="base64_encoded_content", |
| 154 | + filename="recording.wav", |
| 155 | + mimetype="audio/wav" |
| 156 | +) |
| 157 | + |
| 158 | +# Check data type |
| 159 | +is_external = dialog.is_external_data() |
| 160 | +is_inline = dialog.is_inline_data() |
| 161 | +``` |
| 162 | + |
| 163 | +## Attachments and Analysis |
| 164 | + |
| 165 | +### Attachments |
| 166 | +```python |
| 167 | +# Add an attachment |
| 168 | +vcon.add_attachment( |
| 169 | + type="document", |
| 170 | + body="content", |
| 171 | + encoding="none" |
| 172 | +) |
| 173 | + |
| 174 | +# Find attachment |
| 175 | +attachment = vcon.find_attachment_by_type("document") |
| 176 | +``` |
| 177 | + |
| 178 | +### Analysis |
| 179 | +```python |
| 180 | +# Add analysis |
| 181 | +vcon.add_analysis( |
| 182 | + type="sentiment", |
| 183 | + dialog=[0], |
| 184 | + vendor="analyzer", |
| 185 | + body={"score": 0.8}, |
| 186 | + encoding="json" |
| 187 | +) |
| 188 | + |
| 189 | +# Find analysis |
| 190 | +analysis = vcon.find_analysis_by_type("sentiment") |
| 191 | +``` |
| 192 | + |
| 193 | +## Security and Validation |
| 194 | + |
| 195 | +### Signing and Verification |
| 196 | +```python |
| 197 | +# Generate key pair |
| 198 | +private_key, public_key = Vcon.generate_key_pair() |
| 199 | + |
| 200 | +# Sign vCon |
| 201 | +vcon.sign(private_key) |
| 202 | + |
| 203 | +# Verify signature |
| 204 | +is_valid = vcon.verify(public_key) |
| 205 | +``` |
| 206 | + |
| 207 | +### Validation |
| 208 | +```python |
| 209 | +# Validate vCon object |
| 210 | +is_valid, errors = vcon.is_valid() |
| 211 | + |
| 212 | +# Validate JSON file |
| 213 | +is_valid, errors = Vcon.validate_file("conversation.json") |
| 214 | + |
| 215 | +# Validate JSON string |
| 216 | +is_valid, errors = Vcon.validate_json(json_string) |
| 217 | +``` |
| 218 | + |
| 219 | +### UUID Generation |
| 220 | +```python |
| 221 | +# Generate UUID8 from domain name |
| 222 | +uuid = Vcon.uuid8_domain_name("example.com") |
| 223 | + |
| 224 | +# Generate UUID8 with custom bits |
| 225 | +uuid = Vcon.uuid8_time(custom_bits) |
| 226 | +``` |
0 commit comments