This tutorial demonstrates how to seamlessly continue after a fallback on the Resolution bot to a suggested list of search results from a Knowledge base (Wikipedia).
Chatbots training is a long journey, it requires weeks, months and probably years to reach a very good level of satisfaction. You will never waste your time investing effort on improving your chatbot training, but it's worth to have some sort of integration between your chatbot and your already existing knowledge bases (KBs). The scope of this tutorial is to always reply on a fallback intent with some articles got from some knowledge base, so that the user will find, as often as possible, useful replies to his questions. The strategy exposed in this tutorial is to use the words in the user question to search in a knowledge base (i.e. Wikipedia) every time a fallback event occurs. From the programmatic point of view, every time the chatbot replies, it includes the original user question in a special payload of the reply message as well as the last intent name, confidence level and isfallback flag. With a webhook intercepting each reply, it's easy to trigger a search on the KB if the fallback flag is true or the confidence is not good enough.
Create a free Tiledesk account. Then create a new Tiledesk Project. Name your project as you prefer. We used the name "Fallback to Search tutorial" for this tutorial.
Skip with their default values all the other steps during project creation, and just land on the project's dashboard.
Now move on the sidebar and choose the Settings > Bots section. Press the Add bot button. Choose Resolution
Now choose a name and a description for your chatbot:
When asked, Activate this bot.
Optionally you can further configure your bot (i.e. choosing a profile image, improving training etc.) but we'll skip these steps, opting to focus on the Wikipedia integration. Target of our chatbot is, every time a fallback event occurs, using the question phrase of the end user to trigger a search on Wikipedia, showing the results to the user.
The source code used in this example is available as a replit application here.
The source code is also available on Github here
Fork the application in your own repl (or on your own server) so you can modify the code, primarily with the scope of connecting your own Knowledge Base (Wikipedia here is just used as an example).
Choose a new name for the application. We used my-chatbot-fallback-to-search, but you feel free to use your preferred name.
Once the application is forked, press the Run button on the top bar, as in the following picture:
Once our Replit app is up and running, we can move to the Webhooks section of your project. Select Settings > Project settings > Developer > Webhook as in the following picture:
Now press Manage Webhook then Add Subscription
Select Message create event from the menù and type the following endpoint url:
https://mychatbot-fallback-to-search.YOUR-REPL.repl.co/webhook/search
After this subscription your endpoint will be notified about every message sent on your proect.
Before going deep into the mechanics of the tutorial, we can already see it in action.
From the top of your dashboard press the green button "Simulate visitor". A page with a widget appears. Just start a new conversation. If you type Hello the bot will reply with the trained intent:
Now type in something that the chatbot is not trained to reply to (i.e. 'quantum field' or whatever you like)
As you can see the bot initially replies with the default fallback phrase, immediately followed by a new reply with a suggested list of Wikipedia results.
The proposed buttons are link-buttons. Pressing the button will open the Wikipedia article in the browser.
Enjoy Tiledesk!