I got this question from a reader:
Let's say I have a BlackListWord entity that I use in template mode for capturing sentences with curse words. If I say "f**king" or "f**k you" the bot is gonna catch it. But if I get to say something like "the end of the f**king world" it takes me to the fallback intent. How could I manage to my intent to be triggered by every occurrence of a BlackListWord regardless of the sentence it is in? I don't see how the official docs could help. I've already searched the web but I couldn't find many discussion threads. Then I thought I'd find something here–as I always do–but I think that this hasn't been explored in a post yet. Maybe it's too newbie, or maybe not. I don't know–but I'd really appreciate any help. Thanks!
Once you read this article, you might see why it is awkward for people to write about this topic. 🙂 However, if you have ever deployed a bot, you know that you will be handling this issue at some point. So here goes...
The @sys.any wildcard
If you weren't familiar with the @sys.any wildcard, it lets you capture ANY text that the user provides. Our general approach will be to use the @sys.any wildcard to capture everything else except the swear word.
Defining an entity for the curse words
So let us first create an entity called BlackList:
Swear Word Position in the sentence
Once we declare the entity and fill in the appropriate values, we can use the wildcard entity to capture the curse words no matter where they appear.
To do this, we will consider the following four possible phrases:
f**k this (swear word appears at the beginning)
I am f**ked (swear word appears at the end)
what a f**king joke! (swear word appears in the middle)
f**k (only swear word appears in the entire sentence)
Defining the intents
Now we will use the template mode and define 4 intents to handle these four variants. If the agent detects a curse word, it will let the user know by echoing the word as you can see in the text response section.
And to understand whether the agent is indeed capturing all these curse words, we will add a Fallback intent with an appropriate message.
Here are some screenshots to show how well the agent does:
You can see that it still misses a few words. My suggestion to handle these scenarios is to create another intent and add these exceptions directly into the intent.
Also, you can extend this approach to catch any keyword in a sentence, and not just curse words.
Have a question?
Ask here. (Note: if the question is too broad for a single article or doesn't fit the scope of this blog, I may not be able to answer it. In that case, I will let you know the reason via email).
- Dialogflow Knowledge Connector : Pros and Cons
- How to integrate Telegram with Dialogflow
- Why I avoid using slot filling (required parameters) in Dialogflow
- Free Tool: Convert your WordPress website into a Dialogflow FAQ chatbot
- Dialogflow Mega Agent Tutorial
- Reader Question: Will followup events work when an intent has an input context?
- How to learn Dialogflow in a week
- Reader Question: Do I need a contextual fallback intent for every single context?
- Reader Question: Can I use a single agent for Facebook, WhatsApp and website bot?
- Five ways to integrate a Dialogflow chatbot into your website