You’ve probably heard about a prototype we demo at the ASUG Summit in Miami. The proposal was to present how easy companies can embrace the digital economy transforming their business on daily tasks (if you haven’t seen that before, you are probably not following the right people on twitter).
A bit different from what some of you asked me, this is not a core feature of SAP Business One (I know, sad right? ☹️ ), it’s a prototype developed by the Solution Architects team, just like many others we shared before.
Good news the code is open for you to use and implement your own version. And here is a tutorial of how to install the B1 Assistant and “retire” your keyboard for some B1 tasks.
So, grab your popcorn, sit tight, follow me on twitter and enjoy this how-to!
I will not go into details of the Echo development capabilities. If you want to navigate on those waters, check their official ASK (Alexa Skill kit) site (very well made, simple and with great samples) and this detailed tutorial by Jarkko Lane. But one thing that should be clear for you is:
Alexa (Amazon Echo’s persona) has several capabilities (Skills). Those are divided between Native (time, weather, traffic, news…) or 3rd Party (Uber, Spotify, Business One…)
To activate the 3rd party skill, we use Invocation Names. Those are nothing more than the name of the skill we want to call. For example: “Alexa, ask Uber for a ride” or “Alexa, open Spotify”. Once it hears your command, it will identify the skill to be triggered and call a specific Web Service that can be hosted on a Private Cloud or on AWS. Like this:
In our case, working the with B1 Assistant Skill the architecture is:
NOTE: On a productive scenario, we could bypass the AWS Lambda service and make Alexa communicates directly with HANA XS. That would require a secure HTTPs connection with a valid SSL Certificate. Thing we don’t have on most dev environment.
Beside the Invocation Names, the skills have 2 other attributes, the intent, which is the specific action to be activated and the slots that works as parameters of the first one.
Implementing the B1 Assistant
Enough with definitions and small talk, let’s go for the funny part. So you can have your own B1 Assistant.
- A SAP Business One on HANA 9.2 PL04 environment.
- PL03 will also work, with limited features (No Prediction)
- SBODEMOUS schema
- To work with different schema, please adapt all models and procedures
- An Amazon Developer account
- An Amazon Web Services Account
- An Amazon Echo (not mandatory, but pretty cool to demo)
All the code used in this tutorial is shared on my github
1 – Deploying the B1 Assistant HANA app
We’ve seen that whenever a user asks Alexa , it will trigger a Skill, this skill will call a function and this function will interact with an application (SAP Business One)
So let’s build our stack, starting by the end. The B1 Assistant App on HANA.
There 2 options for this part:
- You can import the b1Assistant application delivery unity into your HANA System
- Or just clone the code directly from my github and create your own XS project.
Whatever the case, once you have the b1Assistant package on your HANA system.
Go to HANA Administration Tools dashboard (http://hanaserver:8000/sap/hana/xs/admin) and set a user and password for the file: b1Assistant > lib > annonuser.xssqlcc
Note: Alexa will use this user to retrieve data and access the services.
You can also access http://hanaserver:8000/b1Assistant to test your app back-end
note: B1 user/pass is set on services/b1call.xsjs file
2 – Creating the B1 Assistant Lambda function
With the HANA App deployed, we need a function to call its services (Create orders, item recommendation, sales info). The responsible for it will be a Lambda Function.
Access your Amazon Web Services Account, switch to the Ireland or North Virginia region and select the Lambda Service.
Get started with a new Lambda function
On the blue print selection, search for Alexa and choose the skill tagged as alexa-skills-kit-color-expert
Select Alexa Skills Kit as a trigger
Set a name for your service, e.g b1Assistant and copy the code b1Assistant.js located on my github on the skill folder (set your HANA Server public IP where indicated)
Scroll down a bit and set the following configurations just like the screenshot below
note: 15 sec timeout will avoid issues when B1 Service Layer takes long time to respond.
On the next step you have to opportunity to review all settings and then, create your function.
Once the function is created we need to extract it’s ARN address. It’s quite simple, just do as the following. And copy this address somewhere you can find later.
3 – Creating the B1 Assistant Skill
We are almost there, all that is missing is the Alexa Skill to talk to our Lambda Function.
Log into the Amazon Developer website and chose Alexa on the top menu
Get started with a new Alex Skill Kit
Add a new skill
On the Skill information panel, set the Skill Name – B1 Assistant and Invocation Name – be one.
On the next window you should fill the Intent Schema, Custom Slot Types and Sample Utterances
The codes are available on the Skill folder on my github repository
Save, Go to the next step and paste the ARN address extracted previously, according to the region of your Lambda funciton (US or Ireland)
On the next step you can already test your skill and see that it is ready to work
Your B1 Assistant is ready to work! You can test it with your Amazon Echo by enabling the Skill on your Alexa app or use the Echo Simulator.
Spit it out!
Do you like it? Or maybe you hate it? Have any questions? Feel free to ask and let your comments below. Your feedback it much appreciated.
Special Thanks to the SAP Business One dev team in Shanghai that helped us with the predictive analysis feature! You rock!
Since this is a prototype, of course there are some limitations. One that stands is that currently B1 Assistant do not support multi currency environments.
The code is open source, so be my guest and contribute 😛