Tiledesk Docs
Fallback to Knowledge-Base
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. We used Wikipedia as the placeholder Knowledge base.
Fallback to Knowledge Base example


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 even when the chatbot doesn't find a suitable reply.
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 intent 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 Knowledge base if the fallback flag is true or the confidence is under some predefined threshold.

Create a new project and configure your first Resolution bot

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.

Programmatic management of your fallbacks

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:
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. 'nasa' 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.
Fallabak intent triggers the search
The proposed buttons are link-buttons of type "self". Pressing the button will open the Wikipedia article in the Widget itself.
"self" buttons open the URL content in the Widget frame mode. In this mode the URL content appears into the same widget’s frame with a special header, showing the button title, a button to go back to the conversation and another button to open the content into a full browser window.
You can obtain the best results with "self" option if the content you are displaying plays good with the responsive mode, because of the small dimension of the widget makes it act with mobile-device-like responsiveness.
Please refer to the Widget JSON protocol specifications to learn more about Link Buttons.
You can try a "live" tutorial here. You can get the source code directly from the replit app.
If you have any problems do not esitate to write us on our Community forum!
See you on our next tutorial!
Do you have suggestions on this article? Please send us your feedback writing an email to [email protected]
Enjoy Tiledesk!