Retainage?|Art|stoney535@gmail.com|1362247985|Art|xx|0|76.21.135.205|Noah,<br />Is there a fairly approachable method that would allow for Rivescript's Bots to Retain information about it's master / user, as if to construct a database?<br /><br />I've weeded out over 618,000 useless foreign words and phrases and the program now loads and runs much faster. It is coming along nicely, THANKS!<br /><br />I'd like the bot to be able to learn / know more about me and my likes / dislikes, etc., ever time.<br /><br />Are such goals possible as is currently implemented?<br /><br />Best,<br />- Art -<br /><br />PS - Main page &quot;CONTACT&quot; is broken link.<br /><br />||||
Re: Retainage?|Kirsle|casey@cuvou.net|1362253351|Kirsle|xx|0|76.168.88.125|RiveScript is able to set/get variables about the user if that's what you mean.<br /><br />[code]+ my name is *<br />- &lt;set name=&lt;formal&gt;&gt;Nice to meet you, &lt;get name&gt;!<br /><br />+ what is my name<br />* &lt;get name&gt; != undefined =&gt; Your name is &lt;get name&gt;!<br />- I don't know - you never told me.[/code]<br /><br />You can get the user's variables out of RiveScript via the getUservars() method so you can save them to disk or into a database or something, and use setUservars() to put the vars back into RiveScript. This way the bot will remember info about users between reboots. :) Here is an example: https://github.com/kirsle/aires-bot/blob/master/brains/RiveScript.pm||||
Re: Retainage?|Art|stoney535@gmail.com|1365283815|Art|xx|0|76.21.135.205|Is there a tag like the &lt;get&gt; / &lt;set&gt; ones to DEFINE a User's name within the &gt;begin section?<br /><br />This is to enable the same individual to &quot;jump right in&quot; and have a conversation with the bot &quot;Knowing&quot; his / her name without having to be told each time the bot is started.<br /><br />Thanks as always!||||
Re: Retainage?|Kirsle|casey@cuvou.net|1365321086|Kirsle|xx|0|76.168.196.14|You can call the setUservar() method on the rivescript object to set a user variable.<br /><br />How I usually handle keeping track of user variables between runs of the bot is something along the lines of,<br /><br />1. If the user variable cache (a .json file) exists, load it, and call rs.setUservar() for each variable.<br />2. Get a reply from the bot via rs.reply()<br />3. Get all user variables out of the bot via rs.getUservars()<br />4. Save the user vars to disk as a .json file.<br /><br />So every time the bot gets a reply for the user, all their user variables are pulled from the bot and saved to disk. On the next message, they're read back from disk and fed back into the bot, before the bot gives a reply to the user. This way I can kill and restart the bot and it will still be able to &quot;remember&quot; details about the users, because I save them to disk myself and make sure to put them back into the bot before it gets them a reply.||||
Re: Retainage?|calyx|calyx238@gmail.com|1365414638|calyx|xx|0|82.33.193.237|Another option if you are using Perl you can simply freeze the interpeter instance onto disk using the Storable module, and thaw it when the bot is started.||||
Re: Retainage?|Art|stoney535@gmail.com|1365462290|Art|xx|0|76.21.135.205|Those are some great ideas but I'm just getting my feet wet with Rivescript and wish to have the bot ALWAYS know who I am.<br /><br />Hello Art! Nice to chat with you again...etc.<br /><br />I would like a way to &quot;hard code&quot; this USER NAME into perhaps the begin.rs file.<br /><br />I am working on an idea and I need for the bot to always &quot;know&quot; it's me (or another named user) that it's chatting with.<br /><br />Is this even doable? I using a Command Prompt and Javascript for chatting.<br /><br />Thanks!<br />||||
Re: Retainage?|Kirsle|casey@cuvou.net|1365463309|Kirsle|xx|0|76.168.196.14|Sort of. The RiveScript files themselves can't set user variables (like in begin.rs etc).. only bot variables, and globals and some other things. Setting a user variable has to be done &quot;outside&quot; of the bot, i.e. as explained earlier with the setUservar() function.<br /><br />[code]var rs = new RiveScript();<br />rs.setUservar(&quot;soandso&quot;, &quot;name&quot;, &quot;Art&quot;);<br /><br />...<br /><br />var reply = rs.reply(&quot;soandso&quot;, &quot;what is my name?&quot;);<br />// reply might be &quot;Your name is Art.&quot;[/code]<br /><br />A slightly more complete example, which follows the same logic as I mentioned earlier (saving/restoring the user variables after each reply), for JavaScript, for it to remember details about the user chatting with the bot... using HTML5 LocalStorage.<br /><br />[code]var rs = new RiveScript();<br />rs.loadFile([<br />   &quot;brain/begin.rs&quot;,   &quot;brain/whatever.rs&quot;<br />], load_success, load_error);<br /><br />function load_success () &#123;<br />   rs.sortReplies();<br />   // do something to indicate the bot is ready to chat<br />&#125;<br /><br />// function to handle sending the bot a message<br />function send_message (msg) &#123;<br />   // Retrieve their saved vars if they have any.<br />   var vars = localStorage[&quot;rs_vars&quot;];<br />   if (vars != undefined) &#123;<br />      // JSON-parse them.<br />      vars = JSON.parse(vars);<br /><br />      // Set the variables.<br />      for (var key in vars) &#123;<br />         rs.setUservar(&quot;soandso&quot;, key, vars[key]);<br />      &#125;<br />   &#125;<br /><br />   // Get a reply<br />   var reply = rs.reply(&quot;soandso&quot;, msg);<br />   // do something to display the reply for the user<br /><br />   // Save the user vars back to localStorage.<br />   vars = rs.getUservars(&quot;soandso&quot;);<br />   localStorage[&quot;rs_vars&quot;] = JSON.stringify(vars);<br />&#125;[/code]<br /><br />If you're using the JavaScript version of RS to just be run in a web browser (i.e. no server side component to it), the user ID (&quot;soandso&quot; in these examples) is completely unimportant (unless you want to make a sort of &quot;login screen&quot;, where people sharing the same computer can provide their own username... in which case you'd wanna make the localStorage name of &quot;rs_vars&quot; be something unique to the user ID). If you're using it in Node.JS or something however, where multiple users on the Internet will be interacting with the same code, you'd need to figure something else out to have unique IDs for each user (either prompt them for a username, or just go with the socket fileno. or something).<br /><br />If you really really wanted to set a default user var from within RiveScript itself, i.e. if you're making a &quot;single user&quot; kind of bot, where it will ALWAYS assume the human is named Art even if somebody else chats with it...<br /><br />[code]&gt; begin<br /> &nbsp; + request<br /> &nbsp; * &lt;get name&gt; == undefined =&gt; &lt;set name=art&gt;&#123;ok&#125;<br /> &nbsp; - &#123;ok&#125;<br />&lt; begin[/code]||||
Re: Retainage?|Art|stoney535@gmail.com|1365584811|Art|xx|0|76.21.135.205|Thanks for the information!! Lots of good things to be done with Rivescript!!<br /><br />That's what I was looking for!!!||||
