为了访问我的本地SQL DB(2014),我在NodeJS中开发了一个简单的REST API,使用的npm包是“ mssql”,我在邮递员中进行了测试,并在笔记本电脑中使用了本地的bot模拟器将解决方案部署到Azure时,收到超时错误:
节点REST API:
var sql = require("mssql");
var express = require('express'); // Web Framework
var app = express();
var dbconfig ={
user: "sa",
password: "password",
server: "myServer",
database: "Reports",
port: 1433,
options:{
encrypt: false
}
}
var server = app.listen(8200, function () {
var host = server.address().address
var port = server.address().port
console.log("app listening at http://%s:%s", host, port)
});
批号:
var builder = require('botbuilder');
var restify = require('restify');
var Request = require("request");
var connector = new builder.ChatConnector({
appId:"apid",
appPassword:"pass"
});
var inMemoryStorage = new builder.MemoryBotStorage();
var bot = new builder.UniversalBot(connector).set('storage', inMemoryStorage);
var dialog = new builder.IntentDialog();
dialog.matches(/^soporte/i, [
function (session, args, next) {
if (session.message.text.toLowerCase() == 'soporte') {
builder.Prompts.text(session, 'Cual es el Ticket?');
} else {
var query = session.message.text.substring(8);
next({ response: query });
}
},
function (session, result, next) {
// var resultado = Consulta();
var card = new builder.ThumbnailCard(session);
card.title('Soporte');
// card.images([builder.CardImage.create(session, profile.avatar_url)]);
card.subtitle('Soporte en linea');
var text = '';
var cardTxt='';
Request.get("http://ipaddress/customers", (error, res, body) => {
if(error) {
return console.dir(error);
}
console.log(body);
text = JSON.parse(body);
console.log(text);
text = text.recordset[0]
for(var myKey in text) {
cardTxt = cardTxt + myKey+": "+text[myKey]+" ";
}
console.log(cardTxt);
card.text(cardTxt);
});
var message = new builder.Message(session).attachments([card]);
session.send(message);
}
]);
bot.dialog('/', dialog);
var server = restify.createServer();
server.listen(process.env.port || process.env.PORT || 3978, function () {
console.log('%s listening to %s', server.name, server.url);
});
server.post('/api/messages', connector.listen());
错误:仅在部署时出现:
{ Error: connect ETIMEDOUT xxx.xxx.xxx.212:8200
at Object.exports._errnoException (util.js:1026:11)
at exports._exceptionWithHostPort (util.js:1049:20)
at TCPConnectWrap.afterConnect [as oncomplete] (net.js:1085:14)
code: 'ETIMEDOUT',
errno: 'ETIMEDOUT',
syscall: 'connect',
address: 'xxx.xxx.xxx.212',
port: 8200 }