Fetching Private Skill from SUSI Server
SUSI Server needs to provide an API which would return the private skill’s file content. The private skill is used for the botbuilder project. Since the skill is private, the fetching process is little different from that of the public skills. The client has to provide the user’s access_token and a parameter private to access the private skill instead of the public skill. This blog explains how the private skill is being fetched from the SUSI Server.
Understanding the API
The API used to fetch public skill is /cms/getSkill.json, with the following parameters:
- Model
- Group
- Language
- Skill
These parameters helps to uniquely identify the skill.
The same API is used to fetch private skill too. But the parameters changes to:
- Access_token
- Private
- Group
- Language
- Skill
The access token is used to authenticate the user, since the user should only be able to fetch their own private skill. The access token is also used to extract the user’s UUID which will be useful for locating the private skill.
String userId = null; if (call.get("access_token") != null) { // access tokens can be used by api calls, somehow the stateless equivalent of sessions for browsers ClientCredential credential = new ClientCredential(ClientCredential.Type.access_token, call.get("access_token")); Authentication authentication = DAO.getAuthentication(credential); // check if access_token is valid if (authentication.getIdentity() != null) { ClientIdentity identity = authentication.getIdentity(); userId = identity.getUuid(); } }
Fetching the Private Skill from private skill repository
Now that we have all the necessary parameters, we can fetch the private skill from the susi_private_skill_data repository. The susi_private_skill_data folder has the following structure:
Thus to locate the skill, we will need the above parameters which we got from client and the user’s UUID. The following code checks if the client is requesting for private skill and changes the directory path accordingly.
// if client sends private=1 then it is a private skill String privateSkill = call.get("private", null); File private_skill_dir = null; if(privateSkill != null){ private_skill_dir = new File(DAO.private_skill_watch_dir,userId); } String model_name = call.get("model", "general"); File model = new File(DAO.model_watch_dir, model_name); if(privateSkill != null){ model = private_skill_dir; }
Result:
Resources
- JSON Object in java: https://docs.oracle.com/javaee/7/api/javax/json/JsonObject.html
- Work with Files in java: https://docs.oracle.com/javase/7/docs/api/java/io/File.html
You must be logged in to post a comment.