[SAP CAI] – WORKING WITH SAP CONVERSATIONAL AI

Hi guys, In this article I want to share something when working with SAP Conversational AI like connect to external service, scripting syntax, custom data in conversaions…

For more detail about SAP Conversational AI, kindly reference here SAP Conversational AI

HOW TO CREATE NEW BOT

When login successful, at home page click new bot

HOW TO FORK INTENT

In caes, we want to download intent from internet, we do not want to create new intent while It created on internet as large resource. We just reuse these intents by using FORK

HOW TO CREATE NEW INTENT AND EXPRESSION OF ITS

Expression of intent is sentences which will contain in input from customer. We create more expression for intent, out BOT will get more smart

HOW TO EXTRACT DATA IN CONVERSATION

In cases, we want to extract data in expression conversation between BOT and user, we will declare entity for BOT.

Example, we want to extract package number from conversation to save memory. This case, we will create entity with type : REGEX entity

In case, we want to create entity which is list item. This time we will choose entity with type Restricted Entity

With this type of entity, we can create list of value for entity. Example

Default, data of this entity with format JSON will have properties

In case we want to create more properties then default properties (raw, value, confidence). We will use Enrichments tab

This time, we can set value for data which enriched

DEFINE INTENT TO TRIGGER SKILL

In BOT we have many intent. When create skill we need to define what intent or what entity will be trigger skill

DEFINE REQUIREMENT FOR SKILL

In cases we need to run some task before execute action in skill. Example we need call to API, we need choose some option (YES/NO) save value entity into memory to display result when execute action…

This time we need define requirement for skill

This time value of entity or intent will be saved in memory of BOT and we can get data from this for execute action next step

HOW TO CALL EXTERNAL API

In case we need call API from external system, we need do some step below

  • Define variable in memory at tab Requirement
  • Define action group, add condition
  • Define name for response to get data from response
  • Get data from response

HOW TO CALL EXTERNAL SERVICE TO CREATE VALUE FOR ENTITY

As you know, we can create entity data by add static value.

But we also have another way to get data dynamic for entity by using FETCH DATA

Example 01

We want to create list name of products for entity by call ODATA at here

  • Go to Fetch Values
  • Syntax for just get array value
  • Syntax to create new array base on array above

For more detail about variable scripting in SAP Conversational AI, kindly reference Here

Example- 02

When create requirement to display catagory list in entity #category, if user input value which not contain in values of entity, we have to call external service to get data category. When call Odata, response will have JSON format array category, and we want to loop every object in JSON response to get value for custom message type.

WORKING WITH SCRIPTING SYNTAX

When we re working with SAP Conversational AI, we need to use some variable and how to get data from variable also…, So we will be working with one concept in this.

Yes, I mean that we will be working about script syntax.

First we will use this example data JSON into my BOT

{
  "api_service_response": {
    "body": {
      "results": [
        {
          "Name": "test1",
          "Price": "100",
          "Available": true,
          "lookMeUp": "foundMe",
          "to_ProductCategory": {
            "MainProductCategory": "Computer Systems"
          }
        },
        {
          "Name": "test2",
          "Price": "200",
          "Available": true,
          "lookMeUp": "foundMe",
          "to_ProductCategory": {
            "MainProductCategory": "Computer Systems"
          }
        },
        {
          "Name": "wow",
          "Price": "50",
          "Available": false,
          "lookMeUp": "foundMe",
          "to_ProductCategory": {
            "MainProductCategory": "Computer Systems"
          }
        }
      ],
      "lookup": {
        "foundMe": {
          "works": "works=true"
        }
      },
      "stringArray": [
        "a",
        "b",
        "c",
        "d",
        "e",
        "e"
      ]
    }
  }
}

We will import this data JSON into memory of BOT, and from there we will go every example about scripting syntax.

Kindly read more Scripting Syntax

This time, we will access this by using syntax

{{memory.example}}

If we want to take IDE about scripting syntax, we shoule be use Here

WORKING WITH ARRAY
GET OBJECT
{{memory.example.api_service_response.body.results}}
LOOP FOREACH
LENGTH ARRAY

PLUCK ARRAY SUBPATH – CREATE NEW ARRAY FROM CHILD PROPERTIES

WORKING WITH OPERATORS AND CONDITION STATEMENT
#eq
{{#eq value1 value2}} .... {{else}} .... {{/eq}}
#if
{{#if true}}.... {{else}} .... {{/if}}

MORE EXAMPLE VISUALIZE

DISPLAY LIST BUTTON

In this example, we will base on data JSON above to display list button on conversion by using synxtax {{#eachJoin array}} …. {{/eachJoin}}

{
  "type": "buttons",
  "delay": "",
  "content": {
    "title": "This is a example list button",
    "buttons": [
    {{#eachJoin memory.example.api_service_response.body.results}}
      {
        "title": "{{Name}}",
        "value": "{{Price}}",
        "type": "postback"
      }
      {{/eachJoin}}
    ]
  }
}
DISPLAY LIST CARD

In this example, base on data JSON to displat list card

{
  "type": "list",
  "content": {
    "elements": [
    {{#eachJoin memory.example.api_service_response.body.results}}
      {
        "title": "{{Name}}",
        "subtitle": "${{Price}}",
        "imageUrl": "",
        "status": "{{Available}}",
        "statusState": "{{Available}}",
        "description": "{{to_ProductCategory.MainProductCategory}}",
        "buttons": [
          {
            "title": "Select",
            "value": "Select",
            "type": "postback"
          }
        ]
      }
      {{/eachJoin}}
    ]
  }
}

SUMMARY

In this article, I shared some tips when working with SAP Conversaional AI. I also talk about Scripting syntax and how to write some code scripting syntax to display conversation visualize. Next article, I will take one scenario step by step How to make sale order base on ODATA Northwind. Thanks for your reading and any advise, kindly leave your comment on this.

See you next article.

Thanks

Joseph.

One comment

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.