我目前正在研究Bot框架技术,在我目前的项目中,我想将机器人对话数据存储到azure SQL数据库中。
我开发了一个ReviewBot,在这里我必须编写代码,以便用户对任何酒店进行评论/评级。
Bot与用户沟通工作正常,但我希望使用C#语言将我的机器人的用户对话数据存储到azure SQL数据库中。
请告诉我如何实施上述概念。
此致 普拉迪普
答案 0 :(得分:4)
我写了一个教程,显示了这个:Implementing A SQL Server Database With The Microsoft Bot Framework
关键代码是:
// *************************
// Log to Database
// *************************
// Instantiate the BotData dbContext
Models.BotDataEntities DB = new Models.BotDataEntities();
// Create a new UserLog object
Models.UserLog NewUserLog = new Models.UserLog();
// Set the properties on the UserLog object
NewUserLog.Channel = activity.ChannelId;
NewUserLog.UserID = activity.From.Id;
NewUserLog.UserName = activity.From.Name;
NewUserLog.created = DateTime.UtcNow;
NewUserLog.Message = activity.Text;
// Add the UserLog object to UserLogs
DB.UserLogs.Add(NewUserLog);
// Save the changes to the database
DB.SaveChanges();