Skip to content

Instantly share code, notes, and snippets.

@javichur
Last active November 19, 2019 01:45
Show Gist options
  • Save javichur/724f4c177951600c2f177caee349aebd to your computer and use it in GitHub Desktop.
Save javichur/724f4c177951600c2f177caee349aebd to your computer and use it in GitHub Desktop.
/* Ejemplo de intent handler que sugiere la compra del in-skill purchase si no se
* ha comprado ya antes y además el usuario puede comprarlo (purchasable)
*/
const HelloWorldIntentHandler = {
canHandle(handlerInput) {
return handlerInput.requestEnvelope.request.type === 'IntentRequest'
&& handlerInput.requestEnvelope.request.intent.name === 'HelloWorldIntent';
},
handle(handlerInput) {
SessionState.setCurrentState(handlerInput, SessionState.STATES.HELLO_WORLD);
// si no ha comprado la in-skill purchase... sugerir su compra cada X tiempo
const random = 10;
if (random >= Settings.NUM_FREE_ITEMS) {
const isEntitled = await PurchaseHandlers.isEntitledByProductId(handlerInput,
Settings.ID_PRODUCT_ISP);
if (!isEntitled) {
const isPurchasable = await PurchaseHandlers.isPurchasableByProductId(handlerInput,
Settings.ID_PRODUCT_ISP);
if (isPurchasable) {
return PurchaseHandlers.makeUpsellByProductId(handlerInput, Settings.ID_PRODUCT_ISP);
}
}
}
const speechText = LOC.t.HELLO_WORLD;
return AplTemplates.getAplTextAndHintOrVoice(handlerInput, LOC.t.SKILL_NAME, speechText,
LOC.t.HINT_HOME, speechText);
},
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment