Control access to a skill

Guards are used to control access to a skill. We can block the reading of the skill according to one condition! This is very useful for an authentication system. Here is the JS code:

import code from "./main.converse";
import notAuthorizedSkill from "./skills/not-authorized/not-authorized";

export default {
  code,
  canActivated: ["notAuthorizedSkill"],
  skills: {
    notAuthorizedSkill,
  },
};

Add the `canActivated property with children's skills to control access.

Here is the conversational script in ./skills/not-authorized/not-authorized.converse

@Event('canActivate')
auth() {
    > Your password ?
    Prompt()
    if (:text == 'azerty') {
        return true
    }
    return false
}

Put a function with the @Event('canActivate') decorator. This function will be executed as a priority. If the function returns true, the skill scenario will continue. Otherwise, if the function returns false then the user will not go further in the scenario

Last updated