Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

200
Views
Amazon Alexa, alexa-app and middleware

have been going different routes for 2 days now and can't figure it out. Perhaps someone can shed some light on my problems. I am trying to run a botserver that connects to multiple plaforms and already have around 5 working.

I am now also trying to integrate Alexa. I am seeing Alexa requests coming into my server (so the Alexa skill and endpoint config are correct), however this also took me quite some time as Amazon apparently only sends traffic to port 443, so defining another port number in Amazon dev center is allowed, but does nothing... nice! Solved by adding a load balancer with port forwarding.

Onto the real question. I am trying to use alexa-app as my framework from the following example:

var express = require("express");
var alexa = require("alexa-app");
var express_app = express();

var app = new alexa.app("sample");

app.intent("number", {
    "slots": { "number": "AMAZON.NUMBER" },
    "utterances": ["say the number {-|number}"]
  },
  function(request, response) {
    var number = request.slot("number");
    response.say("You asked for the number " + number);
  }
);

// setup the alexa app and attach it to express before anything else 
app.express({ expressApp: express_app });

// now POST calls to /sample in express will be handled by the app.request() function 
// GET calls will not be handled 

// from here on, you can setup any other express routes or middleware as normal 

The part which I can't figure out is how to use this when I setup my express server in one file and then want to use the middleware function to setup my listener in the second file... something like:

app.js:

var express = require("express");
var express_app = express();

https.createServer({
    key: fs.readFileSync(key),
    cert: fs.readFileSync(cert),
    ca: fs.readFileSync(ca)
}, app).listen(port, function () {
   console.log("http:  api server listening on port " + port);
});

app.use('/alexa', controller.Bot.Messenger.Listener.botMiddleWare());

listener.js:

var alexa = require("alexa-app");
var app = new alexa.app("sample");

bot.botMiddleWare = function botMiddleWare () {
    return <return function to connect to express in app.js>;
}

Thanks for any help or pointers!

about 4 years ago · Santiago Trujillo
1 answers
Answer question

0

In the end I managed to connect my main app.js via epxress router to the getMessagingHandler function of the alexa-app. So in the app.js route your alexa webhook to the getMessagingHandler in your listener and then in the listener:

var bot = new alexa.app('my_bot');

bot.getMessagingHandler = function getMessagingHandler() {
    return function (req, res) {
         req.on('end', function(){
             var jsonData = JSON.parse(requestBody);
             if(jsonData.request.type == "LaunchRequest") {
               // handle response here
             }
         }
    }
}
module.exports = bot;

In the main app.js:

app.use('/alexa', controller.Bot.Alexa.Listener.getMessagingHandler());
about 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!