Skip to content

Instantly share code, notes, and snippets.

View ankkal's full-sized avatar

Ankit Kala ankkal

  • Amazon
  • Bangalore
View GitHub Profile
@ankkal
ankkal / PersistenceInterceptor.js
Created May 2, 2018 17:14
Request and Response Interceptors for Persistance in Node JS V2 SDK
const RequestPersistenceInterceptor = {
process(handlerInput) {
if(handlerInput.requestEnvelope.session['new']) {
return new Promise((resolve, reject) => {
handlerInput.attributesManager.getPersistentAttributes()
.then((sessionAttributes) => {
try {
consentToken = this.event.context.System.user.permissions.consentToken;
deviceId = this.event.context.System.device.deviceId;
apiEndpoint = this.event.context.System.apiEndpoint;
if(!consentToken || !deviceId || !apiEndpoint) {
throw("User did not give us permissions to access their address.");
}
} catch(e) {