vcon-library
v0.1.0
Published
JavaScript library for creating and managing vCons (Virtual Conversations)
Maintainers
Readme
vcon-library
A JavaScript library for creating and managing vCons (Virtual Conversations).
Installation
npm install vcon-libraryUsage
Creating a new vCon
import { Vcon, Party, Dialog } from "vcon-library";
// 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();Loading from JSON
import { Vcon } from "vcon-library";
const jsonString = "..."; // Your vCon JSON string
const vcon = Vcon.buildFromJson(jsonString);Working with Attachments
import { Vcon, Attachment } from "vcon-library";
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");Working with Analysis
import { Vcon } from "vcon-library";
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");Working with Tags
import { Vcon } from "vcon-library";
const vcon = Vcon.buildNew();
// Add a tag
vcon.addTag("category", "support");
// Get a tag
const category = vcon.getTag("category");API Reference
Vcon
The main class for working with vCons.
Methods
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
Party
Class for representing parties in a vCon.
Properties
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
Dialog
Class for representing dialogs in a vCon.
Properties
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
Methods
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
Attachment
Class for representing attachments in a vCon.
Properties
type: string: Attachment typebody: any: Attachment contentencoding: Encoding: Content encoding
License
MIT
