Hi guys, in this article I want to share tips How to use scripting syntax to build chat BOT with message which returned from API response.
In this article, we will learn
- Create entity from API response.
- Create custom message
- Create some visualize conversation from API response by scripting syntax.
For demo, We will use API ODATA Northwind with endpoint here
Endpoint :
https://services.odata.org/V3/(S(vnym1b3ehndm0p4fr0bdtbon))/OData/OData.svc/Products/?$format=json
CREATE BOT

CREATE INTENT AND ADD EXPRESSION FOR INTENT


CREATE ENTITIES
ENTITY CATEGORY
First we will create some data for entity CATEGORY, and later in SKILL of BOT, if category wrong, BOT will connect and call API ODATA to get more caregory.


CREATE ENTITY PRODUCTS
Next, we will create the same entity for PRODUCTS but this time we will fetch data from ODATA API



- Transform data JSON into array of product by using scripting syntax
{{json (pluck api_service_response.body.value "Name")}}


CREATE SKILL FOR BOT
SADD KILL add-to-cart

- Configuration for tab Trigger

- Configuration for tab Requirement to set data of entity #category into memory

- Configuration for missing data of #category. This time, we will call to ODATA API to get more category with endpoint
https://services.odata.org/V3/(S(vnym1b3ehndm0p4fr0bdtbon))/OData/OData.svc/Categories/?$format=json






{
"type": "buttons",
"delay": "",
"content": {
"title": "Please select the category you are interested in!",
"buttons": [
{{#eachJoin api_service_response.category.body.value}}
{
"title": "{{Name}}",
"value": "{{Name}}",
"type": "postback"
}
]
}
}
- Configuration for tab Requirement to set data of entity #products into memory

- Configuration for missing data of #products. This time, we will call to ODATA API to get more products base on memory category data with endpoint


https://services.odata.org/V3/(S(vnym1b3ehndm0p4fr0bdtbon))/OData/OData.svc/Products/?$filter=%20Categories/any(Category:Category/Name%20eq%20%27Foods%27)&&$format=json


{{#if (length api_service_response.default.body.value)}} Availability: {{pluralize 'product' quantity=(length api_service_response.default.body.value) }}. {{/if}}


{
"type": "list",
"content": {
"elements": [
{
"title": "{{Name}}",
"imageUrl": "",
"subtitle": "$ {{Price}}",
"buttons": [
{{#eachJoin api_service_response.default.body.value}}
{
"title": "{{Name}}",
"value": "{{Name}}",
"type": "postback"
}
{{/eachJoin}}
]
}
]
}
}
ADD SKILL check-out

- This skill have no trigger, just have requirement. User need to input value for entity #people. If missing, BOT will reply text to require user input persanal information like FULL NAME, EMAIL


- The same way, we will create another requirement with name #email


- The same way, add requirement for #location

CREATE ACTION FOR BOT
In this, we will build action for BOT. First we will build action for SKILL add-to-cart. After all requirement of skill add-to-catr finished, action will be triggered.
In this we also talk about how to trigger skill from one to another.


You've selected this product {{memory.product.raw}} in your cart. To proceed with your purchase, click here to checkout.


Next, we will create action for skill check-out

BUILD MENU FOR USER SELECT
Any BOT, we also have one skill called greetings. This skill will be trigger when user input default value example: Hi, Hello, …
We will edit this skill for user list menu and select there




TEST BOT





SUMMARY
In this article I shared tip how to get data from API response to create entity by using scripting syxtax. I also talk about how to trigger from one to another. Currently, we got some concept about SAP Conversational AI, we will be use these tips into SAP Process Automation to trigger one automatic in next article. Thanks for your reading and any advise kindly leave your comment on this.
See you next article.
Thanks
Joseph.