Welcome to the community, Naim
This is a very interesting use-case! But your problem is that entities (e.g. “19.6V charger”) are not defined in a list or have a specific pattern. It could literally be anything.
So a more suitable bot for you would be a rule-based bot, not a machine learning bot like Rasa. Of course, you could do that with Rasa, using payloads, but this completely removes the AI part.
If you want to use Rasa, here is what you can do:
1. Transform messages to payloads
What you could do is transform your messages to payloads from your front-end application.
For example: Find the 19.6V charger
→ /find{"object": "19.6V charger"}
.
I think this would be pretty easy to do. You could make a dropdown list with the keywords, and an input textbox for the object name.
2. Send it to Rasa
Now, send this message from your frontend to Rasa using the Rasa REST API.
// POST http://<host>:<port>/webhooks/rest/webhook
{
"sender": "Naim",
"message": "/find{\"object\": \"19.6V charger\"}"
}
3. Define rules for the intents
You should do that step while coding the bot, so technically that should be before the other two, but I’m going through the process in the same order as the bot.
Define rules that link every intent to their specific custom action (more on that later).
Of course, you could send all intents to the same action and handle the logic there since it would be easy to do so. Usually, you should not do that, but it’s kinda okay in your case. Still wouldn’t recommend it.
So build rules like so:
rules:
- rule: Place
steps:
- intent: place
- action: action_place
- rule: Note
steps:
- intent: note
- action: action_note
etc.
4. Query the database
The actions (action_place
, action_note
, etc.) are custom actions, which are regular Python code.
In a custom action, you can access the tracker to check info about the conversation and latest message, such as the entities.
Once you are in a custom action (e.g. action_find
), make sure you have the correct entities present:
class Find(Action):
def name(self):
return "action_find"
async def run(self, dispatcher, tracker, domain):
obj = next(tracker.get_latest_entity_values("object"), None)
if obj is None or obj.strip() == '':
# handle if the "object" entity is not present
dispatcher.utter_message('Please say what you want to find')
else:
# write your own code to find the object in your database or however txtai works
response = find(obj)
dispatcher.utter_message(f'The location of "{obj}" is: {response}')
return []