You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
<p>If you want to make your chatbot visible on the web, you need a server. As it turns out, for low traffic, Amazon will let you have a server machine for free for a year and a low fee thereafter. Here is an overview of how to create a ChatScript server on Amazon's cloud services.</p>
16
19
<p>First, you need an Amazon AWS account. Go to http://aws.amazon.com/account/ and sign up for one if you don't have one.</p>
<p>While the system defaults to running as a stand-alone chatbot under Windows, when run under LINUX it defaults to being a server.</p>
34
38
<p>Nominally (meaning depending on hardware and what your bot does) ChatScript can process a volley on a single core in 10 milliseconds on a slow machine, thus handling 100 volleys every second from different users using one core. A human-human volley is often around 15 seconds, so handling 1000 simultaneous users with a single core slow server is not unreasonable.</p>
<li><p>Write out any user variables you care about. You may not care about the random seed or turn number, or you can write them out as well.</p></li>
200
204
<li><p>Currently there is no interface to context data so you can't write that out. Generally all this will be written out by a post-process phase.</p></li>
201
205
</ol>
206
+
<h1id="encryption">Encryption</h1>
207
+
<p>ChatScript normally reads and writes everything in plain text. If you need greater security then you need to do several things.</p>
208
+
<olstyle="list-style-type: decimal">
209
+
<li><p>turn off server logs and user logs</p></li>
210
+
<li><p>Use encrypt= and decrypt= command line parameters.</p></li>
211
+
<li><p>Use default system or roll your own encryption in privatecode.</p></li>
212
+
</ol>
213
+
<p>Encryption applies to user topic files and long term memory files (^export and ^import). The built-in encryption method calls an external api server using json to perform encryption and decryption, passing the server urls provided by encrypt= and decrypt= command line parameters. The routines will add in the user's login id if you use %s in the command line parameters. Eg.,</p>
<p>To roll your own, you have to define routines in private code that encrypt and decrypt (see examples in os.cpp) and on private initialization override the default variables controlling userFileSystem.encrypt and userFileSystem.decrypt.</p>
<p>ChatScript is fine for a chatbot that does not depend on the outer world. But if you need to control an avatar or grab information from sensors or the Internet, you need a way to communicate externally from ChatScript. There are three mechanisms: embedding ChatScript inside another main program which will do the machine-specific actions, calling programs on the OS from ChatScript where ChatScript remains in control, and getting services via the Interet from ChatScript.</p>
16
19
<h2id="calling-outside-routines-from-chatscript">Calling Outside Routines from ChatScript</h2>
<p>Second are passive strings like "meat-loving plants".</p>
49
52
<p>Third are active strings (which you haven't read about yet) like <code>^"I like $value"</code>. Active strings involve references to functions or data inside them and execute when used to convert their results into a passive string with appropriate value substitutions.</p>
50
53
<p>Other languages would name a CS active string a format string, and have to pass it to a function like sprintf along with the arguments to embed into the format. CS just directly embeds the arguments in the string and any attempt to use the active string implicitly invokes the equivalent of sprintf.</p>
51
-
<p>User variables also come in permanent and transient forms. <strong>Permanent variables</strong> start with a single <code>$</code> and are preserved across user interactions (are saved and restored from disk). <strong>Transient variables</strong> start with <code>$$</code> and completely disappear when a user interaction happens (are not saved to disk).</p>
54
+
<p>User variables also come in permanent and transient forms. <strong>Permanent variables</strong> start with a single <code>$</code> and are preserved across user interactions (are saved and restored from disk). You can see and alter their value from anywhere. <strong>Transient variables</strong> start with <code>$$</code> and completely disappear when a user interaction happens (are not saved to disk). You can see and alter their value from anywhere. <strong>Local variables</strong> (described later) start with <code>$_</code> and completely disappear when a user interaction happens (are not saved to disk). You can see and alter their value only within the topic or outputmacro they are used.</p>
52
55
<h3id="facts">Facts</h3>
53
56
<p>ChatScript supports structured triples of data called facts, which can be found by querying for them. The 3 fields of a fact are either text strings or fact references to other facts. So you might have a fact like</p>
<p>What happens is this- when the system detects the transfer of control (the <code>^reuse</code> call), if there is output pending it is finished off and packaged for the user. The current stream is cleared, and the rule is erased (if allowed to be). Then the <code>^reuse()</code> happens. Even if it fails, this rule has produced output and been erased.</p>
447
450
<p>Assuming the reuse doesn't fail, it will have sent whatever it wants into the stream and been packaged up for the user. The rest of the message for this rule now goes into the output stream <em>and so do you</em> and then that too is finished off and packaged for the user. The rule is erased because it has output in the stream when it ends (but it was already erased so it doesn't matter).</p>
448
451
<p>So, output does two things. It queues up tokens to send to the user, which may be discarded if the rule ultimately fails. And it can call out to various functions. Things those functions may do are permanent, not undone if the rule later fails.</p>
452
+
<h2id="output-cannot-have-rules-in-it">Output cannot have rules in it</h2>
453
+
<p>Output script cannot emed another rule inside it. Output is executed during the current volley whereas rules (like rejoinder rules) may be executed in a different volley. Therefore this is illegal: <code>u: GREETING (~emohello)</code><code>if ($username)</code><code>{</code><code>Hi $username!</code><code>}</code><code>else</code><code>{</code><code>I don't believe we've met, what's your name?</code><code>a: (_*) So your name is '_0?</code><code>}</code> and needs to be written like this: <code>u: GREETING (~emohello)</code><code>if ($username)</code><code>{</code><code>Hi $username!</code><code>}</code><code>else</code><code>{</code><code>I don't believe we've met, what's your name?</code><code>}</code><code>a: (_*) So your name is '_0?</code> Of course you don't want the rejoinder triggered if you can from the <code>if</code> side, so you'd also need to add a call to <code>^setnorejoinder</code> from inside it.</p>
<p>Because you can intermix program script with ordinary output words, ChatScript normally autoformats output code. But programming languages allow you to control your output with format strings and ChatScript is no exception.</p>
451
456
<p>In the case of ChatScript, the active string <code>^"xxx"</code> string is a format string. The system will remove the <code>^</code> and the quotes and put it out exactly as you have it, except, it will substitute variables (which you learn about shortly) with their values and it will accept <code>[ ]</code><code>[ ]</code> choice blocks. And will allow function calls. You can't do assignment statements or loops or if statements.</p>
<p>Now suppose you wanted to set that variable to some number representing the turn after which you might return.</p>
645
650
<pre><code>$$tmp = 25</code></pre>
646
-
<p>doesn't work. It wipes out the <spanclass="math inline">$washing value of `$</span><spanclass="math inline">$tmp` and replaces it with `25`. You can set indirectly through `$</span><spanclass="math inline">$tmp` using function notation `^`, e.g. ``` ^$</span><spanclass="math inline">$tmp = 25 ``` The above says take the value of `$</span>$tmp<code>, treat it as the name of a variable, and assign into it. Which means it does the equivalent of ``` $washing = 25 ``` If you want to an indirect value back, you can't do: ``` $$val = $$tmp ``` because that just passes the name of</code><spanclass="math inline">$washing` over to `$</span>$val`. Instead you do indirection again:</p>
651
+
<p>doesn't work. It wipes out the <spanclass="math inline">$washing value of `$</span>$tmp<code>and replaces it with</code>25`.</p>
652
+
<p>You can set indirectly through <code>$$tmp</code> using function notation <code>^$$tmp</code> The above says take the value of <code>$$tmp</code>, treat it as the name of a variable, and assign into it. Which means it does the equivalent of</p>
653
+
<pre><code>$washing = 25</code></pre>
654
+
<p>If you want to an indirect value back, you can't do:</p>
655
+
<pre><code>$$val = $$tmp</code></pre>
656
+
<p>because that just passes the name of <code>$washing</code> over to <code>$$val</code>. Instead you do indirection again:</p>
<p>Indirection works with values that are user variables and with values that are match variables or quoted match variables.</p>
649
659
<p>Many routines automatically evaluate a variable when using it as an argument, like <code>^gambit($$tmp)</code>. But if you want the value of the variable it represents, then you need to evaluate it another time.</p>
@@ -663,6 +673,10 @@ <h2 id="assigning-match-variables-to-user-variables">Assigning match variables t
663
673
<p>When you assign onto a match variable from a user variable, you make both original and canonical values of the match variable the same, and the positional data is set to 0.</p>
664
674
<pre><code>_0 = _10</code></pre>
665
675
<p>This is a transfer from one match variable to another, so no data is lost</p>
676
+
<h2id="json-dotted-notation-for-variables">Json dotted notation for variables</h2>
677
+
<p>If a variable holds a JSON object value, you can directly set and get from fields of that object using dotted notation. This must be a fixed static fieldname you give- <code>$myvar.$myfield</code> is illegal. Dotted notation is cleaner and faster than <code>^jsonpath</code> and <code>jsonobjectinsert</code> and for get, has the advantage that it never fails, it only returns null if it can't find the field. On the other hand, assignment fails if the path does not contain a json object at some level.</p>
678
+
<pre><code>$x = $$$obj.name.value.data.side
679
+
$$$obj.name.value.data.side = 7</code></pre>
666
680
<h1id="out-of-band-communication">Out of band Communication</h1>
667
681
<p>ChatScript can neither see nor act, but it can interact with systems that do. The convention is that out-of-band information occurs at the start of input or output, and is encased in <code>[ ]</code>.</p>
668
682
<p>ChatScript does not attempt to postag and parse any input sentence which begins with <code>[</code> and has a closing <code>]</code>. It will automatically not try to spellcheck that part or perform any kind of merge (date, number, propername). In fact, the <code>[…]</code> will be split off into its own sentence. You can use normal CS rules to detect and react to incoming oob messaging. E.g, input like this</p>
<p>Just for reference, for our most advanced bot, the actual max values used were: max dict: 346 max fact: 689 max text: 38052.</p>
1011
1025
<p>And the maximum rules executed to find an answer to an input sentence was 8426 (not that you control or care). Typical rules executed for an input sentence was 500-2000 rules. For example, add 1000 to the dict and fact used amounts and 10 (kb) to the string space to have enough normal working room.</p>
1012
1026
<h2id="output-options">Output options</h2>
1013
-
<p><code>output=nnn</code> limits output line length for a bot to that amount (forcing as needed). 0 is unlimited.</p>
1027
+
<p><code>output=nnn</code> limits output line length for a bot to that amount (forcing crnl as needed). 0 is unlimited.</p>
1014
1028
<h2id="file-options">File options</h2>
1015
1029
<p><code>livedata=xxx</code> – name relative or absolute path to your own private LIVEDATA folder. Do not add trailing / on this path. Recommended is you use <code>RAWDATA/yourbotfolder/LIVEDATA</code> to keep all your data in one place.</p>
1016
1030
<p>You can have your own live data, yet use ChatScripts default <code>LIVEDATA/SYSTEM</code> and <code>LIVEDATA/ENGLISH</code> by providing paths to the <code>system=</code> and <code>english=</code> parameters as well as the <code>livedata=</code> parameter.</p>
1017
1031
<p><code>users=xxx</code> – name relative or absolute path to where you want the USERS folder to be. Do not add trailing /. <br><code>logs=xxx</code> – name relative or absolute path to where you want the LOGS folder to be. Do not add trailing /.</p>
1018
1032
<p>Other options: <code>trace</code> – turn on all tracing.</p>
1019
1033
<p><code>redo</code> – see documentation for :redo in debugging manual</p>
1020
-
<p><code>userfacts=n</code> limit a user file to saving only the n most recently created facts of a user (this does not include facts stored in fact sets). Overridden if the user has <code>$cs_userfactlimit</code> set to some value. <br><code>userlog</code> - Store a user-bot log in USERS directory (default). <br><code>nouserlog</code> - Don't store a user-bot log. <br><code>login=xxxx</code> - The same as you would name when asked for a login, this avoids having to ask for it. Can be <code>login=george</code> or <code>login=george:harry</code> or whatever.</p>
1021
-
<p><code>build0=filename</code> runs <code>:build</code> on the filename as level0 and exits with 0 on success or 4 on failure. <br><code>build1=filename</code> runs :build on the filename as level1 and exits with 0 on success or 4 on failure. Eg. ChatScript <code>build0=files0.txt</code> will rebuild the usual level 0.</p>
1022
-
<p><code>debug=:xxx</code> xxx runs the given debug command and then exits. Useful for <code>:trim</code>, for example or more specific <code>:build</code> commands.</p>
1023
-
<p><code>param=xxxxx</code> data to be passed to your private code</p>
1034
+
<p><code>userfacts=n</code> limit a user file to saving only the n most recently created facts of a user (this does not include facts stored in fact sets). Overridden if the user has <code>$cs_userfactlimit</code> set to some value. <br><code>userlog</code> - Store a user-bot log in USERS directory (default). <br><code>nouserlog</code> - Don't store a user-bot log. <br><code>login=xxxx</code> - The same as you would name when asked for a login, this avoids having to ask for it. Can be <code>login=george</code> or <code>login=george:harry</code> or whatever. <br><code>build0=filename` runs `:build` on the filename as level0 and exits with 0 on success or 4 on failure. <br>`build1=filename` runs :build on the filename as level1 and exits with 0 on success or 4 on failure. Eg. ChatScript `build0=files0.txt` will rebuild the usual level 0. <br></code>debug=:xxx<code>xxx runs the given debug command and then exits. Useful for</code>:trim<code>, for example or more specific</code>:build<code>commands. <br>``param=xxxxx</code> data to be passed to your private code <br><code>login=xxxxx` initial user id (bypass asking you for user) <br></code>encrypt=xxxxx<code>data evailable to encrpytion code <br>``decrypt=xxxxx</code> data evailable to decrpytion code <br>`<code>bootcmd=xxx</code> runs this command string before CSBOOT is run use it to trace the boot process</p>
1024
1035
<h2id="bot-variables-1">Bot variables</h2>
1025
1036
<p>You can create predefined bot variables by simply naming permanent variables on the command line, using V to replace $ (since Linux shell scripts don't like $). Eg.</p>
1026
1037
<p><br>ChatScript Vmyvar=fatcat <br>ChatScript Vmyvar="tony is here" <br>ChatScript "Vmyvar=tony is here"</p>
0 commit comments