我试图将alexa连接到mysql。 数据库通过xampp存储在localhost中。 我已经完美地获得了nodejs-mysql连接,但是当我尝试将其与alexa合并时,它说
"无法调用远程端点,或者它返回的响应无效。" 我的数据库文件: -
var mysql=require('mysql');
var con=mysql.createConnection({
host:'localhost',
user: 'root',
password:'',
database:'ctp'
});
function answer(){}
answer.prototype.getdata= function(question,callback)
{
sql="select answer from jarvis where question="+question;
con.query(sql,function(err,rows,fields)
{
callback(rows);
})
}
module.exports=answer;
我的index.js文件: -
'use strict';
var AlexaSkill = require('./AlexaSkill'),
recipes = require('./recipes'),
dbcon=require('./dbconfig');
var mys=new dbcon();
var APP_ID = "amzn1.ask.skill.1bfd2f06-1c46-464f-9f06-9195691e0aae"; //OPTIONAL: replace with 'amzn1.echo-sdk-ams.app.[your-unique-value-here]';
var HowTo = function () {
AlexaSkill.call(this, APP_ID);
};
// Extend AlexaSkill
HowTo.prototype = Object.create(AlexaSkill.prototype);
HowTo.prototype.constructor = HowTo;
HowTo.prototype.eventHandlers.onLaunch = function (launchRequest, session, response) {
var speechText = "Welcome to My Jarvis, version 1 point oh... How can I help you?";
// If the user either does not reply to the welcome message or says something that is not
// understood, they will be prompted again with this text.
var repromptText = "For instructions on what you can say, please say help me.";
response.ask(speechText, repromptText);
};
HowTo.prototype.intentHandlers =
{
"QuestionIntent": function (intent, session, response) {
var itemSlot = intent.slots.Item,
itemName,sp;
if (itemSlot && itemSlot.value){
itemName = itemSlot.value.toLowerCase();
}
sp=itemName;
mys.getdata(sp,function(rows)
{
sp=rows;
});
var cardTitle = "Details for " + itemName,
//recipe=recipes[itemName],
recipe = sp,
speechOutput,
repromptOutput;
if (recipe) {
//window.open("http://www.w3schools.com");
speechOutput = {
speech: recipe,
type: AlexaSkill.speechOutputType.PLAIN_TEXT
};
response.tellWithCard(speechOutput, cardTitle, recipe);
} else {
var speech;
speech = "There are no plans for you today";
}
speechOutput = {
speech: speech,
type: AlexaSkill.speechOutputType.PLAIN_TEXT
};
repromptOutput = {
speech: "What else can I help with?",
type: AlexaSkill.speechOutputType.PLAIN_TEXT
};
response.ask(speechOutput, repromptOutput);
},
"AMAZON.StopIntent": function (intent, session, response)
{
var speechOutput = "Goodbye";
response.tell(speechOutput);
},
"AMAZON.CancelIntent": function (intent, session, response) {
var speechOutput = "Goodbye";
response.tell(speechOutput);
},
"AMAZON.HelpIntent": function (intent, session, response) {
var speechText = "You can ask questions such as, what's the plan for today, or, you can say exit... Now, what can I help you with?";
var repromptText = "You can say things like, what's the plan for today, or you can say exit... Now, what can I help you with?";
var speechOutput = {
speech: speechText,
type: AlexaSkill.speechOutputType.PLAIN_TEXT
};
var repromptOutput = {
speech: repromptText,
type: AlexaSkill.speechOutputType.PLAIN_TEXT
};
response.ask(speechOutput, repromptOutput);
}
};
//what code do you want to see?
exports.handler = function (event, context)
{
var howTo = new HowTo();
howTo.execute(event, context);
};
我有两个sp分配,因为我想查看函数调用是否有效,它没有,它只显示标识的itemName
所以看到以前的论坛,一些亚马逊帮助者告诉我把lambda请求作为测试事件放在lambda控制台中,我已经尝试过了
{
"errorMessage": "RequestId: 7a56e239-d4cc-11e6-9671-cfba622fbaaf Process exited before completing request"
}
我想知道为什么alexa不会等待回调执行并将结果查询回sp并进入speechOutput, 另外,context.done()/ succeed()如何帮助这个?我已经尝试将上下文对象传递给dbconfig文件,但它不起作用。 你能告诉我一个解决方案吗?或至少提供alexa-mysql文档(如果存在)?