Comments (7)
You can initialize before you call alexa.execute()
in your Lambda event handler.
For example:
var Alexa = require('alexa-sdk');
exports.handler = function(event, context) {
var alexa = Alexa.handler(event, context);
initialize(() => {
alexa.execute();
});
}
function initialize(callback) {
// initialize your SDK here
callback();
}
Lambda is stateless, so two requests from a single user's session may go to different containers. You shouldn't rely on checking if the session is new if you're going to depend on the SDK on subsequent requests. You can cache your SDK after initializing to conserve resources.
from alexa-skills-kit-sdk-for-nodejs.
Yes, sorry, I should be more clear. I'm not concerned about running when the Lambda session is new, but only when a request comes in from Alexa with the session.new
variable set to true
. Running the code as you've shown here will run the initialize
function on every new Lambda request, which is not what I'm looking for.
from alexa-skills-kit-sdk-for-nodejs.
In that case, you can easily check the new
session attribute in the incoming request.
var Alexa = require('alexa-sdk');
exports.handler = function(event, context) {
var alexa = Alexa.handler(event, context);
initialize(event, () => {
alexa.execute();
});
}
function initialize(event, callback) {
if(event.session['new']){
// initialize your SDK here
}
callback();
}
You can see the JSON interface reference here.
from alexa-skills-kit-sdk-for-nodejs.
OK, that looks like it will work, thanks. What's the relationship between the special NewSession
handler and doing something like this?
from alexa-skills-kit-sdk-for-nodejs.
NewSession
can be defined to have different behavior depending on the current state, or can be skipped altogether. The above would run on all requests.
from alexa-skills-kit-sdk-for-nodejs.
Just out of curiosity, what analytics SDK are you using?
from alexa-skills-kit-sdk-for-nodejs.
OK, so I ended up checking the session.new
as your second example demonstrates. I'm using VoiceLabs.co for the analytics.
from alexa-skills-kit-sdk-for-nodejs.
Related Issues (20)
- Alexa hosted skill DynamoDB permission error HOT 12
- AskSdk.DynamoDbPersistenceAdapter Error: Could not read item HOT 2
- error when speak detects an accented character
- WebSocket error from ask-sdk-local-debug with EU region HOT 3
- ExpressAdapter.verifySignature causes skills to fail validation HOT 11
- Debugging doesn't work HOT 12
- Docs don't explain how to get Client ID
- Amazon content HOT 1
- Cannot send a proper response to Alexa after MQTT Publish
- Email HOT 1
- addAudioPlayerPlayDirective not playing some URLs HOT 1
- Keep Compiled code in a dist folder
- `AlexaHouseholdListEvent.ItemsCreated` only ever provides a single ItemId HOT 2
- AskSdk.DynamoDbPersistenceAdapter error after upgrading to aws-sdk v2.1269.0
- The directive Navigation.SetDestination it's not accepted in the sdk
- Inaccurate type definitions in `ask-sdk-model`
- Aws sdk V2 in maintenance mode, upgrade for v3 HOT 3
- `withAskForPermissionsConsentCard` generating errors
- Missing support for SMAPI Metrics API v2 HOT 1
- Dynamic media URL and intercepting AudioPlayer fetch requests for HLS long streaming
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from alexa-skills-kit-sdk-for-nodejs.