Create Your Own AI Chatbot in minutes with Rasa
Tags: tutorial, python, ai, chatbot
Published: 2022-07-02 13:12:01

AI Chatbots are an increasingly popular way to service your users. They allow you to field diverse UX requests without pages and pages of buttons for every possible thing that a user might need.

The issue, however, is that building and training an AI chatbot can be an incredibly burdensome task that oftentimes simply isn’t worth the effort.

[Rasa](https://rasa.com/) is attempting to change that. Rasa is an open-source tool to quickly create and train an AI chatbot for whatever purpose you need. You simply enter in near plain-english how you want your chatbot to operate, give it some example inputs, and then reap the benefits.

---

###Setting up the Demo

You can quickly setup a demo in minutes with the following commands(Make sure you have python installed):

**Setup the python environment and install Rasa via pip:**
```
python3 -m venv ./venv
source ./venv/bin/activate
pip3 install rasa
```

**Setup, train, and run the Rasa project:**
`Rasa init`


From there, Rasa will run the default chatbot in the command line for you to play around with


![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/dj846eao4pcxm8wvkpjc.png)

---

###How to Customize Your Chatbot

Okay, if you’re following along you might have realized that the demo bot is pretty limited, so how can we add more functionality?

There are five key components to build your Rasa bot:

1. NLU data
2. Responses
3. Stories
4. Forms
5. Rules

NLU(Natural Language Understanding) Data is the training data that you feed Rasa. You simply need give it examples of ways a person might say something, and then classify what those different messages mean into intents:


![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/faqgvuugdghrnn5c84kr.png)

Responses are the ways in which you want your bot to be able to respond:


![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/k0umqqbfzzi7c1kywpgy.png)

Stories are the paths that you want a conversation to be able to take:


![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/8227abtz5b92ckzagcnz.png)

Odds are you’re using your chatbot to collect some sort of data from users. Forms are the way you can structure requests that you need your chatbot to make and what to do when they successfully collect that information:


![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/hkhbsvfs22zggtd6bi0y.png)

Finally, rules are exactly what they sound like. They can place strict requirements on ways your bot should interact:


![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/v1jlfd2nct9llu6pzlnj.png)

After you edit all these parameters to customize your bot, make sure to retrain your bot with:

`rasa train`

---

###How to Deploy your Chatbot
So now that you have customized your bot, how can you actually use it? Among other ways, Rasa allows you to deploy your bot as an API!

We’d recommend using [Codesphere](https://link.codesphere.com/OI), an all-in-one web IDE and Cloud provider that allows you to deploy any app in minutes.

You can get your project setup in Codesphere simply by connecting the github repo and installing all the necessary dependencies through the command line.

When you are ready to deploy, simply run:

`rasa run -p 3000`

And the api will be running on port 3000.

We can then make post requests to the chatbot at:

`http://<host>:<port>/webhooks/rest/webhook`

With a json with the following format:

```
{

“sender”: “test_user”, // sender ID of the user sending the message

“message”: “Hi there!”

}
```

Note that Rasa will automatically track user sessions from senders with the same sender ID, and will even clear inactive senders after a given time period(1 minute by default).

Rasa even provides a customizable chat widget for easy embedding:

{% embed https://gist.github.com/LiorB-D/0614e7156bef52f8237f28efe1f3ce4a %}

Additionally, Rasa can be connected through Websockets, Slack, Telegram, and a myriad of other ways! You can learn more [here](https://rasa.com/docs/rasa/messaging-and-voice-channels)!

And that’s all it took to get our chatbot live!

Let us know down below what you’re going to use your chatbot for!

Happy coding from the Codesphere team!