Adding report skills feature in SUSI iOS
SUSI.AI is having a various type of Skills that improving the user experience. Skills are powering the SUSI.AI personal chat assistant. SUSI skills have a nice feedback system. We have three different feedback way for SUSI skills, 5-star rating system, posting feedback, and reporting skills.
5-Star Rating – rate skills from 1 (lowest) to 5 (highest) star
Posting Feedback – user can post feedback about particular skill
Report Skill – user can report skill if he/she found it inappropriate
In this post, we will see how reporting skills feature work in SUSI iOS and how it is implemented. You can learn about 5-star rating here and posting feedback feature here.
Adding report skill button –
let reportSkillButton: UIButton = { let button = UIButton(type: .system) button.contentHorizontalAlignment = .left button.setTitle("Report Skill", for: .normal) button.setTitleColor(UIColor.iOSGray(), for: .normal) button.titleLabel?.font = UIFont.systemFont(ofSize: 16) button.translatesAutoresizingMaskIntoConstraints = false return button }()
In above, we have set translatesAutoresizingMaskIntoConstraints
property for false. By default, the property is set to true for any view you programmatically create. If you add views in Interface Builder, the system automatically sets this property to false. If this property’s value is true, the system creates a set of constraints that duplicate the behavior specified by the view’s autoresizing mask.
Setting up report skill button –
We are setting constraints programmatically as we created button programmatically and set translatesAutoresizingMaskIntoConstraints
to false. Also, setting a target to the button.
if let delegate = UIApplication.shared.delegate as? AppDelegate, let _ = delegate.currentUser { view.addSubview(reportSkillButton) reportSkillButton.widthAnchor.constraint(equalToConstant: 140).isActive = true reportSkillButton.heightAnchor.constraint(equalToConstant: 32).isActive = true reportSkillButton.leftAnchor.constraint(equalTo: contentType.leftAnchor).isActive = true reportSkillButton.topAnchor.constraint(equalTo: contentType.bottomAnchor, constant: 8).isActive = true reportSkillButton.addTarget(self, action: #selector(reportSkillAction), for: .touchUpInside) }
In the above method, we can see that we are only showing button if user is logged-in. Only a logged-in user can report the skill. To check if user is logged in or not, we are using the AppDelegate
shared instance where we save the logged-in user globally when the user signs in.
When user clicks the Report Skill button, a popup is open up with a text field for feedback message like below:
When user clicks the Report
action after typing feedback message, we are using the following endpoint:
https://api.susi.ai/cms/reportSkill.json
With the following parameters –
- Model
- Group
- Skill
- Language
- Access Token
- Feedback
Here is how we are handling the API call within our app –
func reportSkill(feedbackMessage: String) { if let delegate = UIApplication.shared.delegate as? AppDelegate, let user = delegate.currentUser { let params = [ Client.SkillListing.model: skill?.model as AnyObject, Client.SkillListing.group: skill?.group as AnyObject, Client.SkillListing.skill: skill?.skillKeyName as AnyObject, Client.SkillListing.language: Locale.current.languageCode as AnyObject, Client.SkillListing.accessToken: user.accessToken as AnyObject, Client.SkillListing.feedback: feedbackMessage as AnyObject ] Client.sharedInstance.reportSkill(params) { (success, error) in DispatchQueue.main.async { if success { self.view.makeToast("Skill reported successfully") } else if let error = error { self.view.makeToast(error) } } } } }
On successfully reported skill, we show a toast with ‘Skill reported successfully’ message and if there is error reporting the skills, we present the toast with error as a message.
Resources –
You must be logged in to post a comment.