In this blog post, we are going to discuss on how the feature to post user feedback was implemented on the SUSI. AI server side. The API endpoint by which a user can post feedback for a Skill is https://api.susi.ai/cms/feedbackSkill.json.
It accepts five url parameters –
- model – It tells the model to which the skill belongs. The default value is set to General.
- group – It tells the group(category) to which the skill belongs. The default value is set to Knowledge.
- language – It tells the language to which the skill belongs. The default value is set to en.
- skill – It is the name of the skill to be given a feedback. It is a compulsory param.
- feedback – It is the parameter that contains the string type feedback of the skill, that the user wants to update.
The minimalUserRole is set to USER for this API, as only logged-in users can use this API.
Going through the API development
- The parameters are first extracted via the call object that is passed to the main function. The parameters are then stored in variables. If any parameter is absent, then it is set to the default value.
- There is a check if the skill exists. It is done by checking, if there exists a file corresponding to that skill. If no, then an exception is thrown.
- This code snippet discusses the above two points –
- Then the feedbackSkill.json that was initialized in the DAO object, is then opened. It is a JSONTray, which is then parsed.
- It is checked if the skill is previously rated or not. If yes, has the user rated it before or not. In the case, when the user has given a feedback for it already, we just need to make changes in the feedbackSkill.json file as the feedback_count key present in the skillRatings.json doesn’t change. In case, the user hasn’t given the feedback earlier, the changes also needs to be reflected on the skillRatings.json file. For this use, the utility function addToSkillRatingJSON is called. The feedback_count of that skill is increased by one, as it is a unique feedback and changes need to be reflected on the file.
- The response object is then sent with three key values mainly, apart from the session object. They are –
- accepted – true – It tells that the skill feedback has been updated.
- message – “Skill feedback updated”
- feedback – <feedback> – It is the string that the client has sent as feedback.
Here are code snippets and data objects that will help in understanding the API well –
- addToSkillRating function –
- Sample of feedbackSkill.json file –
- Sample of skillRatings.json file –
I hope the development of creating the aforesaid API is clear and proved to be helpful for your understanding.