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
Copy file name to clipboardExpand all lines: docs/code-mods/connecting-a-database-using-google-sheets.md
+9-10Lines changed: 9 additions & 10 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -6,14 +6,14 @@ You can use a Google Sheet as a database for your chatbot. Making a database thi
6
6
7
7
Below is an example of a spreadsheet of _machine learning_ terms. Of course, you could have many more terms. **The key is to make it a simple table with single word headings on the first row.**
8
8
9
-

9
+

10
10
11
-
## 2. Publish Your Google Sheet <aid="using-google-sheet-as-database-recommended"></a>
11
+
## 2. Publish Your Google Sheet <ahref="#using-google-sheet-as-database-recommended"id="using-google-sheet-as-database-recommended"></a>
12
12
13
13
In order to import your information, you will need to publish your Google Sheet.
14
14
15
15
1. Publish your copy of the spreadsheet by selecting `File > Publish to the web...` and click the `Publish` button.
16
-
2. Once your spreadsheet is published, click the _share_ button \(upper right-hand side\) of the spreadsheet page and **copy the shareable link**. \(Make sure your link is set to _Anyone with the link can view_.\)
16
+
2. Once your spreadsheet is published, click the _share_ button (upper right-hand side) of the spreadsheet page and **copy the shareable link**. (Make sure your link is set to _Anyone with the link can view_.)
17
17
18
18
## 3. Load the Spreadsheet Data into Your Chatbot JavaScript
19
19
@@ -30,15 +30,15 @@ function setup() {
30
30
}
31
31
```
32
32
33
-
**You will need to change the `key` value \(the long number in the example above\) to the link you copied in the previous step for your Google sheet.** Your spreadsheet data is now available in an array, `chatbot.db`, where each array element represents a row in your spreadsheet as an object.
33
+
**You will need to change the `key` value (the long number in the example above) to the link you copied in the previous step for your Google sheet.** Your spreadsheet data is now available in an array, `chatbot.db`, where each array element represents a row in your spreadsheet as an object.
34
34
35
35
{% hint style="warning" %}
36
-
**For those that may have previously used `loadDB( )`:**
36
+
**For those that may have previously used `loadDB( )`:** 
37
37
38
38
The `loadDB( )` function still works but it is being deprecated. You should use the `getDB( )` shown above since it supports loading multiple databases.
39
39
{% endhint %}
40
40
41
-
The `chatbot.db` array now contains your spreadsheet data as a list of Javascript objects like the one shown below. See the connection to the spreadsheet we started with? So, in Javascript you could use `chatbot.db[0].keywords` to get the first term's key words \("labeled, training"\).
41
+
The `chatbot.db` array now contains your spreadsheet data as a list of Javascript objects like the one shown below. See the connection to the spreadsheet we started with? So, in Javascript you could use `chatbot.db[0].keywords` to get the first term's key words ("labeled, training").
42
42
43
43
```javascript
44
44
[
@@ -73,11 +73,11 @@ The `chatbot.db` array now contains your spreadsheet data as a list of Javascrip
73
73
]
74
74
```
75
75
76
-
## 4. Accessing the Database in a Function
76
+
## 4. Accessing the Database in a Function 
77
77
78
-
You could now access your database in a function like the one below. This function gets a random term to quiz the chatbot user. Notice how the chatbot responds to "quiz me" by calling the `getRandomTerm` function \(object\) which returns a random term so the chatbot responds with something like "What is Reinforcement Learning?".
78
+
You could now access your database in a function like the one below. This function gets a random term to quiz the chatbot user. Notice how the chatbot responds to "quiz me" by calling the `getRandomTerm` function (object) which returns a random term so the chatbot responds with something like "What is Reinforcement Learning?".
79
79
80
-
```text
80
+
```
81
81
> object getRandomTerm javascript
82
82
var randomIndex = Math.floor(Math.random() * chatbot.db.length);
Copy file name to clipboardExpand all lines: docs/code-mods/searching-a-database.md
+6-10Lines changed: 6 additions & 10 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -1,12 +1,10 @@
1
1
# Searching a Database
2
2
3
-
Below is an example of how a chatbot could search a database of definitions and display the results as buttons for the user to click to then get the definition of that term.
4
-
5
3
{% hint style="info" %}
6
4
This example uses the same database described in the example for [Connecting a Database Using Google Sheets](https://docs.idew.org/code-chatbot/code-mods/connecting-a-database-using-google-sheets), which has column names _id, term, definition, and keywords_. Your database will likely have different column names.
7
5
{% endhint %}
8
6
9
-

7
+

10
8
11
9
## 1. Create the Rivescript Trigger
12
10
@@ -35,10 +33,10 @@ The function below will process the search and return HTML about the results.
35
33
36
34
Let's step through what is happening above...
37
35
38
-
**Line 2** uses the `chatbot.dbFilter()` function. Notice there are 3 arguments used by the function.
39
-
- `chatbot.db` is the database to be searched.
40
-
- `"term"` is the column name to be searched. In this case we will search each term name.
41
-
- `args` represents the text the user has typed in for the search.
36
+
**Line 2** uses the `chatbot.dbFilter()` function. Notice there are 3 arguments used by the function.\
37
+
 \-`chatbot.db` is the database to be searched.\
38
+
 \-`"term"` is the column name to be searched. In this case we will search each term name.\
39
+
 \-`args` represents the text the user has typed in for the search.\
42
40
The variable `filtered` now contains the matches of our search.
43
41
44
42
**Lines 3-5** takes each matched item and creates HTML for the term and definition that will be displayed to the user.
@@ -47,7 +45,5 @@ The variable `filtered` now contains the matches of our search.
47
45
48
46
**Line 7** modifies our reply with the HTML of terms and definitions if there were any matches.
49
47
50
-
**Line 8** uses the chatbot.postReply\(\) function to display the reply after 2 seconds.
51
-
52
-
48
+
**Line 8** uses the chatbot.postReply() function to display the reply after 2 seconds.
Copy file name to clipboardExpand all lines: docs/code-mods/use-buttons-for-user-input.md
+4-5Lines changed: 4 additions & 5 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -1,15 +1,15 @@
1
1
# Add Buttons for User Input
2
2
3
-

3
+

4
4
5
-
While a text interface is great for allowing people to engage with natural language, there are times when a simple button has advantages allowing you to interact with specificity and save time for the user.
5
+
While a text interface is great for allowing people to engage with natural language, there are times when a simple button has advantages allowing you to interact with specificity and save time for the user. 
6
6
7
7
### Use HTML Buttons Directly in the Rivescript
8
8
9
-
Below is an example of how you could insert buttons in the chatbot's response. It uses a standard HTML button element with an `onclick` attribute to run the \`getReply\(\) function of the chatbot library. Notice how each argument in the `getReply` functions \('hello', 'bye', or 'youre awesome'\) is a string that will match a trigger in your Rivescript file.
9
+
Below is an example of how you could insert buttons in the chatbot's response. It uses a standard HTML button element with an `onclick` attribute to run the \`getReply() function of the chatbot library. Notice how each argument in the `getReply` functions ('hello', 'bye', or 'youre awesome') is a string that will match a trigger in your Rivescript file.
10
10
11
11
{% hint style="info" %}
12
-
Notice that the example below uses the continuation syntax \(`^`\) in the chatbot response to make the Rivescript easier to read. Also notice that the optional `<br>` element is used to create a line break in the chatbot interface.
12
+
Notice that the example below uses the continuation syntax (`^`) in the chatbot response to make the Rivescript easier to read. Also notice that the optional `<br>` element is used to create a line break in the chatbot interface.
13
13
{% endhint %}
14
14
15
15
{% code title="Rivescript" %}
@@ -32,4 +32,3 @@ Notice that the example below uses the continuation syntax \(`^`\) in the chatbo
The code below will get you started with the iDEW chatbot template. It is a minimum starting point for a working chatbot that you will later modify and refine towards your design goals. There is a ****[**live example**](https://chatbot2018--jimlyst.repl.co/) which doesn't do anything exciting -- that's up to you to change.
5
+
The code below will get you started with the iDEW chatbot template. It is a minimum starting point for a working chatbot that you will later modify and refine towards your design goals. There is a ****[**live example**](https://chatbot2018--jimlyst.repl.co) which doesn't do anything exciting -- that's up to you to change.
6
6
7
7
## HTML
8
8
9
-
Below is the core html for the chatbot. The _div_ element with an _id="dialogue"_ is the block that contains the back-and-forth messages like you see in common messaging interfaces. The _form_ element handles the user's text input at the bottom of the interface.
9
+
Below is the core html for the chatbot. The _div_ element with an _id="dialogue"_ is the block that contains the back-and-forth messages like you see in common messaging interfaces. The _form_ element handles the user's text input at the bottom of the interface. 
10
10
11
-
The required libraries are also loaded. _Tabletop.js_ enables you to use a back-end database using Google Sheets. _JQuery_ is a common library for Javascript programmers. _Rivescript_ is the chatbot scripting language you will use \(more on this later\). _Chatbot.js_ is the iDEW library that makes your programming easier.
11
+
The required libraries are also loaded. _Tabletop.js_ enables you to use a back-end database using Google Sheets. _JQuery_ is a common library for Javascript programmers. _Rivescript_ is the chatbot scripting language you will use (more on this later). _Chatbot.js_ is the iDEW library that makes your programming easier.
12
12
13
-
{% code title="HTML - \(index.html\)" %}
13
+
{% code title="HTML - (index.html)" %}
14
14
```markup
15
15
<!DOCTYPE html>
16
16
<html>
@@ -47,7 +47,7 @@ The required libraries are also loaded. _Tabletop.js_ enables you to use a back-
47
47
48
48
Below is the minimal Javascript needed to get started. The `setup ()`function starts automatically once the page loads in the browser and simply loads the _Rivescript_ file as your chatbot script to get things started.
49
49
50
-
{% code title="JS \(script.js\)" %}
50
+
{% code title="JS (script.js)" %}
51
51
```javascript
52
52
functionsetup() {
53
53
chatbot.loadFiles(['bot.rive']);
@@ -61,7 +61,7 @@ window.onload = setup;
61
61
62
62
The script below determines how your chatbot will converse with a visitor. The `+ start` is automatically started to get the conversation going. The `+ *` is a wildcard that catches anything that you have not programmed your chatbot to recognize. At first your chatbot recognizes little, but we will work on that soon.
63
63
64
-
{% code title="Rivescript \(bot.rive\)" %}
64
+
{% code title="Rivescript (bot.rive)" %}
65
65
```javascript
66
66
// conversation script is below
67
67
// "start" auto-runs to begin the bot conversation
@@ -78,7 +78,7 @@ The script below determines how your chatbot will converse with a visitor. The `
78
78
79
79
There is a lot going on here with the styling of the chatbot. Use the code below as your starting point, but you may choose to change some elements later. A simple way to customize the look would be to change the _background_, _font-family_, and _color_ of the body element.
Copy file name to clipboardExpand all lines: docs/warm-up-project-outline/3-get-familiar-with-rivescript.md
+9-4Lines changed: 9 additions & 4 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -4,19 +4,24 @@
4
4
5
5
Develop a chatbot script that demonstrates several useful features and patterns in programming a conversation.
6
6
7
+
{% hint style="warning" %}
8
+
Any direct links to headings within the Rivescript documentation no longer work. Therefore, you will want to do a search for a keyword in the browser to find the content. We will update this page if we find a better way to link directly to the desired location in the Rivescript documentation.
Let's get familiar with the syntax of RiveScript and how it will provide the logic of your chatbot. For each item below carefully look at the documentation for RiveScript to understand the options available to you as you determine what is possible with your chatbot.
10
16
11
17
1.**Read first section of**[**The Code, Explained**](https://www.rivescript.com/docs/tutorial#the-code-explained)**in the Rivescript documentation.** Pay close attention to the "Important Note" in the reading that describes the importance of using lowercase with triggers.
12
18
2.**Create four**[**random replies**](https://www.rivescript.com/docs/tutorial#random-replies)**to "hello" for your chatbot.**
13
-
3.**Define a single trigger \(a trigger is the user input that starts with a "+" in the script\) that will respond to these two user questions** - "What do you do?" or "What can you do?" with a bot answer that you choose. For example, you could respond to the user with "I do very little at the moment." Hint: use the ["alternatives and optionals" in RiveScript](https://www.rivescript.com/docs/tutorial#alternatives-and-optionals).
19
+
3.**Define a single trigger (a trigger is the user input that starts with a "+" in the script) that will respond to these two user questions** - "What do you do?" or "What can you do?" with a bot answer that you choose. For example, you could respond to the user with "I do very little at the moment." Hint: use the ["alternatives and optionals" in RiveScript](https://www.rivescript.com/docs/tutorial#alternatives-and-optionals).
14
20
4. Use [a redirection](https://www.rivescript.com/docs/tutorial#redirections) to your "hello" trigger when the user inputs "Hey". Basically, make your bot respond the same way to _hello_ or _hey._
15
-
5.**Create a reply to "My name is Sue" \(or any name\).** In your chatbot response, use the person's name---like, "Nice to meet you Sue, my name is ChattyBot." Hint: Use an [open-ended trigger with a wildcard](https://www.rivescript.com/docs/tutorial#open-ended-triggers).
16
-
6.**Have your bot kick-off the conversation with**_**a question**_**when it starts so the visitor knows how to continue the conversation.** Also, add the needed script to listen for a response to that question and respond. Take a look at [this example on short discussions](https://www.rivescript.com/docs/tutorial#short-discussions).
21
+
5.**Create a reply to "My name is Sue" (or any name).** In your chatbot response, use the person's name---like, "Nice to meet you Sue, my name is ChattyBot." Hint: Use an [open-ended trigger with a wildcard](https://www.rivescript.com/docs/tutorial#open-ended-triggers).
22
+
6.**Have your bot kick-off the conversation with**_**a question**_**when it starts so the visitor knows how to continue the conversation.** Also, add the needed script to listen for a response to that question and respond. Take a look at [this example on short discussions](https://www.rivescript.com/docs/tutorial#short-discussions).
17
23
7.**Finally, choose two other features of RiveScript syntax to implement in your bot.**
18
24
19
25
## ✓ Deliverable
20
26
21
27
Have your chatbot working with the features described above and be prepared to demonstrate and explain how it works.
0 commit comments