Messenger Platform — Built-in NLP
You have probably heard about the release of Messenger 2.1 version which introduces some interesting new features. Built-in NLP is a feature added with the new release which deserves some attention if you are planning to build a messenger chatbot. Why so? Because every chatbot should have an NLP back-end to extract the user intent and the intent decides what action that is to be done with respect to each user message. Let’s take a look into the two cases; with and without using built-in NLP
Without built-in NLP
Let’s look into the scenario that we used “before the launch of messenger v2.1”.
It is clear that with each user message the bot has to make a request to the NLP service to identify the user intent. Then the intent along with the entity values are passed to the bot engine, where the response is processed and send a reply to the page with respect to the user intent. This creates some latency issues because with each user input we have to request an NLP API backend. At that time we have no other option but to tolerate the latency problem. Even though Facebook has its own NLP back-end, named wit.ai, we have to make the request explicitly.
With built-in NLP
Now, use the built-in NLP service. Enable the feature in your Facebook app (which can be found in “Messenger” option in the app dashboard). Now the work flow will be like:
Thus enabling the built-in NLP helps us to get the meaning and intents of each message that the user sends. The built-in NLP response which comes with the user message under the field “NLP” will look like :
The built-in NLP feature uses Facebook owned wit.ai to detect the meaning and mark the entities that identified. If we keep the field named Wit Token empty, built-in NLP service detects only ‘Greetings”, “Thanks” and “Bye” entities in English. So to make the feature more reliable create an app in wit.ai, define entities in it and use the wit token while enabling the built-in NLP feature to detect the custom entities that you want to use.
Customize Messenger’s built-in NLP
The response from the built-in NLP depends on how you configure your wit app. You can train your wit app to handle more user actions and code your own logic to send a proper response according to the user input instead of echoing back the message. For example, create an app in wit.ai for a restaurant for online food ordering. Define entities of such an app(eg: add_product, remove_product, clear_cart etc.). Suppose we have an entity defined “show_cart” which is trained to identify the action as “Show user cart”.
Now test it out, go to Messenger and type “show cart”. We will get the following response as the result of built-in NLP:
"value": "show cart",
Here the “Wit.ai’ identifies the user action as ‘show user cart” and the identified entity along with its confidence value is returned with the user message. The message received by our bot will look like this:
"text": "show cart",
"value": "show cart",
If the NLP detects multiple entities in the user text, there may have more than one field under “entities” key. Thus it provides us an option of selecting any entity that is retrieved.
As we see, the built-in NLP makes the task a lot easier because we can concentrate more about the logic that needed to perform the user action. We need not be worried about extracting user entities which will be available along with the received message.
Onchatbot is a chatbot development agency from India. We develop chatbots for e-commerce, real estate, restaurants, pizza stores, colleges, universities etc. You can read more about us here https://www.onchatbot.com/
Jyothish G (Chatbot Developer @ Onchatbot.com)