hubtype / botonic

Build chatbots and conversational experiences using React
https://botonic.io
MIT License
521 stars 76 forks source link

plugin-flow-builder: resolve keywords, smart intents and intents in first interaction #2853

Closed Iru89 closed 3 months ago

Iru89 commented 4 months ago

Description

If the user sends a text that matches a keyword, smart intent or intent in the first interaction, the bot's response is the contents of the start conversation followed by the contents of the match.

If the bot has an active knowledge base after trying to match the above and not getting a match, it will attempt to respond using the knowledge base. If it has sufficient knowledge and the response is faithful the bot will display the start contents followed by the response generated using the knowledge base.

Context

We want the bot in platforms that are not proactive (such as Whatsapp) where the user is the first to write, if the user asks something in the first inbox, the bot will solve it the first time. But the initial contents have to be shown because they usually contain the GDPR and the AI disclaimer.

Approach taken / Explain the design

I have created a function that replicates the logic used in the plugin's pre function to resolve the user input. In the pre function if it is the first interaction the user input is not resolved because we always want to show the first contents of the flow. Refactor the ways to get the content in the action by splitting into different files how the content is obtained depending on whether it is the first interaction, has a payload in the input, uses a knowledge base or is the fallback. In the first interaction file, the other methods for resolving the follow ups are used.

Testing

Add test to check first interaction with: