我知道之前曾有人问过这个问题,但是我发现作者所采用的解决方案不适合我。因此,我不得不再次询问。抱歉。
我已经按照here
所述的步骤使用Bot Builder SDK v4和Yeoman生成了漫游器。回答了几个简单的问题后,已生成带有文件的目录框架。
Mode LastWriteTime Length Name
---- ------------- ------ ----
d----- 02/01/2019 16:58 cognitiveModels
d----- 02/01/2019 16:58 deploymentScripts
d----- 02/01/2019 16:58 dialogs
d----- 02/01/2019 16:59 node_modules
-a---- 02/01/2019 17:21 47 .env
-a---- 02/01/2019 16:58 313 .eslintrc.js
-a---- 02/01/2019 16:58 22 .gitignore
-a---- 02/01/2019 16:58 12042 bot.js
-a---- 02/01/2019 17:12 682 dev-hr-app.bot
-a---- 02/01/2019 17:28 5087 index.js
-a---- 02/01/2019 16:59 210624 package-lock.json
-a---- 02/01/2019 16:58 1179 package.json
-a---- 02/01/2019 16:58 1600 PREREQUISITES.md
-a---- 02/01/2019 16:58 3106 README.md
现在,我正在尝试在本地运行bot,以便可以使用bot框架模拟器连接到它,并且出现以下错误:
> node ./index.js
Error reading bot file. Please ensure you have valid botFilePath and
botFileSecret set for your environment.
- The botFileSecret is available under appsettings for your Azure Bot
Service bot.
- If you are running this bot locally, consider adding a .env file with
botFilePath and botFileSecret.
- See https://aka.ms/about-bot-file to learn more about .bot file its use
and bot configuration.
这是.env文件的内容:
botFilePath="./dev-hr-app.bot"
botFileSecret=""
这是我的.bot文件的内容:
{
"name": "dev-hr-app",
"services": [
{
"type": "endpoint",
"name": "development",
"endpoint": "http://localhost:3978/api/messages",
"appId": "",
"appPassword": "",
"id": "1"
}
{
"type": "luis",
"name": "dev-hr-app",
"appId": "<ID>", <- deleted
"version": "0.1",
"authoringKey": "<Key>", <- deleted
"subscriptionKey": "<Key>", <- deleted
"region": "westus",
"id": "206"
}
],
"padlock": "",
"version": "2.0"
}
这是我的index.js文件的内容:
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.
// index.js is used to setup and configure your bot
// Import required packages
// const env = require('dotenv').config({path: './.env'});
const path = require('path');
const restify = require('restify');
// Import required bot services. See https://aka.ms/bot-services to learn more about the different parts of a bot.
const { BotFrameworkAdapter, MemoryStorage, ConversationState, UserState } = require('botbuilder');
// Import required bot configuration.
const { BotConfiguration } = require('botframework-config');
// This bot's main dialog.
const { BasicBot } = require('./bot');
// Read botFilePath and botFileSecret from .env file
// Note: Ensure you have a .env file and include botFilePath and botFileSecret.
const ENV_FILE = path.join(__dirname, '.env');
require('dotenv').config({ path: ENV_FILE });
// Get the .bot file path
// See https://aka.ms/about-bot-file to learn more about .bot file its use and bot configuration.
const BOT_FILE = path.join(__dirname, (process.env.botFilePath || ''));
let botConfig;
try {
// Read bot configuration from .bot file.
botConfig = BotConfiguration.loadSync(BOT_FILE, process.env.botFileSecret);
} catch (err) {
console.error(`\nError reading bot file. Please ensure you have valid botFilePath and botFileSecret set for your environment.`);
console.error(`\n - The botFileSecret is available under appsettings for your Azure Bot Service bot.`);
console.error(`\n - If you are running this bot locally, consider adding a .env file with botFilePath and botFileSecret.`);
console.error(`\n - See https://aka.ms/about-bot-file to learn more about .bot file its use and bot configuration.\n\n`);
process.exit();
}
// For local development configuration as defined in .bot file
const DEV_ENVIRONMENT = 'development';
// bot name as defined in .bot file or from runtime
const BOT_CONFIGURATION = (process.env.NODE_ENV || DEV_ENVIRONMENT);
// Get bot endpoint configuration by service name
const endpointConfig = botConfig.findServiceByNameOrId(BOT_CONFIGURATION);
// Create adapter.
// See https://aka.ms/about-bot-adapter to learn more about .bot file its use and bot configuration .
const adapter = new BotFrameworkAdapter({
appId: endpointConfig.appId || process.env.microsoftAppID,
appPassword: endpointConfig.appPassword || process.env.microsoftAppPassword
});
// Catch-all for errors.
adapter.onTurnError = async (context, error) => {
// This check writes out errors to console log
// NOTE: In production environment, you should consider logging this to Azure
// application insights.
console.error(`\n [onTurnError]: ${ error }`);
// Send a message to the user
await context.sendActivity(`Oops. Something went wrong!`);
// Clear out state
await conversationState.delete(context);
};
// Define a state store for your bot.
// See https://aka.ms/about-bot-state to learn more about using MemoryStorage.
// A bot requires a state store to persist the dialog and user state between messages.
let conversationState, userState;
// For local development, in-memory storage is used.
// CAUTION: The Memory Storage used here is for local bot debugging only. When the bot
// is restarted, anything stored in memory will be gone.
const memoryStorage = new MemoryStorage();
conversationState = new ConversationState(memoryStorage);
userState = new UserState(memoryStorage);
// CAUTION: You must ensure your product environment has the NODE_ENV set
// to use the Azure Blob storage or Azure Cosmos DB providers.
// Add botbuilder-azure when using any Azure services.
// const { BlobStorage } = require('botbuilder-azure');
// // Get service configuration
// const blobStorageConfig = botConfig.findServiceByNameOrId(STORAGE_CONFIGURATION_ID);
// const blobStorage = new BlobStorage({
// containerName: (blobStorageConfig.container || DEFAULT_BOT_CONTAINER),
// storageAccountOrConnectionString: blobStorageConfig.connectionString,
// });
// conversationState = new ConversationState(blobStorage);
// userState = new UserState(blobStorage);
// Create the main dialog.
let bot;
try {
bot = new BasicBot(conversationState, userState, botConfig);
} catch (err) {
console.error(`[botInitializationError]: ${ err }`);
process.exit();
}
// Create HTTP server
let server = restify.createServer();
server.listen(process.env.port || process.env.PORT || 3978, () => {
console.log(`\n${ server.name } listening to ${ server.url }`);
console.log(`\nGet Bot Framework Emulator: https://aka.ms/botframework-emulator`);
console.log(`\nTo talk to your bot, open dev-hr-app.bot file in the Emulator`);
});
// Listen for incoming activities and route them to your bot main dialog.
server.post('/api/messages', (req, res) => {
// Route received a request to adapter for processing
adapter.processActivity(req, res, async (turnContext) => {
// route to bot activity handler.
await bot.onTurn(turnContext);
});
});
请问有人指出这个问题的解决方案吗?
非常感谢您
答案 0 :(得分:2)
在您的.bot文件中,services
数组中的两个项目之间缺少逗号。应该如下所示:
{
"name": "dev-hr-app",
"services": [
{
"type": "endpoint",
"name": "development",
"endpoint": "http://localhost:3978/api/messages",
"appId": "",
"appPassword": "",
"id": "1"
},
{
"type": "luis",
"name": "dev-hr-app",
"appId": "<ID>", <- deleted
"version": "0.1",
"authoringKey": "<Key>", <- deleted
"subscriptionKey": "<Key>", <- deleted
"region": "westus",
"id": "206"
}
],
"padlock": "",
"version": "2.0"
}