Create a Chatbot that Lets Customers Track Packages
With SAP Conversational AI, create a chatbot that calls an API, in this case to let customers track their packages, and see how to make use of the memory, using SAP Conversational AI.
The customer will indicate that they want to track a parcel
The customer will provide the package number
The customer will confirm they want to track the package
The bot will call an API to retrieve package info and display it
To price package:
The customer will indicate they want to price a package
The customer will provide the address (France only) and the size of the package
The bot will check that the address is in France, and then call an API to retrieve a map of the location
The bot will display the map, and provide a price for the package, based on its size
In this tutorial
In this tutorial, you will start by creating a bot that understands the customer’s intent to track a package, and understands when the user has provided a valid tracking number.
Description: A bot to help shipping customers track and price packages
Language: English
4. Data Policy
Non-personal
Store
Non-vulnerable
5. Bot Visibility
Public
Create bot
Click Create a Bot.
Step 2Create entity for parcel number
+
Our bot must be able to extract the parcel number from within the conversation. Such data extracted from a conversation is defined as entities.
The tracking number is based on one of UPS’s standards: 18 characters with constraints, as described in Tracking Number.
Under the Train tab, go the subtab Entities.
Go to Train
Click Create an Entity.
Call the entity PARCEL-NUMBER, specify it as a Regex entity, and click Create.
Create entity
Free entities: You specify the type of data it is, and you teach the bot how to identity a value for that entity. You specify the form of the data but not the actual acceptable values.
Restricted entity: You specify a limited list of acceptable values.
Click PARCEL-NUMBER.
Edit entity
Enter the following regular expression:
Regex
\b(1Z[0-9A-Z]{6}[\d]{10})\b
This defines only one kind of UPS tracking number, and is a simple regex that does not distinguish between the parts of the tracking number.
You can test some of your parcel numbers to make sure they match, for example, enter 1ZISDE016694068891 and click Test:
Test Regex
Built-in Entities
SAP Conversational AI comes with built-in entities (called gold entities) for common data, like location, dates, and money values. For more information, see List of Gold Entities.
Step 3Add intents for yes and no
+
Customers will have to indicate whether they accept or reject certain requests from the bot, so the bot needs to be able to recognize when a customer means “Yes” and when they mean “No”.
You do not have to create these yourself. Instead, you can fork them from others who have already created them.
Forking is simply copying, and does not create a relationship between your bot and the source of what you forked. You can fork intents, entities, skills or an entire bot. For more information, see Forking Bots, Skills, Intents, and Entities.
The API to get tracking information requires the parcel number in upper case, so this step automatically converts any input to upper case.
Here, we use Handlebars scripting to access the memory and execute the uppercase function. For more information on how to use scripting to access the memory and other conversation data, see Scripting with Variables.
Now you’ll add a second set of requirements – the user’s confirmation that they want to track the package.
Add a second requirement by clicking the plus sign ( + ) – the second one that when you hover it says Add a new list of requirements.
Requirements confirm
In the first field, click and select @yes.
In the second field (after as), enter yes (the name in the memory for this value), and press Enter.
Immediately under @yes, click the plus sign ( + ) and add the @no intent and store its value in the no variable. Press Enter.
Click the And between @yes and @no and change it to Or.
Click New Replies next to If @yes or @no are missing.
Missing yes or non
Then do the following:
Click Send Message.
Click Quick Replies.
For the message, enter:
Message
Do you want to track the parcel {{memory.parcel-number.raw}} ?
Above you added code to retrieve the parcel number from the memory – which stores all requirements, and any information you manually store there. For more information on the memory and syntax, see Memory Management.
Click Add Quick Reply twice, and:
For the first, add Yes for both the title and value.
For the second, add No for both the title and value.
Click Save, then click Back.
Yes and no reply
Step 8Add action to skill
+
Add the action if the user says No.
Go to the Actions tab.
Click Add New Message Group.
Message group
Click Add Condition, and then in the field next to If, select @no, and click Save.
Click Send Message, and then:
Select Text.
Enter No problem. Let me know anytime if you want to track a package. as the message.
Click Save.
Click Update Conversation | Edit Memory.
Update conversation
In the Unset memory field, enter no (the value is case-sensitive), and then click Save.
Unset No
Why unset No ?
This will make it so the skill no longer fulfilled the requirement of having a Yes or No answer. So now if the user changes their mind, they can enter track package and the conversation will already have the tracking number stored and will only ask for confirmation.
If the customer says Yes, then you will make an API call and retrieve the information to display. You will code this in the next tutorial.
Step 9Test the bot
+
If the Test panel is open, close it.
Click Chat Preview (bottom right) and start a conversation with your bottom. Use this tracking number: 1Z12345E6205277936.
In the example below, notice the bot detects the intent to track a package, but notices the tracking number is missing, and asks for it. Finally, it asks for confirmation, using the tracking number by retrieving it from memory.
Link text e.g., Destination screen
After the customer says No, this reply is unset in memory, so if the user again says track package, the bot simply asks for confirmation because the latest tracking number is still in memory.
Link text e.g., Destination screen
If the customer says Yes instead, for now the bot shows No Reply because you have not defined an action in this case.
Link text e.g., Destination screen
No Reply vs. Fallback Actions
When a bot has detected an intent and that intent triggers a skill, but that skill does not have an action that returns a message, then No Reply is shown.
If a bot cannot figure out the intent of the user, or no skill has been triggered by the detected intent, then the fallback skill is triggered. When you created your bot, a fallback skill was created automatically for you with a default message.
Share feedback on this tutorial or join the conversation in SAP Community.
Submit detailed feedbackDiscuss in Community
Steps
Step 1 of 9
1. Create skeleton bot2. Create entity for parcel number3. Add intents for yes and no4. Add intent for tracking parcel5. Create skill for tracking parcel6. Add requirement to skill (parcel-number)7. Add requirement to skill (yes/no)8. Add action to skill9. Test the bot
Joule
AI Notice
Joule is an AI assistant. Generative AI may produce inaccurate, incomplete, or biased information. Always verify important details before acting on them.
Conversations are sent to SAP-hosted large language models for processing. Do not include personal data, credentials, or confidential information in your messages.
Joule's responses are based on the SAP tutorial catalog and may not reflect the latest product changes. For authoritative guidance, consult the linked tutorials and official SAP documentation.