Technical Articles
Capture any text during a conversation with SAP Conversational AI chatbot – Part 2
In this blog post, we will learn how to capture any plain text input from the user for which values are not defined in the entity.
This blog post is 2nd part of a series with the following parts:
- Part 1: Making a simple chatbot with SAP Conversational AI – Part 1.
- Part 2: Capture any text during a conversation with SAP Conversational AI chatbot – Part 2.
- Part 3: Connect your SAP Conversational AI Chatbot with NodeJS/Springboot service running locally – Part 3.
So let’s get started!
We will follow the following steps:
- Add the requirement in our skill.
- Configure the fallback skill.
- Update the reply from chatbot.
In part 1, we created a free entity “message”, which can be used to store the message(any random text e.g. Happy birthday John), to be written on the cake.
Step 1. Add the requirement “message” in the skill.
After adding the requirement, we have to tell the chatbot how to handle a scenario when any of these inputs are not given by the user. For that, we define a reply which chatbot sends to the user in case a particular requirement is missing.
To achieve this, click on the Chevron of the Message row:
You will see two options.
- If #message is complete.
- If #message is missing.
Click on the +New reply on if #message is missing.
Select send message and select text message. Add a message of your choice.
We are doing this because if we enter any random input in the chatbot for which an intent is not defined, then the fallback skill is triggered. And since we do not know what message a user might want to get on the cake, we do not have a scope for the message entity. Hence we set a flag when the user is asked to enter the message for cake and check the value of this flag in the fallback skill.
So we set the following value for a variable cake_message_set.
{"flag":true}
The reply will finally look like this:
Step 2: Configure the fallback skill.
Open the fallback skill and navigate to the Actions tab.
Here, we will add a new message group.
This message group will get triggered when the cake_message_set flag is set to true.
If _memory.cake_message_set.flag is true
We can now take the text entered by the user as the message to be written on the cake and set it in the memory. We then unset the cake_message_set flag.
To do this, click the button Update Conversation, from the drop-down, select Edit Memory.
The following fragment appears:
In the Set memory field section, enter the memory key as message with the following value:
{
"value": "{{current_message.content}}",
"raw": "{{current_message.content}}",
"confidence": 0.99
}
Then, in the Unset memory field section, enter the memory key as cake_message_set.
After this, we need to again trigger the main skill i.e. process-cake-order. For that, click on update conversation inside the same message group of fallback skill and click goto.
Then select the skill process-cake-order and press save.
The message group should now look like this:
Step 3: Update the cake-bot reply.
Let us now update the reply given by the bot to show the details of the message on the cake too.
Here are your order details:
Flavor: {{memory.flavor.value}}
Weight: {{memory.weight.value}}
Message on the cake: {{memory.message.value}}
Our bot is now ready. Let us test the bot.
Click on the button Chat with you bot on the bottom right corner.
Perfect! The bot is behaving as expected.
In Part 3 of this series of blog posts, we will learn how to connect the cake-bot to a backend service, where the orders can be processed.
See you in part 3.
Happy bot building! ?
Cheers.
Why not use the built-in feature for going to a skill and waiting for the user to provide input ("Wait for user input") instead of adding a flag and a message group in the current skill? Is there a time to use one vs. the other, or did I misunderstand that feature?
Hi Daniel,
As I have explained in the blog, we are doing this because if we enter any random input in the chatbot for which an intent/entity is not defined, then the fallback skill is triggered. And since we do not know what message a user might want to get on the cake, we do not have a scope for the message entity. For example "Happy Birthday", "Congratulations on your birthday", etc. If we use the "Wait for user input" feature, even then the fallback skill gets triggered. Hence we set a flag when the user is asked to enter the message for cake and check the value of this flag in the fallback skill.
I hope that answers your question. 🙂
Again, really nice blog -- almost finished part II.
Hi Daniel,
Thanks for trying out the steps. 🙂
I created the same (I think) this way:
I like this because (1) it uses the wait for user input feature; (2) it does not add functionality to the fallback skill — I was once told this should be reserved for only true fallbacks.
The only thing is I’m concerned that we were in the process_cake skill and then sort of in the middle we execute the skill “again” and maybe this messes up the skill stack — but I just don’t understand how it works underneath the hood.
P.S.: I did Part II again and again the text I enter for the message is captured as the message but it is also analyzed for intent and returns the fallback action. Was I supposed to delete the fallback message?
P.P.S.: On to Part III
Hey Daniel,
We can surely achieve the same functionality in the way as you have described. But that adds another skill in the skill set to process this particular requirement by a skill. So to avoid that, I decided to go with this approach of using the fallback skill.
Answering to your question, you can either insert an if condition to check whether the cake_message_set variable is defined or not, or you can delete the default fallback message. I hope that answers your question.
Thanks! 🙂
Very Nice Blog. Could you please suggest me any options available to download and upload our custom bots available . As I have developed my bots in my closed organization tenant.Want to deploy the same in clients tenant.
Don't want to develop it again.
Hi Subrat,
Kindly post the question at https://answers.sap.com/questions/ask.html for greater visibility and quicker help.
Thanks! 🙂
Hi Mr. Varun Kumar Saini
I have been following step by step the instructions of the blog, however, I am still getting the next response "I trigger the fallback skill because I don't understand or I don't know what I'm supposed to do.." from the Bot every time I enter the message for the cake.
Here I have my Requirements Configurations
And here my Actions Configurations
I would really appreciate it if you could please help me with this issue or give me some guidance
Thanks in advance and best regards!