In this tutorial, you will create a simple chatbot to check if the user entered an animal or a location or both: if an animal, the chatbot will display a “fun fact” about the animal by calling an API; if a location, the chatbot will display a Google map by calling a webhook.
The Consume API Service option is used when you need to call an API service and capture the results to be used in other actions like messages or other API calls. You can send any body content you want, and the returned JSON is returned in the api_service_response variable, which you can then use in other actions.
The Call Webhook option is used when you need to create more complex middleware. By default, the entire conversation context JSON is sent (for POST requests), and the webhook must return JSON in the format that can be displayed in the chatbot UI (see Getting Response Using Webhook). The next tutorial in this group will show you how to create your own webhook designed to be called from a chatbot.
From a feature point of view, the 2 ways of calling an API are the same except:
A webhook is automatically sent the conversation context JSON (for POST requests) by default.
A webhook must return JSON that conforms to the SAP Conversational AI UI protocol.
You will create a very simple bot that lets the user specify an animal or a location.
Create a new bot and call it apidemo. Use the following values:
Field Name
Value
1. What do you want your chatbot to do?
Perform Actions
2. Predefined Skills
None
3. Create your bot
Name: apidemo
Description: A bot to test APIs and webhooks
Language: English
4. Data Policy
Non-personal and Non-vulnerable
5. Bot Visibility
Public
Click Create Bot.
In the Train tab, create an intent called ask, and add the expression I’m interested in.
Since we define only one intent, this intent will always be triggered when the user types in a message.
In the Train tab, create a restricted entity called animal and add 4 valid values: cat, horse, snail, dog.
Restricted entity
Open the Test tab and test the bot. No matter what you type the intent will be ask.
Enter dog and it will recognize the animal entity.
Animal
Enter New York City and it will recognize the built-in location entity.
Location
Step 2Add a skill
+
In the Build tab, create a skill called answer, and open it.
Under Triggers, set the condition to: If @ask is-present.
Under Requirements, specify both #animal and #location, and make the logical operator Or.
Requirements
Click the New Replies, and add the following text message, and then click Save and Back:
Message
I can give you info on an animal, or a map of a location.
Enter an animal or a location.
This message is displayed if the requirements are missing.
Open Chat with Your Bot.
Enter anything that is not a location or animal, like Hi. This will trigger our skill but not contain the requirements, so the reply when the requirements are missing will be sent.
Then enter one of the animals. Now the requirements are met but we did not define a reply so the default reply No reply is sent.
Skill test
Step 3Add an API Call
+
Now you will call an API to return an a fun fact about the animal you specify.
Onto the URL we use the scripting syntax to append the animal from the memory. The animal is in memory because the memory contains all the required entities we added to the skills.
Under Response, enter for the namespace: funfact
Click Save.
Add API call
Click Send Message, select Text, and set the message text to:
Message
{{api_service_response.funfact.body.text}}
Click Update Conversation | Reset Conversation, and click Save.
We reset the memory so that you can enter a new animal. Otherwise, the chatbot would use the existing value for the animal entity.
Click Update Conversation | Reset Conversation, and click Save.
Webhook
Notice that for the webhook you did not create a message. That’s because the webhook provides the response in the syntax SAP Conversational AI understands – see Getting Response Using Webhook. Of course, you could provide additional messages in this message group.
Step 6Test webhook call
+
Open Chat with Your Bot, and enter a location, like New York City.
Webhook test
One more feature: You can define the base URL to be used in both API and webhook calls. Go to the chatbots Settings | Versions | <version> | Bot Builder.
Then, for the URL for each API or webhook call, you could enter just the route, starting with /.
Share feedback on this tutorial or join the conversation in SAP Community.
Submit detailed feedbackDiscuss in Community
Steps
Step 1 of 7
1. Create a simple chatbot2. Add a skill3. Add an API Call4. Test API call5. Add webhook call6. Test webhook call7. Test yourself
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.