Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <script type="text/javascript">
- getMessageText = function () {
- var $message_input;
- $message_input = $('input.msg');
- return $message_input.val();
- };
- $('send_message').click(function (e) {
- msg = getMessageText();
- if(msg){
- showUserMessage(msg);
- sayToBot(msg);
- $('.message_input').val('');
- }
- });
- }
- function showUserMessage(msg_input)
- {
- var msg = msg_input + '</p><div class="clearfix"></div>';
- $(msg).appendTo("textarea.chat").hide().fadeIn(1000);
- }
- function showBotMessage(response)
- {
- setTimeout(function () {
- if (response.length < 1) {
- var fallbackMsg = "I am facing some issues, please try again later!!!";
- var BotResponse = fallbackMsg + '</p><div class="clearfix"></div>';
- $(BotResponse).appendTo("textarea.chat").hide().fadeIn(1000);
- }
- else{
- for (i = 0; i < response.length; i++) {
- //check if the response contains "text"
- if (response[i].hasOwnProperty("text")) {
- BotResponse = response[i].text + '</p><div class="clearfix"></div>';
- $(BotResponse).appendTo("textarea.chat").hide().fadeIn(1000);
- }
- }
- }
- }, 500);
- }
- function sayToBot(text){
- document.getElementById("msg_input").placeholder = "Type your messages here..."
- $.post("/chat",
- {
- text:text,
- },
- function(jsondata, status){
- if(jsondata["status"]=="success"){
- response=jsondata["response"];
- response_orig = jsondata["response_orig"]
- console.log("==>",jsondata["response_orig"])
- if(response){showBotMessage(response_orig);}
- if(response){showBotMessage(response);}
- }
- });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement