Skip to Content
Technical Articles

SAP SMB Executive Assistant Sample Bot powered by SAP Conversational AI

In this blog, I will show a sample executive virtual assistant smb-recast-bot which can serve the CXOs about the executive-level analytics question through conversation, powered by SAP Conversational AI(formerly as recast.ai) for SAP Business One and SAP Business ByDesign systems. In this sample, the sales manager can get the insights of sales through conversation, such as 
  • “How is my sales status for this quarter?”
  • “Give me the monthly sales report for 2018”
  • “Compare the sales status by quarter for 2017 and 2018”
  • “Who contributes the most profits for 2018?”
  • “What are the top 5 best-sellers for 2018?”
Here you have the video recordings about the PoC demos of smb-recast-bot.
  • Sales Analysis demo based SAP Business One
  • Sales Analysis demo based SAP Business ByDesign

     

In addition, this sample bot can be easily extended to accomodate other analytics question about delivery performance, purchasing, financial etc.Please refer to this document.
The transactional scenario such as placing an order, checking the delivery status etc is also possible through SAP Conversational AI(formerly recast.ai), Service Layer of SAP Business One and OData API of SAP Business ByDesign. However, you may refer to SMB Market Place Assistant Bot for reference, as the transactional scenario is no part of this sample.

 

High Level Architecture and Components

The architecture diagram above illustrate the following components
  • App/Bot: A self-service bot for end users on messing platform such as Facebook Messenger, Line, WhatsApp, WeChat etc, or a chatbot on web, or an application over the voice on a device, such as an Alexa skill.
  • SAP Conversation AI: A collaborative end-to-end bot platform for developers.
  • smb-recast-bot server: The webhook action of analytics questions
  • ERP backend: In this sample, it supports SAP Business One, version for SAP HANA and SAP Business ByDesign. You also can easily extend smb-recast-bot to support S4HANA etc by adding mapping configuration to intents_mapping.js and handle the login in the /webhooks/login and /webhooks/analytics endpoint in index.js.

SAP Conversation AI

A collaborative end-to-end bot platform for developers.
  • Train: Train your bots to understand the human language.
  • Build: Build a conversation flow for the bot.
  • Code: Program a Webhook action with your preferred language to fulfil the request, which can perform external API call. The action is triggered by a bot skill when its trigger conditions are met. Recast.AI calls your API at the URL specified in the bot settings, at the endpoint specified in the action itself.
  • Connect: Connect your bot to multile channels(WebChat, Facebook Messenger, Line, Slack, Alexa etc)
  • Monitor: Monitor the NLP status for incoming queries, get insights on its usage, and re-train it to make it sharper,
More Useful resources:

smb-recast-bot

Composed of the following components
  • smb-recast-bot in SAP Conversation AI
    The trained intents incuding

    • sales-analysis intent
      Sales analysis by year/quarter/month, product, customer etc
    • login-erp intent
      Login to different ERP system such as SAP Business One, version for SAP HANA and SAP Business ByDesign.By default, the server is connected to the configured SAP Business One, version for SAP HANA system.Sample utterance
      “Login to b1”
      “Sign me into byd”
  • smb-recast-bot server
    The webhook action implemented with NodeJS for sales-analysis and login-erp intents. Please check the source code.Webhook API to be invoked as action in the skill of SAP Conversational AI:

    • /webhook/analytics: A generic webhook for all kind of analytic intent
      • Call the NLP parser to convert the NLP result(intent/entity) into the data structure(measures, dimensions, filters etc) required by semantic analysis
      • Call the query generator to generate the OData query for the target system.
      • Invoke OData query and format the result for message response
    • Intent to Semantic Mapping models
      • Abstract mapping model: An abstract mapping model between intent/entity of NLP and semantic model/(Measures,Dimensions,Filters) without any system specific information.For instance:
        • The dimension entity in NLP result with value “Client”,”Buyer”,”Customer” etc is mapped an abstract dimension field “Customer”.
        • The measure entity in NLP result with value “Sales”,”Sales Number”,”Revenue” etc is mapped an abstract measure field “Sales Amount”.
      • Fuzzy search: To be more typo-tolerant, fuzzy search is applied to find the abstract fields from entity of NLP during Abstract mapping model. For instance:
        • The misspelled dimension entity in NLP result like “Clent”,”Byer” and “Cutomer” etc are correctly recognised as “Client”, “Buyer”, and “Customer” with fuzzy search, which are eventually mapped an abstract dimension field “Customer”.
        • The misspelled measure entity in NLP result like “Sals”,”Saes Numer”,”Reveue” etc are correctly recognised as “Sales”, “Sales Number”, “Revenue” with fuzzy search, which are mapped an abstract measure field “Sales Amount”.
      • Mapping model for SAP Business One:
        The abstract dimension field “Customer” is mapped into the technical field “BusinessPartnerNameAndCode” in view “SalesQnalysisQuery”.

        The abstract measure field “Sales Amount” is mapped into the technical field “NetSalesAmountLC” in view “SalesQnalysisQuery”

      • Mapping model for SAP Business ByDesign:
        The abstract dimension field “Customer” is mapped into the technical field “CCUSTOMER” in report “BIF – Sales Revenue”.The abstract measure field “Sales Amount” is mapped into the technical field “KCNETSALES” in view “BIF – Sales Revenue Report”
    • NLP parser: Convert the NLP result structure(intent/entity etc) into the data structure(measures, dimensions, filters etc) required by semantic analysis
    • Query Generators
      • B1QueryGenerator:
        Generating OData(version 3.0) query to access the target view in Semantic Layer of SAP Business One through Service Layer.
      • ByDQueryGenerator:
        Generating OData(version 3.0) query to access the target view in Semantic Layer of SAP Business One through Service Layer.

ERP backend

SAP Business One, version for SAP HANA

Eventually the smb-recast-bot server converts the analytics question in human language into an OData query to the semantic layer through Service Layer. Please refer to this blog about how to access semantic layer of SAP Business One through Service Layer.

SAP Business ByDesign

Eventually the smb-recast-bot server converts the analytics question in human language into an OData query to the datasource or report. Please refer to this blog about OData APIs for SAP Business ByDesign Analytics.

Process flow

Take the following example:
User input: “Who are my top 5 customers in 2018?”

1.Nature Language Processing by SAP Conversational AI

You can customise your own entities by adding the label in the training step.The following entities are customised in sales-analysis intent.
  • dimension
  • measure
  • limit_number
  • filterby
  • filter_value
  • sorting_direction
NLP result in json format
{
  "nlp": {
    "uuid": "75428ced-7711-4616-91f4-3b49a08d51ab",
    "intents": [
      {
        "slug": "sales-analysis",
        "confidence": 0.99,
        "description": "Sales Analysis by Year, Quarter, Month, Customers and Products"
      }
    ],
    "entities": {
      "sorting_direction": [
        {
          "value": "top",
          "raw": "top",
          "confidence": 0.99
        }
      ],
      "limit_number": [
        {
          "value": "5",
          "raw": "5",
          "confidence": 0.99
        }
      ],
      "dimension": [
        {
          "value": "customers",
          "raw": "customers",
          "confidence": 0.99
        }
      ],
      "datetime": [
        {
          "formatted": "Monday, 01 January 2018 at 12:00:00 AM (+0000)",
          "iso": "2018-01-01T00:00:00+00:00",
          "accuracy": "year",
          "chronology": "past",
          "state": "absolute",
          "raw": "2018",
          "confidence": 0.99
        }
      ]
    },
    "language": "en",
    "sentiment": "positive"
  }
}

2.Convert to semantic model of target system by parser

Firstly, the parser finds the entity mapping to the abstract model with fuzzy search(for instance, even if the customer is misspelled in the sentence as “cutomer”/”byer”/”clent” etc, still can be recognised as “customer”/”buyer”/”client” and identified its neutral abstract name as “Customer”).
Then mapping the abstract fields to the technical fields and view in the target system type.

SAP Business One, version for SAP HANA

{
  "Intent": "sales-analysis",
  "Language": "en",
  "Message": "Who are my top 5 customers in 2018",
  "MappedSemantics": {
    "SourceType": "HANA View",
    "SystemType": "b1",
    "Accesstype": "Service Layer",
    "DataSource": "SalesAnalysisQuery",
    "Filters": [
      "(PostingYear eq '2018')",
      "DocumentTypeGroup eq 'Order'"
    ],
    "Dimensions": [
      "BusinessPartnerNameAndCode"
    ],
    "Measures": [
      {
        "Measure": "NetSalesAmountLC",
        "Aggregation": "sum"
      },
      {
        "Measure": "GrossProfitLC",
        "Aggregation": "sum"
      }
    ],
    "LimitNumber": "5",
    "Sortings": [
      {
        "SortBy": "NetSalesAmountLC",
        "SortDirection": "desc"
      }
    ]
  }
}

SAP Business ByDesign

{
  "Intent": "sales-analysis",
  "Language": "en",
  "Message": "Who are my top 5 customers in 2018",
  "MappedSemantics": {
    "SourceType": "Report",
    "SystemType": "byd",
    "Accesstype": "OData",
    "DataSource": "/sap/byd/odata/cc_home_analytics.svc/RPZ1E0943C634B1218DA2EAB7QueryResults",
    "Filters": [
      "(CYEAR eq '2018')"
    ],
    "Dimensions": [
      "TCUSTOMER"
    ],
    "Measures": [
      {
        "Measure": "KCNETSALES",
        "Aggregation": "sum"
      },
      {
        "Measure": "KCGROSSPROFIT",
        "Aggregation": "sum"
      }
    ],
    "LimitNumber": "5",
    "Sortings": [
      {
        "SortBy": "KCNETSALES",
        "SortDirection": "desc"
      }
    ]
  }
}

3.Generate the OData query to semantic layer of target system

SAP Business One, version for SAP HANA

https://<SeriviceLayerHost>:50000/b1s/v1/sml.svc/SalesAnalysisQuery?$apply=groupby((BusinessPartnerNameAndCode),aggregate(NetSalesAmountLC with sum as NetSalesAmountLC,GrossProfitLC with sum as GrossProfitLC))&$top=5&$filter=(PostingYear eq ‘2018’) and DocumentTypeGroup eq ‘Order’&$orderby=NetSalesAmountLC desc

SAP Business ByDesign

https://<byd_tenant>.sapbydesign.com/sap/byd/odata/cc_home_analytics.svc/RPZ1E0943C634B1218DA2EAB7QueryResults?$format=json&$select=TCUSTOMER,KCNETSALES,KCGROSSPROFIT&$top=5&$filter=(CYEAR eq ‘2018’)&$orderby=KCNETSALES desc
“`

4.Query the analytics to back ERP via OData

5.Format the final message reply to the chatbot

SAP Business One, version for SAP HANA

result in json format

{
  "replies": [
    {
      "type": "list",
      "content": {
        "elements": [
          {
            "title": "Web Customer (C99998)",
            "subtitle": "NetSalesAmountLC: 4103.08\nGrossProfitLC: 1535.08",
            "buttons": [
              {
                "title": "View Details",
                "type": "BUTTON_TYPE",
                "value": "View Details"
              }
            ]
          },
          {
            "title": "Maxi-Teq (C20000)",
            "subtitle": "NetSalesAmountLC: 1200\nGrossProfitLC: -2856.18",
            "buttons": [
              {
                "title": "View Details",
                "type": "BUTTON_TYPE",
                "value": "View Details"
              }
            ]
          }
        ],
        "buttons": [
          {
            "title": "View Chart",
            "type": "BUTTON_TYPE",
            "value": "View Chart"
          }
        ]
      }
    }
  ]
}​

SAP Business ByDesign

result in json format:

{
  "replies": [
    {
      "type": "list",
      "content": {
        "elements": [
          {
            "title": "Silverstar Wholesale Corp",
            "subtitle": "KCNETSALES: 727951.180000\nKCGROSSPROFIT: 440410.460000",
            "buttons": [
              {
                "title": "View Details",
                "type": "BUTTON_TYPE",
                "value": "View Details"
              }
            ]
          },
          {
            "title": "Unlimited Electrics",
            "subtitle": "KCNETSALES: 629095.640000\nKCGROSSPROFIT: 513449.210000",
            "buttons": [
              {
                "title": "View Details",
                "type": "BUTTON_TYPE",
                "value": "View Details"
              }
            ]
          }
        ],
        "buttons": [
          {
            "title": "View Chart",
            "type": "BUTTON_TYPE",
            "value": "View Chart"
          }
        ]
      }
    }
  ]
}​

How to run and extend this sample bot?

Please refer to this document.

License:

This smb-recast-bot project is subject to MIT LICENSE.Here is to highlight that THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED. Therefore no support available. All rights reserved by SAP SE.
In my next blog, I will show how to connect this smb-recast-bot to Facebook Messenger. Please stay tuned.
Be the first to leave a comment
You must be Logged on to comment or reply to a post.