我正在使用以下脚本,但是这个脚本抛出的错误是serveStatic不是一个函数 我已使用此命令“npm install --save restify”
安装了restifyvar restify = require('restify');
var builder = require('botbuilder');
var server = restify.createServer();
server.listen(process.env.port || process.env.PORT || 3978, function () { });
// Create the chat connector for communicating with the Bot Framework Service
var connector = new builder.ChatConnector({
appId: '***',
appPassword: '***'
});
// Listen for messages from users
server.post('/api/messages', connector.listen());
server.get('/', restify.serveStatic({
directory: __dirname,
default: '/index.html'
}));
var bot = new builder.UniversalBot(connector, function (session) {
var msg = session.message;
if (msg.attachments && msg.attachments.length > 0) {
// Echo back attachment
var attachment = msg.attachments[0];
session.send({
text: "You sent:",
attachments: [
{
contentType: attachment.contentType,
contentUrl: attachment.contentUrl,
name: attachment.name
}
]
});
} else {
// Echo back users text
session.send("You said: %s", session.message.text);
}
});
以上代码在执行
时抛出此错误C:\Users\Tushar\botforarticle\app.js:20
server.get('/', restify.serveStatic({
^
TypeError: restify.serveStatic is not a function
at Object.<anonymous> (C:\Users\Tushar\botforarticle\app.js:20:25)
at Module._compile (module.js:570:32)
at Object.Module._extensions..js (module.js:579:10)
at Module.load (module.js:487:32)
at tryModuleLoad (module.js:446:12)
at Function.Module._load (module.js:438:3)
at Module.runMain (module.js:604:10)
at run (bootstrap_node.js:394:7)
at startup (bootstrap_node.js:149:9)
at bootstrap_node.js:509:3
答案 0 :(得分:18)
显然,这在v5.0.0中已经发生了变化(仅在几天前发布),但文档尚未更新。
试试这个:
server.get('/', restify.plugins.serveStatic({
directory: __dirname,
default: '/index.html'
}));