function createContactTraceStream()

in Frontend/main.js [104:146]


function createContactTraceStream(contact, newcontact, agent){
    //Updates the contact passed to the stream
    //Log all 'contact-stage' attributes
    //Logs only the first time a given attribute or state is provided
    try {
        if (!contact.type) {
            contact.type = newcontact.getType();
        }
        
        if (!contact.inbound) contact.inbound = newcontact.isInbound();
        if (!contact.initialConnectionId) contact.initialConnectionId = newcontact.getInitialConnection().connectionId;
        contact.connections = contact.connections || [];

        for (let item of newcontact.getConnections()) {
            saveConnectionState(item, agent, contact.connections);
        }
        // newcontact.getConnections().forEach(async function(item, i) {
        //     saveConnectionState(item, agent, contact.connections);
        // });

        //Log the attributes of by contact state (i.e., connected, pending, etc.)
        let status = newcontact.getStatus();
        if (!contact.initialTimestamp) newcontact.initialTimestamp = status.timestamp;
        //Take a snapshot of each Contact Status once, the first time the status is reached.
        if (status.type && !contact['stage'+status.type.toProperCase()]) {
            contact['stage'+status.type.toProperCase()] = {};
            contact['stage'+status.type.toProperCase()]['type'] = status.type;
            //set all status attributes if object is null
            for (i=0; Object.keys(status).length > i; i++) {
            if (!contact['stage'+status.type.toProperCase()][Object.keys(status)[i]]) {
                contact['stage'+status.type.toProperCase()][Object.keys(status)[i]] = status[Object.keys(status)[i]];
            }
            }
            //other function calls here
            contact['stage'+status.type.toProperCase()].attributes = newcontact.getAttributes();
            contact['stage'+status.type.toProperCase()].queue = newcontact.getQueue();
            contact['stage'+status.type.toProperCase()].thirdPartyConnections = newcontact.getThirdPartyConnections();
        }
        return contact;
    } catch (err) {
        console.log(err);
    }  
}