Back to basics: How Do Chatbots Work? 

read original story here

simone puorto - chatbot

At a glance, a chatbot can look like a normal app. 
There’s an application layer, a database, and APIs to call external services. 
The main thing that’s missing is the UI, which in the case of a bot is replaced by the chat interface. 
While this setup is convenient for users (that’s why chatbots are on the rise, after all), it does add a layer of complexity for the app to handle. 
Without the benefit of a rich interface that allows a user to input specific, discrete instructions, it falls on the app to figure out what the user wants and how best to deliver that.

Unlike normal app inputs, human language tends to be messy and imprecise. 
That’s where the NLP engine comes in. 
Made up of a number of different libraries, the NLP engine does the work of identifying and extracting entities, which are relevant pieces of information provided by the user.

For example, let’s take a simple bot, one that only does one thing: Orders takeout. 
When someone texts the message “order a pizza,” the bot would hopefully recognize the command (“order”) and the request (“pizza”). 
While these techniques alone might allow a chatbot to understand basic commands, they’re a far cry from actually understanding the structure and purpose of language.

What if you’re trying to build a bot that’s a more generalized assistant rather than a text-powered version of a simple web app? 
For that, your bot is going to need to understand context and intent. 
To establish context and intent, you’ll need some additional NLP tasks that allow the NLP engine to understand the relationships between words. 
For example, the sentence “please deliver a large veggie pizza with no mushrooms” might confuse a more basic bot that can only process simple commands, but our dependency parser would hopefully recognize that “no mushrooms” is meant to modify “veggie pizza.” 
Understanding context and intent allows bots to understand and act upon a much wider array of actions, or even ask the user additional questions until they understand the request. 

Like most apps, your chatbot will probably be connected to a database. 
Unlike many apps, however, your chatbot probably won’t be producing discrete, easily parsed metrics like what buttons users clicked on or how long they stayed on a certain page. 
For this reason, many chatbots are natural candidates for NoSQL databases. 

As we’ve seen, the basic structure of a chatbot is not so different from a typical app. That said, chatbots have very different requirements than web or mobile apps. 
Where other apps can be feature-rich and complex, chatbots should be fast and lightweight. 

Wit.ai (owned by Facebook) and API.ai are both platforms that allow you to create question-and-answer chat routines (called “stories” or “flows”) to “train” your chatbot to recognized normal requests and entities. 
Once you’ve created these routines, the services will use machine learning to teach your bot to recognize similar routines and requests, based on data gathered from other bots on their platforms.