AI Zone Admin Forum Add your forum

NEWS: Chatbots.org survey on 3000 US and UK consumers shows it is time for chatbot integration in customer service!read more..

loadDirectory can’t be used on the web!
 
 

In my chat at the bottom, in read color I read “loadDirectory can’t be used on the web!”.
If I can not use it on the web, how I can stop to use it?
On Google is easy to find some other Rivescript chat with this red message:
https://www.google.it/search?client=opera&q=loadDirectory+can’t+be+used+on+the+web!&sourceid=opera&ie=UTF-8&oe=UTF-8#safe=off&q=“loadDirectory+can’t+be+used+on+the+web!”

 

 
  [ # 1 ]

I think that I patched it commenting the line

rs.loadDirectory("brain"); 

in the file named chat.html

 

 

 
  [ # 2 ]

Yeah.

The “eg” folder is there as an example of, “this is *how* you can use it on the web” and wasn’t meant to be uploaded as-is to a site. So, I left that call to `loadDirectory()` in there (which ends up showing that error) as an example of what happens when you try to use `loadDirectory()` on the web. wink

Commenting it out is fine. I just made that fix on the git repo as well.

 

 
  [ # 3 ]

All right! but watching the cache, I still find all the .rive files of the brain folder.

 

 
  [ # 4 ]

The example HTML file uses `loadFile()` but gives it an array of multiple file paths to load at the same time:

// Load our files from the brain/ folder.
rs.loadFile([
"brain/begin.rive",
"brain/admin.rive",
"brain/clients.rive",
"brain/eliza.rive",
"brain/myself.rive",
"brain/rpg.rive",
"brain/javascript.rive"
]on_load_successon_load_error)

Since loadDirectory can’t be used on the web, you have to individually load every file by name; if you add a new .rive file, you have to also add it to that list.

If curious, loadDirectory isn’t supported from a web browser because the environment is different; in the Perl, Python, Java, and (server side, node) JavaScript versions of RiveScript, loadDirectory() works by opening the folder on the local file system and listing the files inside, to find which ones need to be loaded. This is pretty basic in any programming language. But RiveScript.js when run from a browser is in a different environment; it runs inside the end user’s web browser, so it knows nothing about the server’s file system, and it has no way to access the server’s file system. All it can do with the server is make HTTP requests, same as the user could in their own web browser.

The closest analog to trying to scan a directory over HTTP is if the folder path has no index file (so i.e. an Apache web server might respond with “Index of /replies” and list all the entries, for example when you go to http://static.rivescript.com/ ). But, even with directory indexing turned on, the server is technically giving an HTML response full of links and other markup and to try to parse that in the JavaScript… down that way lies madness. It could be programmed to know how to parse Apache’s index page, but then it wouldn’t work on Nginx, and it also would fall apart on any kind of server environment that uses a custom index page template (for example, this site has a custom index template: http://mirrors.liquidweb.com/CentOS/ ).

 

 
  login or register to react