🐰Quickstart
Build a vCon in TypeScript with parties, dialog, analysis, a lawful basis attachment, and tags, then serialize it.
This is the TypeScript counterpart to the Python Quickstart. Both libraries write the same JSON structure. Field rules are in the field reference.
Install
npm install vcon-jsvcon-js 0.5.2 targets draft-ietf-vcon-vcon-core and sets vcon: "0.4.0" for you. It needs Node 18 or later.
Parties and a text dialog
addParty returns nothing. A party's index is its position in parties.
import { Vcon, Party, Dialog } from 'vcon-js';
const vcon = Vcon.buildNew();
vcon.subject = 'Customer Support Chat';
vcon.addParty(new Party({ tel: '+15551234567', name: 'Alice', role: 'customer' }));
vcon.addParty(new Party({ mailto: 'bob@example.com', name: 'Bob', role: 'agent' }));
const customer = vcon.findPartyIndex('name', 'Alice'); // 0
const agent = vcon.parties.length - 1; // 1
const chat = new Dialog({
type: 'text',
start: new Date().toISOString(),
parties: [0, 1],
originator: 0,
});
chat.addInlineData('Hi, I need help with my account.', 'text/plain', { encoding: 'none' });
vcon.addDialog(chat);addInlineData(body, mediatype, { encoding, filename }) sets the body and clears any url. encoding defaults to 'none'. Valid encodings are 'base64url', 'json', and 'none' (Attachment.VALID_ENCODINGS).
Recording with external media
Keep audio and video out of the JSON. Reference it with url and a content_hash of the form sha512-<base64url>. addExternalData(url, mediatype, { filename, content_hash }) sets all three and clears any inline body.
Dialog also has isText(), isRecording(), isAudio(), isVideo(), isEmail(), isInlineData(), and isExternalData().
Analysis
Pass an object or array as body. addAnalysis serializes it to a string and sets encoding: 'json'. Always set vendor. This example is a WTF transcription; see WTF Transcription and draft-howe-vcon-wtf-extension.
Lawful basis
The lawful basis extension is an attachment with purpose: 'lawful_basis' and a JSON body, defined in draft-howe-vcon-lawful-basis. The body carries lawful_basis, expiration (an RFC 3339 time or null), and purpose_grants, each with purpose, granted, and granted_at. proof_mechanisms is optional, each entry with proof_type, timestamp, and proof_data. The values below are an illustration, not a real consent record. Declare the extension with addExtension.
Attachment bodies are stored as you pass them, so an object stays an object. Always pass start: the core schema requires it and the library does not fill it in for you (only addTag does). party and dialog default to 0.
Tags
Tags are stored as one purpose: 'tags' attachment. The conserver and the vCon MCP server read them for filtering.
Serialize and load
Common mistakes
Using
appendedinstead ofamended, ormust_supportinstead ofcritical. UseaddCriticalExtension()forcritical.Putting transcripts in
attachments[]. Transcripts belong inanalysis[].Writing
type: 'lawful_basis'on an attachment. Attachments usepurpose, nottype.Omitting
vendoron an analysis.Omitting
starton an attachment you add withaddAttachment.Reading the return value of
addPartyas an index. It returnsvoid.
See also
Last updated
Was this helpful?