javascript - how to talk to cleverbot via input box? -


i found a script uses cleverbot's api. i'm able response when enter variable in ask() function, how can make user can communicate cleverbot entering value in input box?

also, cleverbot's api prints responses console.log() had use code @ bottom transcribe entries .console div:

$(document).ready(function() {    var bot = new cleverbot("biskhtihzdmgbopp", "dwikyxzthk6geg7lcvhckfobcxydutmp");    bot.setnick("sessionname")    bot.create(function (err, session) {    // session session name, either set previously, or cleverbot.io generate 1      // woo, initialized cleverbot.io.  insert further code here  });    $('#clever').keyup(function (e) {     if (e.keycode == 13) {          var value = $(this).val();        var input = value;           if (value == input) {            document.getelementbyid("input").innerhtml =            '<p>&#62;&nbsp;' + bot.ask(input, function (err, response) {              console.log(input);              console.log(response);            }); + '</p>';         }       }  });    if (typeof console  != "undefined")    if (typeof console.log != 'undefined')      console.olog = console.log;  else    console.olog = function() {};    console.log = function(message) {    console.olog(message);    $('.console').append('<br>' + '<p>&#62;&nbsp;' + message + '</p>');  };  console.error = console.debug = console.info =  console.log  });
<!doctype html>    <head>  <meta charset="utf-8">  <meta name="viewport" content="width=device-width, initial-scale=1">  <link href='https://fonts.googleapis.com/css?family=source+code+pro:400,700,300' rel='stylesheet' type='text/css'>  <link rel="stylesheet" href="https://unilogue.github.io/css/style.css">  <script type="text/javascript" src="https://unilogue.github.io/js/jquery-1.11.3.min.js"></script>  <script type="text/javascript" src="https://unilogue.github.io/js/cleverbot/cleverbot.io.js"></script>  </head>    <body>    <div class="console" style="width:75%;"></div>  <div id="input"></div>  <p>&#62;&nbsp;</p><input id="clever" type="text" placeholder="say clever." />      </body>      </html>

i updated snippet , added if... statement enable dialogue.

$(document).ready(function() {    var bot = new cleverbot("biskhtihzdmgbopp", "dwikyxzthk6geg7lcvhckfobcxydutmp");        bot.setnick("sessionname")    bot.create(function (err, session) {    // session session name, either set previously, or cleverbot.io generate 1      // woo, initialized cleverbot.io.  insert further code here  });    $('#clever').keyup(function (e) {     if (e.keycode == 13) {          var value = $(this).val();        var input = value;           if (value == input) {            document.getelementbyid("input").innerhtml =              bot.ask(input, function (err, response) {              console.log('me > ' + input);              console.log('cb > ' + response); // be: "living in lonely world"            });            $(this).val('');         }       }  });    $('html').keydown(function(e) {   if (e.which == 118) {      window.open('/', '_self');  }  });    if (typeof console  != "undefined")    if (typeof console.log != 'undefined')      console.olog = console.log;  else    console.olog = function() {};    console.log = function(message) {    console.olog(message);    $('.console').append('<br>' + '<p>' + message + '</p>');  };  console.error = console.debug = console.info =  console.log  });
<!doctype html>    <head>  <meta charset="utf-8">  <meta name="viewport" content="width=device-width, initial-scale=1">  <link href='https://fonts.googleapis.com/css?family=source+code+pro:400,700,300' rel='stylesheet' type='text/css'>  <link rel="stylesheet" href="https://unilogue.github.io/css/style.css">  <script type="text/javascript" src="https://unilogue.github.io/js/jquery-1.11.3.min.js"></script>  <script type="text/javascript" src="https://unilogue.github.io/js/cleverbot/cleverbot.io.js"></script>  </head>    <body>    <div class="console"><div id="input" style="display:none;"></div></div>  <p>me &#62;&nbsp;</p><input id="clever" type="text" placeholder="say clever." spellcheck="false" />      </body>      </html>


Comments

Popular posts from this blog

get url and add instance to a model with prefilled foreign key :django admin -

css - Make div keyboard-scrollable in jQuery Mobile? -

ruby on rails - Seeing duplicate requests handled with Unicorn -