Created
April 11, 2020 20:38
-
-
Save javichur/df3989e4295b5f027ba883f989256413 to your computer and use it in GitHub Desktop.
Alexa account linking Facebook
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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){ | |
// Si la request no incluye el Access Token, entonces mostrar la Card en la app de Alexa para solicitar el login. | |
speechText = "Debes hacer login en Facebook a través de la app de Alexa de tu móvil. Por favor abre la app Alexa en tu móvil para continuar.."; | |
return handlerInput.responseBuilder | |
.speak(speechText) | |
.withLinkAccountCard() | |
.getResponse(); | |
} else { | |
// si llega accessToken, puedo hacer peticiones autenticadas al backend (facebook). Ejemplo: | |
// GET https://graph.facebook.com/me?fields=id,name&access_token=<ACCESS_TOKEN_AQUI> | |
// devolverá el ID de facebook del usuario logueado, con dicho ID puedo hacer consultas en la base de datos (ver pedidos del usuario, etc). | |
// ... | |
} | |
} | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment