繁体   English   中英

使用触发词将对话数据永久存储在Azure聊天机器人中

[英]Using a trigger word to store conversation data permanently in a Azure chat bot

我正在开发天蓝色聊天机器人,特别是C#中的QnA机器人,现在我正在考虑将对话历史存储到表或数据库存储中。

但与Web上的大多数教程和文档不同,我不希望从头到尾存储整个会话,我只想存储用户发送给bot的第一条消息。 我希望此消息暂时存储,直到用户输入“no”。 当用户键入“否”时,我希望永久存储临时存储器中保存的内容。

聊天机器人可以这样做吗?

任何帮助或见解将非常感谢!

这可以通过临时存储很容易实现像字典一样。 有很多方法可以实现这一目标。 我要研究的一件事是用于捕获“否”文本的可见性 在这个例子中我没有使用scorables但它确实提供了你正在寻找的基本功能。 这个想法是当一条消息进来时,你检查是否已经保存了来自该userId的消息并保存了它,如果没有保存的话。 如果用户发送文本“否”,则将文本保存到永久存储器并从字典中删除该条目。 我只是在一个基本的RootDialog.cs中这样做:

    private async Task MessageReceivedAsync(IDialogContext context, IAwaitable<object> result)
    {
        var activity = await result as Activity;

        var userId = activity.From.Id;
        var message = activity.Text;
        if (!Utils.FirstMessageDictionary.ContainsKey(userId))
        {

            Utils.FirstMessageDictionary.Add(userId, message);
            await context.PostAsync($"Message saved {userId} - {Utils.FirstMessageDictionary[userId]}");
        }

        if (message.ToLower() == "no")
        {

            //save to permanent storage here 

            Utils.FirstMessageDictionary.Remove(userId);
            await context.PostAsync($"Entry Removed for {userId}");

            try
            {
                await context.PostAsync($"{userId} - {Utils.FirstMessageDictionary[userId]}");
            }
            catch (Exception e)
            {
                await context.PostAsync($"No entry found for {userId}");
            }
        }
        context.Wait(MessageReceivedAsync);
    }

我也为字典做了这个简单的类:

public static class Utils
{
    public static Dictionary<string, string> FirstMessageDictionary = new Dictionary<string, string>();
}

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM