How to make changes in the incoming query message from user

Hi guys! So I need to make changes in the user message before passing it to the nlu. Where should I make these changes? Actually, the use case is like. If I have2 companies using same bot and there are let’s say 1 module in my app named lead. But for…

company1- lead = hospitals company2 - lead = lead.

So when a user types.

q1. How many new hospitals found?

Then first i will get a module name for the user and match the module in the query. So now if a module matches with query like here “Hostpitals” == “Leads” …So I will change the hospital in query to lead and then pass to bot.

I can’t use synonyms because user keeps changing the module names. and I need something dynamic to match these.

Can someone suggest me a solution for this? @akelad @JiteshGaikwad @Juste

You could use a custom components which will be first in your pipeline and which will make the changes, maybe by requeting something to be dynamic ?

Do you have an example for this? what changes are you suggesting in pipeline?

Well I have a spell checker and it’s changing the message before passing to the rest of the NLU. It’s look like this :

class SpellCheck(Component):
    """ Component put at the start of the pipeline to spell check the user message."""

    name = "SpellChecking"

    def __init__(self, component_config=None):
        super(SpellCheck, self).__init__(component_config)

    def process(self, message, **kwargs):
        # Here you can access the message with message.text and then change it
        message.text = correction
1 Like