【问题标题】:How to store user conversation data with bot into azure SQL database using C# langugage?如何使用 C# 语言将与 bot 的用户对话数据存储到 Azure SQL 数据库中?
【发布时间】:2016-10-17 12:07:28
【问题描述】:

我目前正在研究 Bot 框架技术,在我当前的项目中,我想将 bot 对话数据存储到 Azure SQL 数据库中。

我已经开发了一个 ReviewBot,在此我必须编写代码以按用户对任何酒店进行评论/评分。

Bot 与用户通信工作正常,但我想使用 C# 语言将与我的 bot 的用户对话数据存储到 azure SQL 数据库中。

请告诉我如何实现上述概念。

问候, 普雷迪普

【问题讨论】:

  • 您需要保存哪些对话数据?整个对话?
  • 只是为了确认一下,您是否希望将机器人数据(即用户、对话和私人对话属性包)存储在 SQL Server 中?

标签: azure-sql-database bots botframework


【解决方案1】:

我写了一个教程来展示这个: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();

【讨论】:

    猜你喜欢
    • 2018-09-21
    • 2019-05-26
    • 2021-02-20
    • 1970-01-01
    • 2011-03-26
    • 1970-01-01
    • 2021-12-21
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多