2017-04-03 10 views
11

अब 2 दिनों के लिए अलग-अलग मार्गों पर जा रहे हैं और इसे समझ नहीं सकते हैं। शायद कोई मेरी समस्याओं पर कुछ प्रकाश डाल सकता है। मैं एक बॉटसर्वर चलाने की कोशिश कर रहा हूं जो एकाधिक plaforms से जुड़ता है और पहले से ही लगभग 5 काम कर रहा है।अमेज़ॅन एलेक्सा, एलेक्सिया ऐप और मिडलवेयर

अब भी मैं एलेक्सा को एकीकृत करने की कोशिश कर रहा हूं। मैं अपने सर्वर में आने वाले एलेक्सा अनुरोध देख रहा हूं (इसलिए एलेक्सा कौशल और एंडपॉइंट कॉन्फ़िगरेशन सही हैं), हालांकि मुझे कुछ समय लगेगा क्योंकि अमेज़ॅन स्पष्ट रूप से पोर्ट 443 पर यातायात भेजता है, इसलिए अमेज़ॅन देव केंद्र में एक और पोर्ट नंबर को परिभाषित करने की अनुमति है , लेकिन कुछ नहीं करता ... अच्छा! पोर्ट अग्रेषण के साथ लोड बैलेंसर जोड़कर हल किया गया।

वास्तविक प्रश्न पर। मैं निम्न उदाहरण से मेरी ढांचे के रूप में एलेक्सा-एप्लिकेशन का उपयोग करने की कोशिश कर रहा हूँ:

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 

हिस्सा जो मैं समझ नहीं है कि यह कैसे उपयोग करने के लिए जब मैं सेटअप एक फ़ाइल में मेरी एक्सप्रेस सर्वर और उसके बाद करना चाहते हैं दूसरी फ़ाइल में मेरे श्रोता सेटअप करने के लिए मध्यस्थ समारोह का उपयोग करें ... कुछ की तरह:

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>; 
} 

किसी भी मदद या संकेतक के लिए धन्यवाद!

+0

मैं एलेक्सा-ऐप के लिए बाध्य नहीं कर रहा हूँ , इसलिए यदि लोगों के पास अन्य पुस्तकालय हैं जिनका उपयोग इसे प्राप्त करने के लिए किया जा सकता है, तो मैं सुझावों के लिए बहुत खुला हूं। – lleto

+0

अंत में मैं एक्सप्रेस और एलेक्सा-ऐप के आधार पर यह काम करने में कामयाब रहा। – lleto

+0

क्या आप इस समाधान के उत्तर के रूप में अपना समाधान पोस्ट कर सकते हैं? –

उत्तर

0

अंत में मैं एपलेक्स-एप के getMessagingHandler फ़ंक्शन पर epxress राउटर के माध्यम से अपने मुख्य app.js को कनेक्ट करने में कामयाब रहा। तो में app.js मार्ग अपने एलेक्सा अपने श्रोता में getMessagingHandler को webhook और उसके बाद श्रोता में:

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; 

मुख्य app.js में:

app.use('/alexa', controller.Bot.Alexa.Listener.getMessagingHandler()); 
संबंधित मुद्दे