alexa / alexa-skills-kit-sdk-for-nodejs

The Alexa Skills Kit SDK for Node.js helps you get a skill up and running quickly, letting you focus on skill logic instead of boilerplate code.
Apache License 2.0
3.12k stars 736 forks source link

Use Alexa SDK without lambda #263

Closed Dallanosm closed 6 years ago

Dallanosm commented 6 years ago

Hello,

This issue has been opened and closes several times, but we don't have any solution:

In this repo we have the issue: Using this without Lambda

Here we have: #72 and #200 but not resolved yet.

We want use the alexa skill without lambda, could be this possible?

Best regards, Daniel.

wolter commented 6 years ago

This workaround works for me:

var express = require('express');
var bodyParser = require('body-parser');
var app = express();
// Initialize the Alexa SDK
var Alexa = require('alexa-sdk');
app.use(bodyParser.json());
app.post('/', function(req, res) {
    // Build the context manually, because Amazon Lambda is missing
    var context = {
        succeed: function (result) {
            console.log(result);
            res.json(result);
        },
        fail:function (error) {
            console.log(error);
        }
    };
    // Delegate the request to the Alexa SDK and the declared intent-handlers
    var alexa = Alexa.handler(req.body, context);
    alexa.registerHandlers(handlers);
    alexa.execute();
});

Cheers,

Sascha.

sujeetjaiswara commented 6 years ago

Thanks @wolter

kyle-wrenn commented 6 years ago

Thanks @wolter ! That worked perfectly. Just out of curiosity, do you know the standard context functions look like? I couldn't find any documentation from Amazon on the context object and logging it didn't really help much.

wolter commented 6 years ago

@kyle-wrenn here you go https://docs.aws.amazon.com/lambda/latest/dg/nodejs-prog-model-context.html

maegnes commented 6 years ago

Is there yet another workaround for the v2 ask-sdk?

mklntf commented 6 years ago

Same question as @maegnes. Is there a workaround for ASK SDK v2 for node.js? My code:

const express = require('express');
const bodyParser = require('body-parser');
const alexa = require('ask-sdk-core');
const verifier = require('alexa-verifier-middleware');

const handlers = require('./handlers');

const port = 3000;
const path = '/laborsteuerung';
const app = express();

app.get('/', (req, res) => {
    res.send('Online');
});

app.post(path, verifier, bodyParser.json(), function (req, res) {
  // Alexa code here
})

app.listen(port, () => {
    console.log('Server listening on port ' + port + '!');
});

NEVERMIND I found the answer here https://github.com/alexa/alexa-skills-kit-sdk-for-nodejs/issues/362#issuecomment-384686134