Integration Of Sap CAI Chatbot + Amazon Alexa with R3 Corda Blockchain

UMUT
10 min readDec 21, 2020

Introduction:

R3 Corda Blockchain platform is one of the most used Private Blockchain solutions together with Hyperledger Fabric. In this article, we will set up an “Auction” application on a Corda network and then create an API to access this network from outside. Later, we will set up on the SAP CAI Chatbot with Amazon Alexa skill and use the Corda Auction API to interact with our chatbot.

Check out my last article about Sap RPA and Corda Integration, if you want.

R3 Corda Installations

1- First of all, we install the infrastructures we need to run the R3 Corda solution with the latest version of VSCode, which makes it very easy for us to make our Corda improvements, from the links below.

JAVA 8 SDK
VSCODE
Git
Gradle

2- After installing VSCode, we install the following plugin, which is a plugin that will help us a lot while managing our Corda network.

3- Then we run mac terminal and download our corda samples package to our home directory.

$ git clone https://github.com/corda/samples-java.git

We are now ready to activate our R3 Corda network and run our Auction app on it.
In the samples-java folder we downloaded, we find the Auction-App folder in Advanced.

Important Note: In order for the Corda plug-in in VSCode to understand that this package is a Corda application, you need to make the right choice that includes the appropriate packages. If you show the Samples Java folder by saying Open Folder in VSCode and then try to go to the Auction break from it, you will have a problem using the plugin. Let’s do it as follows.

After opening the package, if you have not installed Java plugins and Gradle properly, it will give you some warning and VSCode will guide you to install these plugins. In this way, you can install Gradle. If you have installed the VSCode Corda plugin properly and you have shown the Auction-Cordapp folder correctly, you should have seen the Corda-Project assignment, which I marked in green below. This will show you that everything is fine.

Now you will do to run this example will be surprisingly simple.
There are 3 main components pre-prepared in our R3 Corda sample.

  • Corda Network Infrastructure
  • Contract and Workflows to run on Corda Network
  • Our Client application that will allow us to connect externally to our workflows and smart contracts running on the Corda Network and the UI side of it written in Angular.

After opening our package in Visual Studio Code
By pressing Shift + Command + P we will view the features that Corda Extension offers us.

1- We are waiting to select and complete the transactions to activate our Corda network and deploy our nodes.

If the process is successful, you will see a screen like the one below. A, B, C and Notary Nodes have been successfully created.

Trading parties on our “Auction” Network are represented as Part A, Party B and Party C. Notary is the node that includes the consensus mechanism of our network, which is also the Ordering service in the Hyperledger Fabric solution, and is responsible for the approval and ordering of transactions. We saw that it was installed automatically when we run the .gradlew DeployNodes command via Extension.

2- The next step is to run these nodes that we deployed and for this, let’s use the extension again.

We do Shift + Command + P and this time choose Corda Run Nodes.
After running it, you will see that a separate terminal screen is opened for each node as in the VsCode terminal screen below, and each of the nodes is working independently from each other and ready to process.

You should see the screen below for each node.

What have we done so far?

We did the node setup and started our nodes.
Now the infrastructure of our Corda network is ready. Next, triggering transactions within the Corda network via the Client API. For this, we will make use of our Client subproject created before in our project.

Note: As I said before, I do not mention the details of our Corda project here, since the article is long enough, it will cause us to miss the outline. Those who want to work on Corda or in more detail, those who will take the certification exams, can also contact me on LinkedIn.

3- We will use our Corda Client API links to trigger transactions in the Corda network on SAP CAI Chatbot.

Note: Normally, we can trigger this local api that we created via Cloud Connector and Sap Cloud Platform Destinations on Sap Cloud Platform. But this time I took a different path. By using NGROK, which provides us with a solution that developers will often need for testing, we will easily open our local API to the outside and execute transactions using this API link on the SAP CAI Chatbot side.

At first, we will publish our api at http://localhost:8085. After that, we will open to the outside with Ngrok and we will have the ability to communicate from outside with flows in the Corda network.

Let’s follow the steps below to run our Client API and view our Angular interface on http://localhost: 8085.

We will open a new terminal screen and make the Client API working using the command below.

Mac:auction-cordapp umtyzc$ ./gradlew runAuctionClient

It does not matter if it is stopped at 94%. If you see the screen below. Now you can go to http://localhost: 8085 and upload the Demo Data to the system and manage your Corda Auction network through the interface.

By clicking Setup Demo Data, we can upload our sample data to the network to be used for the “Auction”.

After that, those who wish can make tests on the Corda network with this interface and view the logs of their operations on VSCode and some important information in a tidy manner using the Show Node Explorer option in the Extension as follows.

Shift + Command + P -> Show Node Explorer

Finally, to open our Corda API we created in our local network, let’s install Ngrok and complete the Corda process by getting our public link.

Let’s download and install the Ngrok solution from this link.

After the installation is finished, let’s open our API that we previously published in 8085 local with the following command.

Mac:~ umtyzc$ ./ngrok http 8085

Our new link is as follows. Now we can access our api from outside.

SAP CAI Chatbot

First of all, we go to the Chatbot application from the link below. If we have a Sap account, we can log in with it. If not, we can create an account from scratch and try the chatbot product for free.

cai.tools.sap

1- We start to create a new bot with the new bot option on the screen that opens.

2- We determine the features of our bot as follows.

3- After the bot has been successfully created, the first step is to create an intent. This will be our function that is triggered at the top of our chatbot tree. Click create intent and value: ask.

4- Then we need to click on our intent and create an expression under it. Let’s name it I’m interested in and hit enter.

5- Let’s go back to our train main tab and create an entity named corda as follows. After creating the Entity, we will click on it and create its values.

Important note: This part is important because we will send the entity value fields that we will create under the entity we created as parameters when calling our Corda API.

6- Let’s create two separate entity values ​​to pull the list of assets in our “Corda Auction” application and existing auction information from our Corda network. We made these naming according to the information in our api.

list

getCashBalance

Note: We use api base url : api/auction to create external service.

7- Now we press the train and let our bot learn the improvements we have made so far. In our next step, we will add skill to our bot. We come to the build tab and create a skill called answer.

8- Then we go into it and show the ask function we created earlier as a trigger.

9- We set the requirements section as #corda as corda and we will reply from the function and write the following message to the missing part. This will enable our chatbot to send us an introduction message when we send any value except entity values ​​and direct us.

10- Finally, we come to the Actions section and create a new message group and under it, we write the link to our Corda API from the Connect External Service section.

11- We add the list and getCashBalance information we determined earlier to the end of our link to get it from memory and give the name corda to the response section. We complete the last step of our api service configuration in the form of {{api_service_response.corda.body.data}}. You can see all the steps below.

After saving, we click on the train button for our bot to learn these features and we can now try our chatbot from the chat preview at the bottom right. We have triggered our API below, which returns our balance information in our Corda network.

Let’s integrate this with Amazon Alexa now. :)

Amazon Alexa + SAP CAI Chatbot

1- We will open our Amazon Alexa account from the Connect section and create a skill there that triggers our chat bot. For this, we need to follow the steps below.

No need to explain the first 2 steps. Those who do not have an account will create an account. Those with old accounts can be linked. We will do the authorization. The next steps are important.

2- To integrate our chatbot with Amazon Alexa, we create a new intent named start and add an expression named CONVERSATION_START under it.

3- Then I create a channel as “cordabot-awesome-amazonalexa-channel”, I say “corda” as Invocation Name. We will be able to see this in our Amazon Alexa account. We deploy this skill to our amazon account. We choose development in the Connect section.

From now on, our job will be on Amazon Alexa.

When we enter our Amazon Alexa account, we select your skills from the Skills section and from there we come to the DEV Skills section. Here we can see the skill that will talk to our deployed SAP Chatbot.

We are not testing our skill here. Let’s open the Alexa Developer Console to experiment.

Let’s write the Invocation name in corda, which we defined earlier and wait for the result. It connected to our Sap Chatbot and triggered our function that we communicated with R3 Corda Application.

Now I’ll try it with the Amazon Echo dot device I have. : )

Echo Dot video is here…

Good year to everyone :)

Let 2021 be more positive for all of us😊❤️.

References:

1- https://github.com/corda/samples-java

2- https://developers.sap.com/tutorials/conversational-ai-webhook-api-call.html

--

--

UMUT

SAP ABAP Developer/DLT&Blockchain Consultant