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

Build a Webhook for a Chatbot Using Python

Create a Python script (with Flask), deploy it to SAP Business Technology Platform, and use it as a webhook to be called by an SAP Conversational AI chatbot.

Overview

🎓 beginner 25 min. SAP Conversational AiBeginnerArtificial IntelligenceMachine LearningPythonSAP Business Technology Platform

You will learn

  • โœ”How to create a Python endpoint in SAP BTP, using Flask
  • โœ”How to read POST data from a chatbot
  • โœ”How to send back data to a chatbot
  • โœ”How to deploy a Python script to SAP BTP (using Cloud Foundry CLI)
  • โœ”How to connect the webhook to the chatbot
Unknown U Unknown November 4, 2022
Created by September 22, 2021
Contributors

Prerequisites

Prerequisites

Steps

Intro

You will create a very simple chatbot that asks the user to pick an animal, and then have the chatbot call a webhook, which will then call an API to retrieve a “fun fact” about the animal via the cat-facts API. The webhook will also update the memory variable that keeps track of how many times the user requested a fun fact.

The point of the tutorial is to show you how the webhook reads the request data from the chatbot, and to show you the format of the data that must be returned to the chatbot.

As an added bonus, we will show how to deploy a Python script to SAP BTP. Special thanks to Yohei Fukuhara for his blog Create simple Flask REST API using Cloud Foundry.

IMPORTANT: The focus of this tutorial is the response an application (API) must return in order to work with SAP Conversational AI. The requirements for Python on SAP BTP changes from time to time – e.g., quota, runtime – so you are encouraged to check the documentation for how to deploy Python scripts: Developing Python in the Cloud Foundry Environment


Step 1 Create a simple chatbot
โ€”

Create a bot that asks the user to select an animal to get a fun fact about.

  1. Create a new bot and call it webhookdemo. 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: webhookdemo
    • Description: A bot to test creation of 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 you 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. 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 #animal as animal.

    Expand the requirement and click New Replies – If #animal is missing, add the following text message, and then click Save and Back:

    Message
    Type an animal and I will get you a fun fact about it.
    
    But I am only familiar with certain animals.
  5. Click Train at the top of the page.

Step 2 Test the bot without webhook
+
Step 3 Create Python project
+
Step 4 Write Python endpoints
+
Step 5 Push Python script to SAP BTP
+
Step 6 Point chatbot to webhook
+
Step 7 Test chatbot
+
Step 8 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 8
1. Create a simple chatbot 2. Test the bot without webhook 3. Create Python project 4. Write Python endpoints 5. Push Python script to SAP BTP 6. Point chatbot to webhook 7. Test chatbot 8. Test yourself

Learn more →