Botframework 如何在node.js中获取Microsoft azure bot sdk 4.0中的会话对象?
附加下面的代码段。botbuilder 4.1.5中不推荐使用UniversalBot和ChatConnectorBotframework 如何在node.js中获取Microsoft azure bot sdk 4.0中的会话对象?,botframework,Botframework,附加下面的代码段。botbuilder 4.1.5中不推荐使用UniversalBot和ChatConnector var bot; try { bot = new BasicBot(conversationState, userState, botConfig); } catch (err) { console.error(`[botInitializationError]: ${ err }`); process.exit(); } // Create HTTP s
var bot;
try {
bot = new BasicBot(conversationState, userState, botConfig);
} catch (err) {
console.error(`[botInitializationError]: ${ err }`);
process.exit();
}
// Create HTTP server
// let server = restify.createServer();
let server = express();
server.listen(process.env.port || process.env.PORT || 3978, function() {
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 basic-bot.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);
});
});
你的问题相当笼统 已删除3.x中的会话对象。而是使用访问器。您将希望在bot类中执行以下操作:
public onTurn = async (turnContext: TurnContext) => {
const userProfile = await this.userProfile.get(turnContext, new UserProfile());
const conversationData = await this.dialogStateAccessor.get(turnContext, { dialogStack: undefined });
// set vars in cache
userProfile.yourUserVarProp = "userValue";
conversationData.yourConversationVarProp = "conversationValue";
// persist userVars through dialog turn
await this.userProfile.set(turnContext, userProfile);
// persist conversationVars through dialog turn
await this.dialogStateAccessor.set(turnContext, conversationData);
//
// -> your dialogs here (await dc.beginDialog("dialogname");)
//
// save uservars to db at end of a turn
await this.userState.saveChanges(turnContext);
// save conversationVars to db at end of a turn
await this.conversationState.saveChanges(turnContext);
}
但是还有一些额外的构造函数
- @param{ConversationState}ConversationState用于存储对话框状态的ConversationState对象
- @param{UserState}UserState用于存储特定于用户的值的UserState对象