in customer/src/customer/index.js [104:182]
function successHandler(chatSession) {
// chat connected
windowAny.chatSession = chatSession;
$('#divSpinner').fadeOut(200);
$('#chatWrapper').fadeIn(400);
//Change the incoming data set
chatSession.incomingItemDecorator = function(item) {
if (['SYSTEM_MESSAGE'].indexOf(item.displayName) !== -1) {
item.displayName = 'System Message';
}
if (chatSession.transcript.length > 0) {
var transcriptItem = chatSession.transcript[chatSession.transcript.length - 1];
if (transcriptItem.transportDetails.direction === 'Incoming') {
var chatDescription = 'This is a demo of a customer chat experience.';
var name = transcriptItem.displayName;
if (
['prod', '$LATEST', 'AI Assistant', 'SYSTEM_MESSAGE', 'System Message'].indexOf(name) ===
-1
) {
chatDescription = 'You are now chatting with ' + name;
}
document.getElementById('chatDescription').innerHTML = chatDescription;
}
}
return item;
};
chatSession.onIncoming(async function(data) {
if(
data['Content'] &&
typeof data['Content'] === 'string'
) {
if(data['Content'].startsWith('Meeting')) {
$('span:contains("Meeting")').parent().parent().hide();
$('.header-wrapper').next().css('visibility', 'visible');
meeting = JSON.parse(data['Content'].replace('Meeting Info: ', ''));
setTimeout(() => {
$('span:contains("Meeting")').parent().parent().hide()
$('span:contains("Let")').parent().parent().hide();
$('.header-wrapper').next().css('visibility', 'visible');
}, 500);
} else if(data['Content'].startsWith('CustomerAttendee')) {
$('span:contains("CustomerAttendee")').parent().parent().hide();
$('.header-wrapper').next().css('visibility', 'visible');
customerAttendee = JSON.parse(data['Content'].replace('CustomerAttendee Info: ', ''));
setTimeout(() => {
$('span:contains("CustomerAttendee")').parent().parent().hide()
$('span:contains("Let")').parent().parent().hide();
$('.header-wrapper').next().css('visibility', 'visible');
}, 500);
}
}
if (meeting && customerAttendee) {
domShow('meeting-info');
}
});
chatSession.onChatDisconnected(function(data) {
console.log('Chat disconnected');
leave();
});
windowAny.connect.ChatInterface.init({
containerId: 'root',
headerConfig: {
isHTML: true,
render: () => {
return `
<div class="header-wrapper">
<h2 class="welcome-text">Chat Demo</h2>
<p id="chatDescription">This is a demo of interacting with a Lex bot.</p>
</div>
`;
},
},
});
}