12 Channels

Rule Based Chatbot Using Rivescript – Easy Guide 2022


Often seen as the next big thing in customer service, chatbots are computer programs designed to simulate human conversation. Businesses are turning to chatbots to provide a more efficient and cost-effective way to handle customer queries, 24 hours a day, 7 days a week.

With the rise of chatbots usage comes the need for a better understanding of how to create chatbots that can actually be useful for businesses. In this article, we will cover everything you need to know to get started building your rule based chatbot. This includes setting up your development environment, creating intents and entities, training your chatbot, and deploying it to a production server.

Assuming you have basic knowledge of Rivescript (a simple scripting language for chatbots), we will go over each of these topics in more detail.

rule based chatbot
Source: Drift

Why use Rivescript for a Rule based Chatbot?

Rivescript is a simple, yet powerful scripting language specifically designed for chatbots. It is easy to learn and use, which makes it a great choice for those just getting started with chatbot development.

One of the key benefits of using Rivescript is that it allows you to create chatbots that can handle a wide range of customer queries without the need for human intervention. This is because Rivescript provides a way to define “rules” that the chatbot can use to automatically respond to customer queries.

One notable advantage of employing Rivescript for chatbot development is its superior scalability. As your chatbot garners more attention and grapples with additional customer queries, you can effortlessly append more rules to the Rivescript file. This facilitates the chatbot in handling an expanding gamut of customer queries more effectively.

Moreover, Rivescript is platform-agnostic, thereby enabling the creation of chatbots for diverse platforms, including Facebook Messenger, Slack, Telegram, and numerous others.

Conclusively, now that we have explored the vital benefits of Rivescript in chatbot development, let us examine how to commence with the process.

Rivescript code example

Setting Up Your Development Environment

To initiate your developmental journey, your primary action item necessitates the establishment of your developmental milieu. This undertaking encompasses the installation of the pertinent software and the configuration of your project structure in its entirety.


To build a chatbot, you will need:

A text editor or IDE. We recommend Visual Studio Code.

The Rivescript interpreter, rivebot. You can install this via npm: npm install -g rivescript

Your project structure should look something like this:


   ├── intents/

   │   └── …

   ├── entities/

   │   └── …

   ├── bot.rs

   └── config.js

Creating Intents and Entities

Once you have your development environment set up, you will need to create intents and entities for your chatbot.

When it comes to chatbot development, comprehending the nuances of intents and entity types is crucial. Allow me to elucidate. Intents, in a nutshell, refer to the myriad of things a user might say to your chatbot. Take, for instance, a user who desires to book a flight, or another user seeking assistance with their account; each of these constitutes an intent.

On the other hand, entity types are the various types of information that can be extracted from a user’s speech or text. Let me illustrate this with an example. When a user voices out the phrase, “I want to book a flight from New York to Los Angeles,” the entities that would be extracted from the speech would be “from” and “to.”

Now, to build your chatbot, you will need to create, at the very minimum, one intent and one entity type. My recommendation would be to start with a modest number of intents and entity types, and progressively incorporate more as you proceed.

To create an intent, you will need to generate a file in the intents/ directory. The name of this file should correspond to the name of the intent, with the “.intent” extension appended to it. For instance, if the name of the intent you desire to create is “book_flight,” the file name should be “book_flight.intent.”

Moving on to the contents of the file, it should contain a JSON object with two fundamental properties: “utterances” and “responses.” The “utterances” property should be an array of strings, encompassing various example utterances that would trigger the particular intent. Correspondingly, the “responses” property should be an array of strings, encompassing plausible responses that your chatbot can output.

Here is an example book_flight.intent file:


   “utterances”: [“I want to book a flight”, “Can you help me book a flight?”],

   “responses”: [“Sure, I can help you with that. Where would you like to fly from?”, “Of course. Let me know where you’re flying from and I’ll help you book a flight.”]


To bring into existence an entity type, you must undertake the act of file creation within the designated “entities/” directory. The nomenclature of this file ought to correspond to the entity type’s name, where the “.entity” extension is attached thereto. For instance, if your entity type corresponds to “location,” you must establish a file named “location.entity.”

The substance of the file ought to consist of a JSON object, composed of two properties, to wit: “values” and “synonyms.” The “values” property must contain an array of strings, which signifies the various potentialities that this entity type can assume. In contrast, the “synonyms” property must be constituted by an array of objects, each harboring a “value” property and a “synonyms” property. The “value” property necessitates a string value, whereas the “synonyms” property calls for an array of strings, which defines synonyms for the value.

Here is an example location.entity file:


   “values”: [“New York”, “Los Angeles”, “Chicago”],

   “synonyms”: {

       “New York”: [“NYC”],

       “Los Angeles”: [“LA”]



Training Your Chatbot

Following the successful creation of your intents and entity types, the training phase of your chatbot beckons. This undertaking necessitates the provision of training data for your chatbot to ingest and learn from.

The corpus of training data must be lodged within the bot.rs file, which is composed of Rivescript scripts. This particular scripting language is especially tailored to cater to the needs of chatbots.

Should you crave further insight into the Rivescript language, kindly refer to the following web address: https://www.rivescript.com/docs/tutorial

Contained within the bot.rs file are two pivotal sections, namely, “intents” and “entities.” The former ought to embody a comprehensive enumeration of every intent within your chatbot, with each intent specified on a new line, commencing with the plus sign, followed by the respective intent’s appellation. As an illustration:

+ book_flight

+ cancel_flight

+ change_flight

Allow me to elaborate on the entities section, which is a critical aspect of your chatbot development. It entails an enumeration of all the entity types present in your chatbot, with each entity type being specified on a distinct line. Furthermore, each entity type should commence with a “+” sign, followed by the name of the entity type. Allow me to expound on this with an example to cement your understanding:

Suppose you have an entity type named “food,” then the entities section for this particular entity type should be structured as follows:


This design ensures that your chatbot recognizes the entity type and can accurately extract the pertinent information from the user’s speech or text.

To further your comprehension on chatbot development, let me expound on the necessity of providing training data for each intent and entity type. This is achieved by including +trigger and -trigger lines for each intent and +value and -value lines for each entity type.

The +trigger and -trigger lines serve to indicate whether a specific utterance should trigger the intent or not. For instance, if your chatbot has an intent called “book_flight,” the following training data may apply:

Book Flight:

The initiation of a flight booking is feasible through the invocation of the “book_flight” intent by the user, as exemplified by the input “I’m looking to book a flight.” Conversely, inputs such as “I’m not interested in booking a flight” or “Can you recommend a good restaurant?” are deemed unsuitable for triggering the “book_flight” intent.

The “+value” and “-value” lines bear the responsibility of identifying whether a specific value is recognized as an entity type or not. To illustrate, assume you have an entity type dubbed “location.” The following training data could be relevant:


  • San Francisco => Yes, this value warrants identification as an entity type
  • SF => Yes, this value warrants identification as an entity type
  • I don’t know => No, this value does not warrant identification as an entity type

Further information on the subject of training data can be accessed through the subsequent link: https://www.rivescript.com/docs/tutorial/#training-data.

Deploying Your Chatbot

Once you have trained your chatbot, you will need to deploy it to a production server.

There are many different ways to do this, but we will cover the two most common methods: deploying to a web server and deploying to a conversational platform.

Web Server

The process of deploying your chatbot can be accomplished through myriad techniques. One particularly efficacious approach is to imbue it onto a web server, which furnishes you with the ability to integrate your chatbot onto a website or web application.

Multiple routes can be taken to execute this operation, but we will expatiate upon the two most prevalent techniques: utilizing a web framework and employing a headless browser.

Web Framework

A web framework, in its essence, is a software framework crafted to expedite the development of dynamic websites and web applications.

Numerous web frameworks are available to select from, but we will dissect the two most celebrated: Django and Ruby on Rails.

Django, a Python web framework, encompasses all the requisites required to engender a website or web application.

On the other hand, Ruby on Rails, a Ruby web framework, provides all the necessary components to formulate a website or web application.

Headless Browser

A headless browser, in essence, serves as a web browser that can be commandeered from a command line or script, giving rise to the option of running your chatbot sans a graphical user interface, albeit on a server.

In the realm of headless browsers, two prominent players come to mind, namely, PhantomJS and NightmareJS. The former, written in JavaScript, is a headless browser that has won the hearts of many. On the other hand, the latter, which is written in Node.js, is also a commendable headless browser.

Conversational Platform

Alternatively, you could opt to unleash your chatbot onto a conversational platform, which affords you the opportunity to interact with it through a chat interface. The likes of Facebook Messenger, Slack, and Telegram are just a few examples of chat interfaces.

Numerous conversational platforms are at your disposal, but we shall delve into the two foremost options: Chatfuel and Botpress. The former grants you the power to establish and supervise chatbots for Messenger, Slack, Telegram, and Kik, while the latter, which is an open-source conversational platform, permits you to create and manage chatbots for Messenger, Slack, Telegram, and Kik.

Having successfully dispatched your chatbot, it would behoove you to execute a series of tests to ascertain its proper functionality.

Testing A Chatbot

Within the realm of chatbot development, there exist a plethora of methodologies. However, in this discourse, we shall expound upon the two most prevalent modes of operation: manual testing and unit testing.

Manual Testing

The act of manually testing one’s chatbot is the process of ensuring that the bot’s functionality operates optimally according to its intended purpose. To execute this process, one can interact with the chatbot through its user interface. Additionally, one can initiate various commands or scripts against the chatbot to evaluate its proficiency.

Unit Testing

In contrast, unit testing involves crafting code that scrutinizes the chatbot’s functionality to determine its efficacy. This process can be accomplished through the utilization of a unit testing framework, such as JUnit or TestNG.

With the aforementioned data at your disposal, you are now equipped to commence the construction of your rule-based chatbot. It is our sincere desire that this article has been of benefit to you and that it will enable you to fabricate a chatbot that meets your precise specifications. If any inquiries arise, please do not hesitate to contact us at 12 channels.


Throughout the duration of this discourse, we have exhaustively discussed all of the requisite knowledge necessary to initiate the process of fabricating your rule-based chatbot. Additionally, we have furnished you with an array of practical tips to optimize your chatbot experience. The assimilation of this information empowers you to produce a chatbot that is tailored to your specific needs. We would like to express our gratitude for your readership.

Should you require any further assistance, we encourage you to book a call with our adept team at 12channels It would be our pleasure to assist you with the initiation of your chatbot project. Alternately, peruse our blog for an abundance of informative articles concerning chatbots and artificial intelligence.

Leave a Comment

Your email address will not be published. Required fields are marked *

Latest Articles

Sign up for our newsletter to get information, promo, or insight about the vehicle