Technology Blogs by SAP
Learn how to extend and personalize SAP applications. Follow the SAP technology blog for insights into SAP BTP, ABAP, SAP Analytics Cloud, SAP HANA, and more.
cancel
Showing results for 
Search instead for 
Did you mean: 
Joni
Product and Topic Expert
Product and Topic Expert

Introduction


SAP Conversational AI platform provides 2 basic bot templates when you want to create a chatbot: Skills-based bot template and FAQ-based bot template.


A skills-based bot template allows you to create any skills to execute actions based conversation flows. While a FAQ-based bot is a knowledge base bot that you can create quickly by simply uploading a .csv file with question and answer in the content.

Underneath the hood, a FAQ-based bot template is just a skills-based bot but it’s automatically pre-configured with relevant intents and skills specifically made to handle FAQ to make bot developer's life easy.
While you still can create a FAQ bot using Skills-based bot template, it just that it will take more times to manually create and configure intents and skills when you need to add 10 more questions and answers. Nevertheless, you should only use FAQ-based bot template when the bot needs to perform complex action only (i.e. connect to backend or respond with multiple set of answers).

If you have come across a situation where you or your team had already built a skills-based bot, but want to merge with FAQ-based bot created & maintained by other team, or simply being requested to add knowledge-base skill with more than 10 static questions and answers into your existing Skills-based bot quickly; yes, this happened to my team while working on this Emergency Response Communications project. Fret not, let's explore some techniques that we can apply to resolve this situation by combining Skills-based bot with FAQ-based bot using SAP Conversational AI's API.

The Solution



There's no magic trick here, the key is here really just make use of fallback skill and consume Conversational AI's API.
Just make sure that the end user's query or question was not added in any intents of Skills-based bot so it will trigger a fallback skill in order to pass-over that query to FAQ-based bot. For API, we can use Runtime API - Dialog Endpoint or FAQ API, but we will need a FAQ-based chatbot's developer token to make API request. SAP Conversational AI also provides several SDKs, they are all open-source and hosted on public Github.

Here's how the request-response payload looked like when we make a Dialog Endpoint API request to FAQ-based bot. By looking at the request-response payload below, personally I would recommend using Runtime API - Dialog Endpoint as the response payload (take a good look the messages json-array) contains with structured message formats which you can grab and send directly to Bot Builder via webhook to display with same look-and-feel of FAQ-based bot respond and its experience.


And here's how the request-response payload looked like when we make a FAQ Ask API request to FAQ-based bot which you can also use it but you may need to style the message format accordingly.


Knowing the solution, now let's see 2 approaches you can use here to combine Skills-based chatbot with FAQ-based chatbot as a single unified chatbot.

Approach 1: Call Webhook with Custom Bot Logic


This is my preferred approach when my Skills-bots already using a custom bot logic (middleware). I can just reuse back same the custom bot logic and enhance it to call a Dialog Endpoint API of FAQ-based bot. Next just grab the messages json-array payload from API response. This way we can still have the standard message respond style and same experience of FAQ-based chatbot in our Skills-based chatbot without doing extra massaging to the message format.

Configure a webhook call to point to specific endpoint of your custom bot logic.


Add code logic in your custom bot logic to make API request to Dialog Endpoint API to FAQ-based bot. In my code snippet below I have also added a condition to return a default fallback message when Dialog Endpoint API doesn't provide any FAQ answer.
##  This is the URL path triggered from fallback skill, and handling it by checking CAI Dialog Endpoint API from other FAQ-based bot project
@app.route('/faq', methods=['POST'])
def faq():
data = json.loads(request.get_data())
final_reply = getCAIFAQPayload(data['nlp']['source'], data['conversation']['conversation_id'])
if len(final_reply) < 1:
# Return standard fallback message
final_reply.append({
"type": "text",
"content": "I have not been trained to answer your phrase yet, but I am continuously learning. Please check the list of [FAQ questions](https://sap.sharepoint.com/AllFAQ.aspx) to find an answer for your question. If your question is of medical concern, contact your local Health Authority or Doctor.",
"markdown": True
})
return jsonify(
status=200,
replies=final_reply
)

## Call Dialog Endpoint API of FAQ-based bot and get only 'messages' json-array
def getCAIFAQPayload(query=None, conversation_id=None):
payload = {'message': {'content': query, 'type': 'text'}, 'conversation_id': conversation_id}
resp = requests.post('https://api.cai.tools.sap/build/v1/dialog',
data=json.dumps(payload),
headers={'Authorization': 'Token 05281xxx28ea794c999f0e3988xxxxxx', 'Content-Type': 'application/json'})
if resp.json()['results'] and len(resp.json()['results']['messages']) > 0:
return resp.json()['results']['messages']
return []

Note: My custom bot logic was developed using Python with Flask and deployed to SAP Cloud Platform - Cloud Foundry environment. Similarly, you can also create a custom bot logic using other services available within SAP Cloud Platform, for example: Functions-as-a-service, API Management, or Open-Connector.

Approach 2: Call Consume API Service


This is an alternative quick approach if you don’t want to create a custom bot logic or you don't have access to it.
However, unlike option 1 above, we can't really just grab the messages payload and display as-is; instead we have to get direct answer string value from API response and put the string value into text message format.

Configure an API service configuration to call Dialog Endpoint API, and configure the Authorization from developer token of the FAQ-based bot.


Configure the Body payload accordingly like below. I use the {{current_message.content}} to get current user's query but you can also use {{nlp.source}}. This is {{current_message.content}} and {{nlp.source}} are part of the Runtime Data Variables accessible throughout bot project, for more information on other runtime data variables you can check out here.


Leave the response as-is. The API response payload will be appended into the body' of API Service's response payload.


Next, we just need to grab the string value of FAQ recommended answer and display it as Text Message style.


OR pick the one the answer with higher confidence.


However, with this approach you can't just re-use messages json-array payload; this is because we are using Text Message format to render and display the JSON object, so it will get displayed as plain string instead. If you want a same look-and-feel how current FAQ-based bot is responding, you will have to reconstruct the message formats display of FAQ-based bot (using Text Message, and Quick Replies), and using Scripting Syntax to handle certain conditions too depending on its API response.



Conclusion


By combining the Skills-based chatbot with FAQ-based chatbot as a single unified chatbot, not only we are speeding the time-to-market of additional new feature while keeping 2 separate bot projects organized and maintained at their own workspace, but we are also improving customer experience for end-users. Here's the screenshot of my unified chatbot:



SAP Conversational AI platform allows you to build your chatbot or bot quickly, but also at the same time gives so much flexibility in extending your chatbot or bot.

For more information about SAP Conversational AI:
11 Comments