A JavaScript library for creating and managing vCons (Virtual Conversations).
npm install vcon-js
import { Vcon, Party, Dialog } from 'vcon-js';
// Create a new vCon
const vcon = Vcon.buildNew();
// Add parties
const party1 = new Party({
tel: '+1234567890',
name: 'John Doe'
});
const party2 = new Party({
tel: '+0987654321',
name: 'Jane Smith'
});
vcon.addParty(party1);
vcon.addParty(party2);
// Add a dialog
const dialog = new Dialog({
type: 'text/plain',
start: new Date(),
parties: [0, 1], // References to party indices
body: 'Hello, this is a conversation!',
mimetype: 'text/plain'
});
vcon.addDialog(dialog);
// Convert to JSON
const json = vcon.toJson();
import { Vcon } from 'vcon-js';
const jsonString = '...'; // Your vCon JSON string
const vcon = Vcon.buildFromJson(jsonString);
import { Vcon, Attachment } from 'vcon-js';
const vcon = Vcon.buildNew();
// Add an attachment
const attachment = vcon.addAttachment(
'application/pdf',
'base64EncodedContent',
'base64'
);
// Find an attachment by type
const pdfAttachment = vcon.findAttachmentByType('application/pdf');
import { Vcon } from 'vcon-js';
const vcon = Vcon.buildNew();
// Add analysis
vcon.addAnalysis({
type: 'sentiment',
dialog: 0, // Reference to dialog index
vendor: 'sentiment-analyzer',
body: {
score: 0.8,
label: 'positive'
}
});
// Find analysis by type
const sentimentAnalysis = vcon.findAnalysisByType('sentiment');
import { Vcon } from 'vcon-js';
const vcon = Vcon.buildNew();
// Add a tag
vcon.addTag('category', 'support');
// Get a tag
const category = vcon.getTag('category');
The main class for working with vCons.
static buildNew()
: Creates a new vConstatic buildFromJson(jsonString: string)
: Creates a vCon from JSONaddParty(party: Party)
: Adds a party to the vConaddDialog(dialog: Dialog)
: Adds a dialog to the vConaddAttachment(type: string, body: any, encoding?: Encoding)
: Adds an attachmentaddAnalysis(params: AnalysisParams)
: Adds analysis dataaddTag(tagName: string, tagValue: string)
: Adds a tagfindPartyIndex(by: string, val: string)
: Finds a party indexfindDialog(by: string, val: any)
: Finds a dialogfindAttachmentByType(type: string)
: Finds an attachment by typefindAnalysisByType(type: string)
: Finds analysis by typegetTag(tagName: string)
: Gets a tag valuetoJson()
: Converts the vCon to JSONtoDict()
: Converts the vCon to a dictionary
Class for representing parties in a vCon.
tel?: string
: Telephone numberstir?: string
: STIR identifiermailto?: string
: Email addressname?: string
: Display namevalidation?: string
: Validation informationgmlpos?: string
: GML positioncivicaddress?: CivicAddress
: Civic addressuuid?: string
: UUIDrole?: string
: Rolecontact_list?: string
: Contact listmeta?: Record<string, any>
: Additional metadata
Class for representing dialogs in a vCon.
type: string
: Dialog typestart: Date
: Start timeparties: number[]
: Party indicesoriginator?: number
: Originator party indexmimetype?: string
: MIME typefilename?: string
: Filenamebody?: string
: Dialog contentencoding?: string
: Content encodingurl?: string
: External URLsignature?: string
: Digital signatureduration?: number
: Duration in secondsmeta?: Record<string, any>
: Additional metadata
addExternalData(url: string, filename: string, mimetype: string)
: Adds external dataaddInlineData(body: string, filename: string, mimetype: string)
: Adds inline dataisExternalData()
: Checks if dialog has external dataisInlineData()
: Checks if dialog has inline dataisText()
: Checks if dialog is textisAudio()
: Checks if dialog is audioisVideo()
: Checks if dialog is videoisEmail()
: Checks if dialog is email
Class for representing attachments in a vCon.
type: string
: Attachment typebody: any
: Attachment contentencoding: Encoding
: Content encoding
MIT