微软Bot框架,它可以开始对话

我正在Azure中使用微软Bot框架,并有一个工作的机器人。 但是,到现在为止,它处于空白状态,只是作出反应。 我想用类似的方式添加/开始对话:“嗨,我该怎么帮你?”

这是我的代码:

"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); }) .matches('get_price', (session, args) => { session.send('Hi, you asked about the cost of a service: oil change: $10, brakes: $50, transmission: $200: \'%s\'.', session.message.text); }) .matches('get_service', (session, args) => { session.send('Hi, you asked about car service options, here they are: oil change, brakes, and transmissions'); }) .matches('cant_service', (session, args) => { session.send('Sorry, we do not offer that service: \'%s\'.', session.message.text); }) .matches('schedule_apt', (session, args) => { session.send('Hi, you asked about scheduling an appointment, please call 1-800-fix-cars to schedule'); }) .matches('greeting', (session, args) => { session.send('Hi you!'); }) .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() } } 

你可以尝试下面的代码,并改变它来适应你的需求。 你可以在这里find这个和许多其他有用的节点SDK的片段

 bot.on('conversationUpdate', function (message) { if (message.membersAdded) { message.membersAdded.forEach(function (identity) { if (identity.id == message.address.bot.id) { var reply = new builder.Message() .address(message.address) .text("Welcome to my page"); bot.send(reply); } else { var address = Object.create(message.address); address.user = identity; var reply = new builder.Message() .address(address) .text("Hello %s I\'m botty McBotface", identity.name); bot.send(reply); bot.loadSession(address) session.send( "test" ) } }); } }); 

也不相关,你应该更新你的luis端点到这样的v2端点:

 westus.api.cognitive.microsoft.com/luis/v2.0/apps/