js是第一次尝试在node.js中使用Microsoft的Azure bot框架开发机器人。
我添加到下面的完整代码(这是一个模板)的唯一代码是:
.matches('None', (session, args) => {
session.send('Hi, this is the None handler. You said: \'%s\'.', session.message.text);
});
以下是完整代码:
"use strict";
var builder = require("botbuilder");
var botbuilder_azure = require("botbuilder-azure");
var path = require('path');
var useEmulator = (process.env.NODE_ENV == 'development');
var connector = useEmulator ? new builder.ChatConnector() : new botbuilder_azure.BotServiceConnector({
appId: process.env['MicrosoftAppId'],
appPassword: process.env['MicrosoftAppPassword'],
stateEndpoint: process.env['BotStateEndpoint'],
openIdMetadata: process.env['BotOpenIdMetadata']
});
var bot = new builder.UniversalBot(connector);
bot.localePath(path.join(__dirname, './locale'));
// Make sure you add code to validate these fields
var luisAppId = process.env.LuisAppId;
var luisAPIKey = process.env.LuisAPIKey;
var luisAPIHostName = process.env.LuisAPIHostName || 'westus.api.cognitive.microsoft.com';
const LuisModelUrl = 'https://' + luisAPIHostName + '/luis/v1/application?id=' + luisAppId + '&subscription-key=' + luisAPIKey;
// Main dialog with LUIS
var recognizer = new builder.LuisRecognizer(LuisModelUrl);
var intents = new builder.IntentDialog({ recognizers: [recognizer] })
/*
.matches('<yourIntent>')... See details at http://docs.botframework.com/builder/node/guides/understanding-natural-language/
*/
.matches('None', (session, args) => {
session.send('Hi, this is the None handler. You said: \'%s\'.', session.message.text);
});
.onDefault((session) => {
session.send('Sorry, I did not understand \'%s\'.', session.message.text);
});
bot.dialog('/', intents);
if (useEmulator) {
var restify = require('restify');
var server = restify.createServer();
server.listen(3978, function() {
console.log('test bot endpont at http://localhost:3978/api/messages');
});
server.post('/api/messages', connector.listen());
} else {
module.exports = { default: connector.listen() }
}
这是错误:
SyntaxError: Unexpected token .
at Object.exports.runInThisContext (vm.js:76:16)
at Module._compile (module.js:528:28)
at Object.Module._extensions..js (module.js:565:10)
at Module.load (module.js:473:32)
at tryModuleLoad (module.js:432:12)
at Function.Module._load (module.js:424:3)
at Module.require (module.js:483:17)
at require (internal/module.js:20:19)
at eval (eval at compileFunc (D:\Program Files (x86)\SiteExtensions\Functions\1.0.11015\bin\edge\double_edge.js:34:28), <anonymous>:1:80)
at compileFunc (D:\Program Files (x86)\SiteExtensions\Functions\1.0.11015\bin\edge\double_edge.js:35:16).
2017-07-12T18:21:57.420 Function started (Id=71b6a39b-ebca-4bc4-a642-5e7cfb68c921)
2017-07-12T18:21:57.420 Function completed (Failure, Id=71b6a39b-ebca-4bc4-a642-5e7cfb68c921, Duration=0ms)
2017-07-12T18:21:57.436 Exception while executing function: Functions.messages. mscorlib: D:\home\site\wwwroot\messages\index.js:42
.onDefault((session) => {
^
SyntaxError: Unexpected token .
at Object.exports.runInThisContext (vm.js:76:16)
at Module._compile (module.js:528:28)
at Object.Module._extensions..js (module.js:565:10)
at Module.load (module.js:473:32)
at tryModuleLoad (module.js:432:12)
at Function.Module._load (module.js:424:3)
at Module.require (module.js:483:17)
at require (internal/module.js:20:19)
答案 0 :(得分:0)
你在这里链接功能
var intents = new builder.IntentDialog({ recognizers: [recognizer] })
.matches('None', (session, args) => {
session.send('Hi, this is the None handler. You said: \'%s\'.', session.message.text);
});
^ should be removed
.onDefault((session) => {
session.send('Sorry, I did not understand \'%s\'.', session.message.text);
});
matches.(...)
之后的分号是多余的