jovotech / jovo-framework

🔈 The React for Voice and Chat: Build Apps for Alexa, Messenger, Instagram, the Web, and more
https://www.jovo.tech
Apache License 2.0
1.67k stars 310 forks source link

Implement Alexa Shopping #1074

Closed guilhermelirio closed 2 years ago

guilhermelirio commented 2 years ago

I'm submitting a...

Expected Behavior

https://developer.amazon.com/en-US/docs/alexa/alexa-shopping/implement-shopping-actions.html

Alexa Shopping allows you to create skills where you can add products from an official store to your cart.

It uses the add Directive function (which already exists in the Jovo), but it needs a special intent type: SessionResumedRequest At the link above, there are examples.

aswetlow commented 2 years ago

Hey @guilhermelirio

Thank you for the feature request. As a workaround you could use hooks:

// app.ts
app.hook('after.platform.init', (error: JovoError, host: Host, jovo: Jovo, next: Function) => {
    alexaSkill.$type = {
        type: 'ON_SESSION_RESUMED',
      };
});

app.setHandler({
    ON_SESSION_RESUMED() {
    }
 });
guilhermelirio commented 2 years ago

Don't work:

app.hook('after.platform.init', (error, host, jovo) => {
  jovo.$alexaSkill.$type = {
    type: 'ON_SESSION_RESUMED',
  };
});

app.setHandler({

  ON_SESSION_RESUMED() {
    console.log('teste')
  },

  LAUNCH() {
    return this.showSimpleCard('Teste Hook', strings.intro).ask(strings.intro);
  },
})

It goes through console.log('test') and stops there.

aswetlow commented 2 years ago

In this case it won't route to LAUNCH after ON_SESSION_RESUMED

This will return the card and ask response.

app.setHandler({
  ON_SESSION_RESUMED() {
    return this.showSimpleCard('Teste Hook', strings.intro).ask(strings.intro);
  },
})
guilhermelirio commented 2 years ago

Hi @aswetlow , thanks for the help.

So that way, on all intent calls, it executes ON_SESSION_RESUMED.

In my case, I would need it to work the same as Alexa Shopping, but I believe this is not possible.

aswetlow commented 2 years ago

Yes, you have to make the check in the hook:

app.hook('after.platform.init', (error, host, jovo) => {
  if(jovo.$reqeust.request.type === 'XXXXX') {
    jovo.$alexaSkill.$type = {
       type: 'ON_SESSION_RESUMED',
    };
  }
});
guilhermelirio commented 2 years ago

Thanks @aswetlow , it`s work!