VUI Structure for Apps With Account Linking


#1

I am developing a skill where most features heavily depend on having an account linked. There are a couple basic things like asking for FAQ like information, but for the most part to use the skill you have to be logged in.

I was thus thinking it would make the most sense to add a LoggedInState and then add most of my intent handlers under that while letting all the intents from non-logged-in users be rerouted through Unhandled. However, I cannot seem to find docs on how to add handlers from multiple files to a state.

i.e. I want to do something like this:

LoginState: {
require(...),
require(...),
...
}

^ Obviously not valid JavaScript, but I hope that gets the point across.

Is there a way to do the above/a best practice different from what I was trying?


#2

Hi @baileytincher, welcome to the Jovo Community :wave:

Quick question: Are you using TypeScript? We’re thinking about adding decorators for things like this.

For JavaScript, I can think of 2 options right now, but there’s probably more:

Option 1: if-statements

You’re probably already doing that and it feels clunky, but I think most people use if-statements like this at the beginning of every intent that requires account linking:

if (!this.$request.getAccessToken()) {
        return this.toIntent('Unhandled');
    }

Option 2: Create a Jovo Hook

One other idea (and I haven’t fully tested this for this use case) may be to use a Hook. The router middleware generates the path, so it could work to hook into this and then change the route that is then passed to the handler:

app.hook('router', (error, host, jovo) => {
    // ...
});

Use the jovo object to access the Jovo route elements (I think it could be found by logging jovo.$nlu) and then change it if you identify it as an intent that should be redirected.

I know this is kind of a vague answer, but hopefully this points you in the right direction. let me know if you have any questions


#3

Is it possible to have a hook provide a response? This is what we were trying, but jovo.tell does not do anything on execution (no errors, but it goes along to the intent), and neither does the showAccountLinkingCard call.

app.hook('before.handler', async (error, host, jovo) => {
  const token = jovo.$request.getAccessToken();
  let user = jovo.$session.$data.user;

  if (!token) {
    jovo.$alexaSkill.showAccountLinkingCard();
    jovo.tell('Please link your Account by opening the Alexa app.');
  } else if (!user) {
    user = await getUser(token);

    if (user) {
      jovo.$session.$data.user = user;
    } else {
      jovo.tell(`I am having trouble verifying your login.
          Please try relinking your account through the Alexa app.`);
    }
  }
});