0
votes

I have an application built in NodeJS and Angular2+. I want to integrate the NodeJs part with Alexa. I have surfed for the code but all I found was many Intents functions and then I even tried to look up into the following github link

https://github.com/alexa/skill-sample-nodejs-petmatch/blob/master/lambda/custom/index.js

But I am unable to figure out as to where to start from.

NodeJs code -

seekapi.service.js

// Require Neo4j

var neo4j = require('neo4j-driver').v1;

var path = require('path');
var logger = require('morgan');
var bodyParser = require('body-parser');
var express = require('express');

var router = express.Router();

var app = express();


// Create Driver

 const driver = new neo4j.driver("bolt://localhost:11001", neo4j.auth.basic("neo4j", "lib1"));



app.set('views', path.join(__dirname, 'views'));

 app.use(logger('dev'));
 app.use(bodyParser.json());
 app.use(bodyParser.urlencoded({ extended: false }));
 app.use(express.static(path.join(__dirname, 'public')));


var session = driver.session();
var request = require('request');

router.post('/', seekAPI);


 module.exports = router;


//working code below


function seekAPI(req, res) { 

    console.log("INSIDE NODE JS CONTROLLER OF seekAPI");

    console.log("BODY IS ", req.body);

        session

           .run(`MATCH p=()-[r:API]->() RETURN p;`)
           .then(function (result){

             res.send(result); 
               result.records.forEach(function(record){
                   console.log("record = ", record);


               });
               res.send(result); 
           })      
           .catch(function(err){
            console.log("inside catch = " + err);
        })

        session.close();   
}


console.log("Inside seekAPI-controller.js")
1

1 Answers

1
votes

As you have your code base (the API part) already written in your Angular app, you can expose your API on a web service. The web service should comply with contract given by Amazon. Once the web service is ready, configure the web service URL in Alexa console and your are done, Start invoking alexa right there.

The advantage is that, you can use your existing application deployment rather than running the same API again in AWS Lambda.

With web service method, you can even debug the skills on your local machine by using ngrok https endpoint.

I would prefer this web service way as I can develop all things on my local and deploy in my infrastructure.