Skip to Content
Technical Articles
Author's profile photo sherine shibu

Step by Step process to create chatbot(Conversational AI) using Odata and integration with MS teams

Dear Community,

Welcome to my first blog. Hope you guys will find it informative.

Special thanks to a good soul Mahesh Palavalli for encouraging me to take this first step. I hope this blog will be helpful in being a stepping stone to jump-start with conversational AI(CAI) and provide a basic understanding of the same.

Due to the length of the document, I will break it down into 2 blogs.

  1. Creating a chatbot using Odata https://blogs.sap.com/2021/02/21/conversational-a…ation-with-teams/
  2. Integration of chatbot with Teams — coming soon

Let’s start our journey with CAI by creating an account in http://cai.tools.sap.

Once you log in to CAI you can view all similar blogs that give an understanding of how you can make your chatbot work under the blog tab – ( It has tutorials for beginners, intermediate, and advanced levels) – very informative as per my observation.

So what’s Conversation AI ? – refers to technologies, like chatbots or voice assistants, which users can talk to.

Here I would concentrate on creating a simple chatbot that would get a response from OData and how to integrate it with Microsoft Teams.

The objective of this blog post: To add a product

Step 1: Create a chatbot by clicking “+New Bot” in CAI.

It will show you two options as below: I selected the first option for my action bot.

1. Perform Actions –  Creates a bot that performs actions like approving leaves or booking tickets

2. Retrieve Answers – Creates a bot that answers data policies or answers frequently asked questions

Select the skills that you want your bot to inherit like I selected greeting( “It will respond to your hello”), small talk(“you say I love you, it will respond “), and customer satisfaction(“you can get a feedback for your bot “).

Name your bot ( I named it as(Product) ), give a description, select the topic that your bot will deal with, select the language(you can make your bot multilingual by adding a different language).

Then select the data policy, quite descriptive in itself ( ” Data policy also affects the visibility of the bot, as Personal(data policy) will have private visibility by default “). Health option of data policy is not supported in SAP hence in RED highlighted.

You can always change the settings of your bot anytime by clicking the settings.

Make your bot public, in case you want to share it with others.

Now that you created your bot, let’s train it.

Step 2: Create the Intents and Train your Bot

Intents: An intent is a set of expressions that mean the same thing, but are constructed in different ways.

you can actually search for any existing intent(created by you or others) or create your very new intent. I would be creating a new one here named ‘add-product’.

You will notice here that the greeting’s intents are already added as we selected greetings during our bot creation.

I added the Intent “add-product” with matching strictness 50, this means that if 50 % of our query text matches our intent, then our bot will correctly identify this intent. Added the expression under the intent as “Add new product abc”. Here “abc” is the custom-free new entity that I created. An entity can be gold( already provided by SAP like noun, pronoun, numbers, etc., custom free( as the name suggest it refers to the custom entity, in this case, it will represent any “product name” given), Regex entity( if you want some entity to be restricted like phone number having only numbers or email address) and restricted( if you want to restrict your entities with values like cheese entity is restricted by mozzarella cheese only or other types of cheese.

  1. Add expression: An expression is a sentence that your bot can understand. It will suggest you similar sentences or you can add your own new alternative sentence with the same meaning. This is how Natural language processing works(NLP). By default the language is English, you can make it multilingual by clicking on add language and assigning the corresponding expressions for the same. I added few statements, intending the same activity to add a product.

let’s test if our bot understands the expression with the test bubble on the right side. It correctly identifies the intent, when I said: “add product”.

The expression can be loaded with the entity(An entity is a keyword that is extracted from an expression) or we can create our own entity. Expand the expression and you will find an automatically detected entity.

Here #number is the gold entity.

Here #Prd is my custom entity.

 

Our Intent got created, now start training your bot by clicking on the BUILD tab to add the skill.

 

2. Add Skill: A skill is a block of conversation that has a clear purpose and that your bot can execute to achieve a goal.

You can create the following types of skills:

Skill type

Description

Business

Skills that are closely linked to the core purpose of your bot.

Floating

Small-talk skills, that is topics that are not closely related to the core purpose of your bot.

I am creating a Business skill named add-product.

Now skill has three tabs.

  • Triggers

    Triggers are conditions that determine whether the skill should be activated.

  • Requirements

    Requirements determine the information that the bot needs to retrieve from the user and how to retrieve it.

  • Actions

    Actions are performed by the bot (for example, send a message) when all requirements are complete.

Trigger: My bot will trigger the skill when it meets the below condition. Now that I made sure when my skill will be triggered, I move on to mention the requirement. I can add additional conditions by pressing the + symbol beside the delete button.

Requirement: I mention my intent(@add-product) as a product and provide a response for the same. I can use intent, entity, or memory variables in the requirement definition. If my intent is complete it will counter question the user to provide the details else it will ask to specify the request. So for that, I will click on +New Replies under both the option and provide the details as below.

Finally, it will look like below. Will expand both replies and show what I have entered.

If #product is complete: I have defaulted few memory values and also the value received from the entity #prd

selected the message type Text for the text entered “You want to add the product {{ memory.product.raw}}“. Here as you see in the above screenshot, I have named the entity #Prd as product, so this actually stores in the memory the value that we added in the entity. We can refer the value stored in memory via .raw or .value.

If #product is missing: I have added the below text.

Now that my requirements are over, I move to the Action tab.

What I did in the action tab

  1. added message-type text to get the product description.
  2. clicked on update conversation->edit memory to set the memory userinput to be true so that the bot waits for the userinput of the product description.
  3. clicked on update conversation->goto to trigger the skill userinput and set the value as wait for user input.

These actions are sequential(executed sequentially) and if you add anything below the Redirect(calling new skill), it will execute it without waiting for the user input , therefore when triggering user input skill or any other new skill , be sure you do not add any following action below it.

 

Skill: User Input( click on build again for creating the new skill)

I won’t go into details but would provide the screenshots of what I did in the following tabs.

  1. Trigger : checks if userinput memory variable is true.

  1. Requirements: didn’t add any requirement
  2. Actions:

1. Checked again if the userinput is true

2. mapped the value given by the user via nlp.source .

reset the userinput memory variable

3. Added the text message as “Do you want to add this product {{ memory.ProductName}} with description {{ memory.Description}} to the database ?”

the highlighting and boldness of the text can be managed by marking markdown syntax as enable and putting two ** prefixes and suffixes of the word to be made bold(shown below).

4. Set memory variable addproduct as true for user input to trigger the skill product.

5. trigger skill product and wait for user input.

 

Skill Product: (let’s move to the skill product which will add this product via OData post method and show the products via OData get method.

For a change, I made this skill as floating instead of business hence the yellow clour. Find below the things I did in this skill.

I won’t go into details but would provide the screenshots of what I did in the following tabs.

  1. Trigger: check if the memory variable addProduct is true.

2. Requirement: Added nothing

3. Action: Did the following

  1. Again checked for the addProduct variable to be true.
  2. Called oData post method to post the values that I got from the user to the oData URI provided.

https://services.odata.org/V3/(S(blacksheep))/OData/OData.svc/Products

The payload was passed with an ID that I defaulted as 12 and the rest of the details from the memory variable(just for test purposes and to show how post works 🙂 ).

3. Adding message as product posted

4. Unsetting the memory variable addProduct

5. Triggering skill  list-product but this time I am starting skill and not waiting for the user-input.

 

If id 12 in the payload is not working then add ID as 11 or get the count of the list and then add it as the id(play around with it  🙂 ).

How do you call the oData?

Follow the below steps.

  1. click connect External Service -> consume API service

By default the method will be post , maintain the method based on your need , remember it understands json , so the header should contain application/json. Moreover previously the get method needed explicit ?$format=json for the get method to work properly but now with updated version, this is not needed.

 

Skill list-product : This skill will directly list all the products received from the get method of oData URI “https://services.odata.org/V3/(S(blacksheep))/OData/OData.svc/Products/?$format=json”

for the trigger and requirement tab, I didn’t do anything but for the action tab, I added the following

Response of ODATA is received via api_response in the response tab of the API service.

By default, the value memory variable will contain the value received from the API. So you can see it being referred below.

I used custom list message type for listing my product details, by following the below step.

  1. Click on the message type
  2. Select custom type
  3. Select the list type from the dropdown and then edit the code to suit your needs( don’t be lazy as me, do it properly :).

Here is the edited version of my list.

{
  "type": "list",
  "delay": "2",
  "content": {
    "title": "Product List",
    "subtitle": "Product",
    "imageUrl": "",
    "total": "15",
    "upperBoundText": "",
    "buttons": [
      {
        "title": "Product",
        "value": "Product",
        "type": "postback"
      }
    ],
    "elements": [ {{#eachJoin api_service_response.default.body.value}}
      {
        "title": "{{Name}}",
        "subtitle": "{{Description}}",
        "imageUrl": "",
        "status": "Available",
        "statusState": "success",
        "description": "Rating {{Rating}}, Price {{Price}}",
        "ratings": "{{Rating}}",
        "price": "{{Price}}",
        "buttons": [
          {
            "title": "test",
            "value": "test",
            "type": "postback"
          }
        ]
      }{{/eachJoin}}
    ]
  }
}

PS: There is a limit of 10 for the list to be shown on screen. To test you can use skip=10 to find your items in the chatbot. Eg: https://services.odata.org/V3/(S(blacksheep))/OData/OData.svc/Products/?$skip=10

This ends my play around with the skills( I guess I pretty much covered all that needs to know about different objects in CAI … 🙂 ).

The final build screen will look like 

Now comes the testing part

Testing

Test your chatbot by using the yellow bubble below the right corner

Addon feature: CAI provided debug view to check what went wrong in case your chatbot does not work as expected.

Enjoy creating your own chatbot and do play around with different options.

🙂 🙂 

 

Summary

In this article, we learned below points

  1. How to create an Intent
  2. Add expression to the intent
  3. Train the bot by creating skill
  4. Add triggers, requirements, and actions to the skill
  5. Call Odata service to get and post data
  6. Test your chatbot

Useful links

https://cai.tools.sap

https://open.sap.com/courses/cai1

https://help.sap.com/viewer/a4522a393d2b4643812b7caadfe90c18/latest/en-US/ffbfe65e3e01485397ba32d7c6c738d3.html

https://community.sap.com/topics/conversational-ai

https://cai.tools.sap

https://open.sap.com/courses/cai1

https://help.sap.com/viewer/a4522a393d2b4643812b7caadfe90c18/latest/en-US/ffbfe65e3e01485397ba32d7c6c738d3.html

Part 2. Integration with MS Teams and monitoring of the usage coming soon……

 

Assigned tags

      7 Comments
      You must be Logged on to comment or reply to a post.
      Author's profile photo SHREERAM IYER
      SHREERAM IYER

      Hello Sherine !

      Congratulations on your first blog ... Good start and loved the way you have explained in detail.

      One suggestion (that I follow) is to prefix the skills with an ordered tracing ID such as one in pic below... hope it helps !

      You can read my following blog where I have showcased a similar approach https://blogs.sap.com/2021/03/11/challenge-submission-chitti-the-heal-bot-built-using-design-thinking/

      https://blogs.sap.com/2021/03/13/sap-conversational-ai-tutorial-challenge-2021-and-the-winners-are.../

      Ordered%20skill%20prefix

      Ordered skill prefix

      Author's profile photo sherine shibu
      sherine shibu
      Blog Post Author

      Thanks Shreeram for your valuable comment. As I am still novice in writing blog post, will keep this in mind in my future posts.

      Author's profile photo Mahesh Kumar Palavalli
      Mahesh Kumar Palavalli

      Thanks for sharing sherine,  this is worth a read and a try 🙂

      Author's profile photo sherine shibu
      sherine shibu
      Blog Post Author

      Thanks Mahesh..you were an inspiration 😁😁

      Author's profile photo Paul PINARD
      Paul PINARD

      Thank you Sherine for sharing your knowledge 🙂

      Author's profile photo SANGEETH REDDY ADDUMUDHALA
      SANGEETH REDDY ADDUMUDHALA

      Such a great explanation Sherine Thank You.

      Author's profile photo Swamy Madduluri
      Swamy Madduluri

      Thank you, well explained.