“Hello World”, chatbot version — Complete example

“Hello World”, chatbot version — Complete example

Hello World for chatbots

The Hello World program is the typical first example you see when learning any programming language since it was first used in a tutorial to learn B (predecessor of the C language) in 1973. It is often the first program written by people learning to code. Its success resides in its simplicity. Writing its code is very simple in most programming languages. It’s also used as a sanity test to make sure the editor, compiler,… is properly installed and configured. For these same reasons, it makes sense to have a “Hello World” version for chatbots. Such bot could be defined as follows:

A Hello World chatbot is a chatbot that replies “Hello World” every time the user greets the bot

So something as this:

While this chatbot is indeed simple (compared with any other chatbot), it’s much more deceitful than its Hello World counterparts for programming languages. That’s because of the essential complexity of chatbot development. Even the simplest chatbot is a complex system that needs to interact with communication channels (on the “front-end”) and the Text Processing / NLP engine (in the “backend”), among, potentially, other external services. Clearly, creating and deploying a Hello World chatbot is not exactly your typical Hello World exercise.

Chatbots are complex systems

But don’t be scared, let me show you how to build your first chatbot with our open-source platform Xatkit. Our Fluent API will help you to create and assemble the different parts of the chatbot. Let’s see the chatbot code you need to write.

Recognizing when the user says “Hi”

The chatbot needs to detect when the user is greeting it. This is the only intention we need to care about. So it’s enough to define a single Intent with a few training sentences. Any NLP Provider (e.g. DialogFlow or nlp.js) would do a good job with this simple intent.

Trending Bot Articles:

1. The Messenger Rules for European Facebook Pages Are Changing. Here’s What You Need to Know

2. This Is Why Chatbot Business Are Dying

3. Facebook acquires Kustomer: an end for chatbots businesses?

4. The Five P’s of successful chatbots

Replying Hello World

To process the user greetings text, we need at least one state that replies by printing the “Hello World” text. But to keep the bot in a loop (who knows, maybe many users want to say Hi!), we’ll use a couple of them.

Configuring the chatbot

As we mentioned above, chatbots come with some inherent essential complexity. At the very least, they need to wait and listen to the user on some channel and then reply to the same channel. In Xatkit, we use the concept of Platform for this. In the code below, we indicate that the bot is displayed as a widget on a webpage and that it will get both events (e.g. the page loaded event) and user utterances via this platform.

And this is basically all you need for your Hello World chatbot!. Feel free to clone our Xatkit bot template to get a Greetings Bot ready to use and play with.

Of course, this is a very simple Hello World chatbot (e.g. what about if the user does not say Hi but something else?) but I think it’s the closer we can get to the Hello World equivalent you’re so used to see for other languages. Remember you can head to our main GitHub Repo for more details on Xatkit or check some of our other bot examples.

Don’t forget to give us your 👏 !

“Hello World”, chatbot version — Complete example was originally published in Chatbots Life on Medium, where people are continuing the conversation by highlighting and responding to this story.