*Opens MS Teams*
Me: Hey Ariba, are there any documents pending my Approval?
Chatbot: Here are some of the latest approvables in your queue
Me: Sweet! I want to approve an invoice
Chatbot: Certainly, just key in the Invoice Id and take appropriate action
I believe you would've already guessed what this blog post is going to be about. If you are planning or even looking for possibilities of integrating SAP Conversational AI with any other services in order to create a seamless communication experience while at the same time getting those "To-Do" done just via chat, I might be able to humor you a bit in this blog post. While I'm going to talk about the SAP CAI integration with
SAP Ariba Approval APIs throughout most of this post, you can essentially mimic this for any other service which has a common pre-requisite: It exposes APIs in order to do what you want to accomplish with your SAP CAI Chatbot.
But first... Let me talk about SAP Conversational AI
CAI is one of SAP's offerings which essentially is an end-to-end (a lot of stress on end-to-end) bot building platform. These chatbots can let you do either of the below things:
- Answer your questions from its knowledge based repository: you as a 'bot developer' (these are some heavy words, but really you are one 😉) can prepare a csv file that contains question and answer pairs which the bot recognizes and answers from.
- Accomplish tasks using APIs: you connect your chatbot with SAP or 3rd party APIs in order to fetch information from those systems, review that information and maybe even take further actions.
All this, under the guise of you chatting with a colleague straight from a chat platform say Slack, MS Teams, even a webpage or many more other channels.
These are the two primary focus areas of SAP CAI, however there have been brilliant use cases that the
SAP CAI Community has come up with, which might be of your interest. In this post I am going to be talking about the 2nd kind only, which lets you accomplish some tasks.
I'd say the tool in itself is quite intuitive and the
documentation that SAP provides is just enough to get you started on the road to build a production ready chatbot.
There is a
Community Edition available for SAP CAI which is great to get your hands dirty. On the other hand, for organizations who are already using SAP Business Technology Platform, they can subscribe to SAP Conversation AI to get started from there itself.
With great power comes great responsibility
As a Chatbot Developer you are not only responsible for doing the basic chatbot setup, integrations but also build relevant skills into your chatbot. The idea behind building skills is not very difficult if you can tell a story about your use case that you are trying to build around via SAP CAI. The chatbot is only going to do the work that you as a human can do. So till the time you have a clear vision about the task at hand and you know how to handle that task if someone asked you to do it, working with SAP CAI becomes very simple.
SAP CAI provides you with a blank canvas in order to build skills for your chatbot. Here is where you put your Storyteller cap on and start envisioning how the conversation with the chatbot will commence, progress and conclude in order to accomplish your use case.
Taking an example of Approving a Transaction Document (say an Invoice) in SAP Ariba, let's build on the possible chat messages which the user might want to ask the chatbot.
- "Hello" - This is a typical introductory exchange. You might expect to know who is it at the other end of the chat.
- It might be a good place where the chatbot replies explaining what is it supposed to do.
- Additionally to make the communication interactive, provide a few possible quick replies which the user can select and get the further details or answer for. Eg. for our scenario:
- Get Pending Approvables
- Approve a Document
- This makes sure that the user is well informed, has to take minimal steps and reach their desired conclusion.
- The user need not necessarily do trials of what input might work, what might not.
- Need not type their questions
- This also makes you the one driving the conversation.
- This minimizes questions that the bot is not built to answer
- "Get my Pending Approvables" - The user now wants to get the list of documents, from SAP Ariba, which are pending their approval.
- As a user of Ariba, I would like to first see a list of such documents. Each entry in this list can have minimal information like who created this Invoice, when was it assigned to the user for approval.
- Correlate this with the APIs available and what their response looks like or vice versa.
- Remember you are driving the conversation. Provide next possible options to the user. Eg.
- Show more details about one of the document
- Approve a document
- "Get me the Details of a document" - To view more granular details of a specific document, a user might ask the bot for this.
- Why though? Remember, we are in a chat. The previous response is a list which contains only minimal details about each document
- Present the important information that might be necessary, in form of let's say a card. A trick to identify important data points in case you are not sure, courtesy my very smart colleagues, adapt this information from current notifications
- I used approval notifications that SAP Ariba sends to the approvers to base this card on
- These are side-by-side extensions, you can still refer to core application anytime
- Provide next possible options. I provided the below:
- Open a document in Ariba UI using the webjumper url
- An option to approve the document (yes, right from the chat)
- Feeling curious? More information about the document
- "Is there any more information about this document" - The information on the card cannot have all the information. If you look at the response we get from the API, it is just huge. We need not display all the information in one shot, but we sure can provide it on demand if the user asks for it.
- You do not need to make a fresh API to call to fetch this information. You can re-use the response received from the previous step depending on the APIs available.
- Identify what kind of additional information a user might like to see.
- I talked to few of my colleagues who use SAP Ariba frequently for Approvals. This chatbot was built keeping Approver in mind because they were the target audience. So given your use case, identify yours.
- Depending on how the data is structured in the API response, it might be easy, in some cases it might be extra difficult too. BUT handlebars might have everything to get things done. I'll talk about it in a little bit.
- "I want to approve an Invoice" - Considering the user actually got enough information in order to take a decision, your chatbot might receive a task such as this.
- There is nothing to worry if you have the APIs for getting this done
- You need to make sure that the bot captures the ID of the approvable correctly in order to initiate Approve or Deny action
- Make sure to provide a logical response back to the user once the action is taken, doesn't matter it resulted in success or failure (there can always be technical glitches). The user must be made aware about it
With the above sample, we can infer that
User Experience is at the front and center of building a chatbot. You need to give enough leeway to the users and consider situations that the user might not know something crucial to start with. Say the user might not know the exact Document ID that they want to approve. Provide them with an option to scroll through the list of their pending approvables so that such things can be taken care of. Think of other ways in which such information can be gathered, example, the user might know the name of the Requester of the Invoice that they want to approve. You might be able to filter the list via scripting in handlebars and provide that as a response to the user in order to ease up their task of scrolling through a long list. So to say, there are multiple possibilities with which a user might interact with your chatbot. Identify your target audience, put yourself in their shoes, take their help in laying a foundation for your chatbot's conversation.
Functionalities I made use of while building this chatbot
Intents, of the users and the bot
SAP CAI has Artificial Intelligence in its name. So bringing in some AI, we have something called Intents. Consider a situation where a user would like to ask for their pending approvables. Different users might have their own way of framing this sentence:
- "I want my pending approvables"
- "Can you get the invoices pending my approval?"
- "Which documents are pending my approval?"
There 'might' be a finite number of possibilities for asking this question, but that might just be a tough job to feed that to your bot. Instead, identify a handful of statements that best identify a job at hand which can serve as a training set and let SAP CAI's Natural Language Processing take care of the rest. I'm no expert about it but you can certainly find more about it from SAP's documentation on
Intents.
Entities
When you write a sentence in the chat, some data points might be scrambled here and there because that is how humans talk. Entities help in recognizing just those data points.
One of the entities that I used was a regex type entity so as to identify the Invoice numbers entered by the users in order to search for a specific invoice. These Invoice IDs always had a 'INV' prefixed so this type of entity made it easy to identify the Invoice IDs in the chat. I had built the chat such that the user would only key in the Invoice ID in the response, so this worked like a charm without fretting much.
Bot Builder: Your Story Board
This is where you design or at least lay the foundation for your bot's conversation. Each box here is a Skill that has been defined for your bot which it makes use of while conversing with a user.
Story Board
Skills: You can polish yours as well as the bot's
Consider it to be a block of Low-code/No-Code that will help you take a necessary action in your chat. Based on the intents that you have setup for your chatbot, you can trigger specific skills. In the analogy of the Approvals Scenario, An intent to "Fetch Pending Approvables" is supposed to trigger a skill that I have configured which is supposed to invoke an API call to retrieve the pending approvables of that user. It is that simple. In return these skills can provide the following:
- A response in the form of free text, card, buttons, quick replies... there are a few others as well - There are cool features to add delays in responses as well so as to make it look as if a real person is writing on the other end of the chat 🤖.
- An ability to store data in the chatbot's memory (mark this one, this is extra important)
- Transition to a different skill - consider this something like modular programming in which a function calls another function in order to keep things clean and simple.
You can use one of these individually, two at a time or all at once. It's all up to you and what fits your use case. This is incredibly intuitive and flexible, and the product team of SAP CAI seems to have given a really good thought about such things. This makes the platform very, very powerful to say the least.
Memory: The bots remember
Throughout a unique user session, the bot can keep track of certain entities that you'd like it to in its
memory object. This makes it easier for storing data that can be re-used throughout the course of conversation. This data can be:
- an entity that you might have created in order to recognize something specific.
- I had an entity to recognize the Invoice ID entered by user. I could use it throughout the length of the bot's conversation until the user entered a different one of course.
- a 3rd part JSON response that you might have received from an API.
- After retrieving the details for a particular Invoice, I stored that information in the memory in order for the bot to answer more detailed/supplementary questions from the user. This reduced the API calls that would have been otherwise needed for the same document, consequently reducing time to answer as well.
{{Handlebars}} - They have a Moustache as their logo. LOL
Like any programming language, when you need to print something and make use of the variables you need to format the variables in a specific syntax. In SAP CAI, when you need to do substitution of variables be it those coming in API response attributes or bot's memory, you need to use handlebars template expressions to do so. How does it look? Simple
If you have an API response structure which is in JSON or for that matter a memory structure (which is JSON) resembling something like below in the screenshot, the expression to print the "status_code" would be:
{{api_service_response.entityResponse.status_code}}
Sample API Response
Similarly you can employ some other expressions and functions to manipulate data coming from the API, or residing within the memory in order to achieve what you want to do. SAP has
documented a list of functions that can help with performing a number of operations in complex JSON response structures. Is it difficult to use handlebars? Not really. Of course you'd fail a few times in the start, but that's almost half the fun of learning something new. There is always Twitter to vent off that anger anyway. Additionally I came across handlebar's own
documentation as well while I was working on this bot. It is really useful too.
A typical example of what I did in order to get the Approver who approved the Document before the currently active Approver:
Breaking things down to make it easy
From the huge response I had, I trimmed it down to the node which I was interested about and stored it to the memory separately.
{{json (pluck memory.entity-data.ApprovalRequests "ApprovedBy.UniqueName")}}
Apply Logic
Once I had this data which btw was a List, I could apply list specific functions like below in conjunction with what developer use the best: the if-else clause:
{{#if memory.approver-list}}
{{last memory.approver-list}}
{{else}}
You are the first Approver
{{/if}}
These were some core functionalities which will certainly come in handy when you create your chatbot using SAP CAI.
Coming to maintenance
The platform certainly had a few tricks up it's sleeves for sure in this area too. These made the SAP CAI easy to use and at the same made the maintenance job seem like no pain at all. I sure can be clumsy at times when it comes to version control and maintaining application credentials. It was just the other day that I spent some hours cleaning up my Postman collections, so maintenance can be a crucial feature worth mentioning about.
Version Control
The APIs that I was relying on when I started the project were the v1 Ariba Approval API for Procurement. In the meantime, v1 became deprecated and SAP Ariba pushed a v2 for that API. While v1 is still supported by SAP Ariba, it is always good to have the client applications updated to consume the latest version too. In this case the client application was SAP CAI. While I honestly thought that the upgrade would require a lot of rework, surprisingly it didn't. I created a version v2 of my chatbot, updated the URLs, made changes in the request and response structure in order to adapt the latest APIs and that's it. This made sure that my version v1 of chatbot was still live and could always be used as a fail safe in case the upgrade took longer than expected or didn't go as planned.
Credential Templates
During the API deprecation, I had to plug in the new API's credentials in place of the old ones. Now these APIs were using an ApiKey and OAuth Credentials for access token generation. I was using these APIs in almost 4-5 skills. This meant that the ApiKey and the Credentials needed to be updated in all these skills. Fortunately while defining the skills in v1, I had used an Authentication template provided out of the box by SAP CAI which I had re-used in all these 4-5 skills while making API calls. This meant that now in v2 I only needed to update these in one single place ie. the template and that was it. This was a game changer and certainly minimized the manual effort.
Future Scope
- SAP CAI allows numerous integration with 3rd Party Channels like MS Teams, Slack, Messenger. To make its use more seamless, MS Teams integration would be an upcoming task because our organization uses MS Teams for org wide communications. So essentially a user typically has MS Teams open throughout the day. It would be so easy to approve the documents right from there without opening an additional window.
- Incorporating other Approvables Eg. from SAP Ariba Strategic Sourcing Suite as well and even say S/4 HANA in order to make it a single entry point to manage quick approvals in a single place.
- To say that the details the Chatbot provide are sufficient for taking an action right from chat, is perhaps too ambitious for now. But we will certainly like to reach there. This can only be done via constant feedback from the users and making enhancements to the bot's skills gradually.
- How about "Hey Google, I want to approve Shashank's latest Invoice". There are some really good resources including this one available at SAP CAI Community Page.
- The intent behind using technologies like SAP CAI is to focus on strategies like:
- User Experience, which is evident from how easy it is to interact with the chatbot
- Interoperability, in order to provide users with different ways to interact with our applications. Accessibility and inclusivity should be the areas of prime importance
The product is ever evolving with cool new features coming in with each release. As of now I've always been able to get great feedback from the community wherever I felt stuck or needed some help with anything SAP CAI. I'm sure the cycle will continue going forward too. You can let me know your thoughts or questions you might have encountered while reading this post, in the comments section below and in case you are already using SAP Conversation AI, I'll be more than happy to hear about what all use cases you are trying to solve with it.