SAP Home Learn Build Integrate Model Operate Extend with AI ConnectTutorial navigator Knowledge Graph API Devtoberfest Developer Advocates App Space

Manage my Account SAP Devs YouTube ↗ Learnings ↗ Community ↗ Provide Feedback ↗
Logout
โคข Open full site

Consume API Services and Call Webhooks from Your Chatbot

Call APIs or webhooks from within your chatbot to retrieve information or create UI elements for your conversation.

Overview

🎓 beginner 15 min. SAP Conversational AiBeginnerArtificial IntelligenceMachine LearningSAP Business Technology Platform

You will learn

  • โœ”How to call an API from your chatbot
  • โœ”How to call a webhook from your chatbot
Unknown U Unknown November 4, 2022
Created by September 22, 2021
Contributors

Prerequisites

Prerequisites

Steps

Intro

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.

For more information on making calls from your chatbot, see Connect to External Service.


Step 1 Create a simple chatbot
โ€”

You will create a very simple bot that lets the user specify an animal or a location.

  1. Create a new bot and call it apidemo. Use the following values:

    Field NameValue
    1. What do you want your chatbot to do?Perform Actions
    2. Predefined SkillsNone
    3. Create your bot
    • Name: apidemo
    • Description: A bot to test APIs and webhooks
    • Language: English
    4. Data PolicyNon-personal and Non-vulnerable
    5. Bot VisibilityPublic

    Click Create Bot.

  2. 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.

  3. In the Train tab, create a restricted entity called animal and add 4 valid values: cat, horse, snail, dog.

    Restricted entity
    Restricted entity

  4. 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
    Animal

    Enter New York City and it will recognize the built-in location entity.

    Location
    Location

Step 2 Add a skill
+
Step 3 Add an API Call
+
Step 4 Test API call
+
Step 5 Add webhook call
+
Step 6 Test webhook call
+
Step 7 Test yourself
+

Resources

Discussion

Share feedback on this tutorial or join the conversation in SAP Community.

Submit detailed feedback Discuss in Community
Steps
Step 1 of 7
1. Create a simple chatbot 2. Add a skill 3. Add an API Call 4. Test API call 5. Add webhook call 6. Test webhook call 7. Test yourself

Learn more →