Skip to content

Instantly share code, notes, and snippets.

View javichur's full-sized avatar
🏠
Working from home

Javier Campos javichur

🏠
Working from home
View GitHub Profile
@javichur
javichur / apl_template_export.json
Last active February 9, 2019 23:29
apl_template_export.json --> documentAPL.json + datasourceAPL.json
{
"document": {
"type": "APL",
"version": "1.0",
"theme": "dark",
"import": [
{
"name": "alexa-layouts",
"version": "1.0.0"
}
/* in-skill purchases */
const PurchaseHandlers = require('./handlers/purchaseHandlers.js');
const initPurchaseHandlers = {
process(handlerInput) {
PurchaseHandlers.methodPostPurchase = initializeSkill; // reload session after purchase, etc.
PurchaseHandlers.methodPostRefund = initializeSkill; // reload session after refund, etc.
PurchaseHandlers.LOC = LOC; // strings
PurchaseHandlers.speakPostPurchase = LOC.t.SPEAK_POST_PURCHASE;
PurchaseHandlers.speakPostRefund = LOC.t.SPEAK_POST_REFUND;
const skillBuilder = Alexa.SkillBuilders.custom();
exports.handler = skillBuilder
.addRequestHandlers(
...
PurchaseHandlers.WhatCanIBuyIntentHandler, // purchase handlers
PurchaseHandlers.TellMeMoreAboutProductIntentHandler,
PurchaseHandlers.BuyIntentHandler,
PurchaseHandlers.BuyResponseHandler,
PurchaseHandlers.PurchaseHistoryIntentHandler,
PurchaseHandlers.RefundProductIntentHandler,
/* 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);
...
"types": [
{
"name": "LIST_OF_PRODUCT_NAMES",
"values": [
{
"id": "nameproductpurchase", /* id de producto comprable (isp)*/
"name": {
"value": "suscripción premium",
"synonyms": [
@javichur
javichur / skill.json
Created January 25, 2020 16:38
Añadiendo soporte para notificaciones en una skill Alexa
{
"manifest": {
"apis": {
// ...
},
"manifestVersion": "1.0",
"privacyAndCompliance": {
// ...
},
"publishingInformation": {
const https = require('https');
const mode = 'prod'; // dev or 'prod'
const clientID = 'xxx'; // obtenido de consola web de Alexa developers.
const clientSecret = 'xxx'; // obtenido de consola web de Alexa developers.
let tokenGlobal = null; // se usa para enviar notificaciones. Dura 1h. Se rellena en notify().
// Ejemplo de envío de una notificación
const who = 'cake';
@javichur
javichur / index.js
Created April 11, 2020 20:38
Alexa account linking Facebook
const HelloWorldIntentHandler = {
canHandle(handlerInput) {
return Alexa.getRequestType(handlerInput.requestEnvelope) === 'IntentRequest'
&& Alexa.getIntentName(handlerInput.requestEnvelope) === 'HelloWorldIntent';
},
handle(handlerInput) {
var accessToken = handlerInput.requestEnvelope.context.System.user.accessToken; // obtener el Access Token (si lo hay)
var speechText = '';
if (accessToken == undefined){
/* eslint-disable no-console */
/* eslint-disable global-require */
// More info about Alexa Location Services:
// https://developer.amazon.com/es-ES/docs/alexa/custom-skills/location-services-for-alexa-skills.html
const auto = {
getFrescuraSegundos(handlerInput) {
var geoObject = handlerInput.requestEnvelope.context.Geolocation;
return (new Date(handlerInput.requestEnvelope.request.timestamp) - new Date(geoObject.timestamp)) / 1000; // freshness in seconds
const Sentry = require("@sentry/serverless");
Sentry.AWSLambda.init({
dsn: 'https://examplePublicKey@o0.ingest.sentry.io/0', // cambiar por el DSN que te proporciona Sentry.
tracesSampleRate: 1.0,
});
exports.handler = Sentry.AWSLambda.wrapHandler(async (event, context) => {
// Your handler code
// TODO