in assets/web/js/custom.js [19:82]
function pushChat() {
// User statement is read directly form the input box itself.
var chatInputText = document.getElementById('chatInput');
// Disable mic tempropily and dim mic icon.
micEnabled = false;
$(".mic-con").css('opacity', '0.25');
// Checks is there such element with id chatInput and it
// contains any value and its length greater than 0 after triming.
if(chatInputText && chatInputText.value && chatInputText.value.trim().length > 0) {
// Trim spaces from the input and update visual cues for
// the user. Disable the chat input temprorily.
var chatInput = chatInputText.value.trim();
chatInputText.value = 'Lisa is typing...';
chatInputText.locked = true;
document.getElementById("chatInput").disabled = true;
// Create a parameter dict with bot details and user
// details. It will be used during the negotiation with
// the Lex.
var params = {
botAlias: botAlias,
botName: botName,
inputText: chatInput,
userId: lexUserId,
sessionAttributes: {}
};
// Append the user statement to the chat window.
showRequest(chatInput);
// Append the loader element to view loading icon and
// scroll to bottom.
$("#chat-con").append(loaderElement);
$("#conversation").scrollTop($("#chat-con").height());
// Post the user statements to Lex and wait for the response.
lexRunTime.postText(params, function(err, data) {
// Received response from the Lex so, enalbe mic back and
// remove the loader icon from the chat window.
micEnabled = true;
$(".mic-con").css('opacity', '1');
$(".loader-con").remove();
// If error is received then log it to the console and
// show the error message in the chat window.
if(err) {
console.log(err, err.stack);
showError('Error: ' + err.message + ' (see console for details)')
}
// If data is received then copy the session attributes from
// the response to the global variable, so it can be consumed
// by other functions. Show the received response to the user.
if(data) {
sessionAttributes = data.sessionAttributes;
console.log(data);
showResponse(data);
}
// Set the user input box to empty, enable it and
// focus it, so user can start typing without clicking
// the text box again.
chatInputText.value = '';
chatInputText.locked = false;
document.getElementById("chatInput").disabled = false;
document.getElementById("chatInput").focus();
});
}
}