Creating a Chatbot

Learn how to build your very own chatbot

Chatbot

Comments

When you see // it means that the statement is a comment. A comment has no effect on the chatbot.

Call and response

First you need a trigger, indicated by +. (should be lowercase). This is what the person needs to say to ellicit a response Then you need a response, indicated by -. This is what the bot will respond back to you. Here is an example:

+ hello
- Hey how are you?

Multiple responses

You can also include multiple responses to a single trigger. Just add more lines with -.

+ i am doing well
- Glad to hear it.
- I am glad you are doing well
- I am happy you are doing well

Multiple inputs or calls

You can also have multiple statemets lead to a response. You use one trigger and use parenthesis () and seperate statements by a pipe |

+ (how are you doing?|do you have any plans?)
- I am looking forward to the weekend.

Catch all input or call

Up until now, your triggers only elicit a response if the student inputs the trigger exactly If the student does not use an exact trigger to cause a response you will need a catch all trigger Here is a catch all trigger, indicated by a single wildcard *. It will be used when the bot did not find a matching trigger.
Using the responses listed below are good examples to cause the student to retype their phrase.

+ *
- I'm sorry I dont understand.
- Could you ask that a different way.

Advanced chatbots

Keywords

If you only care about certain key words in a trigger you can use '[*]' before and after the key words This allow the trigger to work even if a student input does not exactly match the trigger For example, if you only care about the words 'hello bot' to initiate a chatbot you can use the following command

+ [*]hello bot[*]
- Hello human

By adding [*] it only needs to find hello bot to run. For example if a student said 'hello bot how are you?' the chatbot would respond. If you did not use [*] the chatbot would not respond or would respond with the catch all response.

Variables

Variables can be used to allow the chat bot to remember certain parts of information from responses.

  1. The trigger needs to identify what information will be a variable with a wildcard. Use * for words/numbers, # for numbers only, and _ for words only.
  2. You need to set the variable name in a response. Use <set variablename=<star>>
  3. Finally you can use the varaible in any response with <get variablename>

Example:

+ my name is *
- <set name=<star>>It's nice to meet you <get name>.

Another example

+ i am # years old
- <set age=<star>>I will remember that you are <get age> years old.
+ how old am i
- You are <get age> years old.

Topics

Topics act similar to loops in other coding languges.
If you have no coding experience, topics/loops are like a room. Once you enter a room, you are stuck there until you exit the room with the proper door/ key. Topics can be a way to organize your code or allow your chat bot to wait for the proper input. A topic needs a way for entering the topic, content in the topic, and a way to leave the topic

Format:

+ key phrase to enter
- {topic=name} // The key to enter the topic called name. Place at the end of a response response
> topic name // Signifies the start of the topic
+ key phrase to leave and enter another topic
- {topic=anothertopic} // Place at the end of the a response. "anothertopic" send you to another topic called "anothertopic".
+ key phrase to leave and enter the general chat bot
- {topic=random} // Place at the end of the a response. "random" send you to the general body of the chatbot.
+ Other input
- Other response
< topic // Signifies the end of a topic

Example:

+ my name is *
- <set name=<formal>>Nice to meet you <get name>. Are you ready to play a game {topic=start}
> topic start
+ [*] yes [*]
- Hooray! Do you see the picture? {topic=picture}
+ no
- Are you sure you do not want to play?
+ *
-I could not understand. Are you ready to play a game?
< topic
Nualang

Nualang
3-4 Joshua Lane, Dublin 2, Ireland

info@nualang.com

Social Media

TwitterlinkedinInstagramFacebook

© Nualang™, 2020. All rights reserved.