' +
'
' +
'
'+text+'
' +
'
'+date+'
' +
'
' +
'
' +
'';
}else{
control = '
' +
'' +
'
' +
'
' +
'
'+ text +'
' +
'
'+date+'
' +
'
' +
'
' +
'';
}
$("#messages").append(control);
var objDiv = document.getElementById("messages");
objDiv.scrollTop = objDiv.scrollHeight;
}
$("#chat-panel").on('click',function(){
$(".innerframe").toggle();
});
function resetChat(){
$("#messages").empty();
}
$(".mytext").on("keyup", function(e){
if (e.which == 13){
var text = $(this).val();
if (text !== ""){
insertChat("local", text);
$(this).val('');
queryBot(text)
}
}
});
resetChat();
function queryBot(text) {
$.ajax({
type: "POST",
url: baseUrl + "query?v=20150910",
contentType: "application/json; charset=utf-8",
dataType: "json",
headers: {
"Authorization": "Bearer " + accessToken
},
data: JSON.stringify({ query: text, lang: "en", sessionId: "somerandomthing" }),
success: function(data) {
insertChat("remote",data.result.fulfillment.speech);
},
error: function() {
insertChat("remote","Internal Server Error");
}
});
}