【问题标题】:How to store only the users response when using the Azure chat bot使用 Azure 聊天机器人时如何仅存储用户响应
【发布时间】:2018-08-01 08:24:48
【问题描述】:

我正在尝试将用户响应存储在表存储中。我只想存储他们输入的用户数据,对机器人的响应不感兴趣。 这怎么可能?另外,这在触发词上是否可行,例如,当用户说“不”时,它会在那里记录与机器人的第一次交互,例如“Hello”。

我已经对此主题进行了大量研究,但仅存储用户输入的记录似乎较少。

对此的任何帮助将不胜感激!

【问题讨论】:

  • How is this possible and additionally would this be possible on a trigger word, for example when the user says "no" it logs there first interaction with the bot for example "Hello".你能详细说明一下这个要求吗?
  • 当用户输入“No”时,他们发送的第一条消息将被存储。例如:您好,我是聊天机器人,我该如何帮助您我的电脑无法正常工作——第一条消息将其关闭并重新打开,这有帮助吗?否 --Trigger @FeiHan 这有助于澄清吗?
  • When the user types the word "No", their first message they send will be stored.你好@L.Full,根据你的要求,我分享了一个回复,请参考。

标签: c# azure botframework azure-table-storage chatbot


【解决方案1】:

我正在尝试将用户响应存储在表存储中。我只想存储他们输入的用户数据,对机器人的响应不感兴趣。这怎么可能?另外,这在触发词上是否可行,例如,当用户说“不”时,它会在那里记录与机器人的第一次交互,例如“Hello”。

您似乎只想将用户输入存储在表存储中,而不是存储机器人响应的数据。为了达到这个要求,你可以截取用户在MessagesController(或在对话框MessageReceivedAsync方法中)发送的消息,然后从activity中提取你想要的属性值并将值存储在你的表存储中。

public static string firstmessage = null;

/// <summary>
/// POST: api/Messages
/// Receive a message from a user and reply to it
/// </summary>
public async Task<HttpResponseMessage> Post([FromBody]Activity activity)
{
    if (activity.Type == ActivityTypes.Message)
    {
        if (firstmessage == null)
        {
            firstmessage = activity.Text?.ToString();
        }

        storeuserinput(activity);

        await Conversation.SendAsync(activity, () => new Dialogs.RootDialog());

    }
    else
    {
        HandleSystemMessage(activity);
    }
    var response = Request.CreateResponse(HttpStatusCode.OK);
    return response;
}

private void storeuserinput(Activity activity)
{
    var uid = activity.From.Id;
    var uname = activity.From.Name;

    if (activity.Text?.ToLower().ToString() == "no")
    {
        var userinput = firstmessage;
    }

    //extract other data from "activity" object

    //your code logic here
    //store data in your table storage

    //Note: specifcial scenario of user send attachment
}

如果您想将数据存储到 Azure 表存储中,可以使用 WindowsAzure.Storage client library 将实体存储/添加到表中。

此外,Bot Builder SDK 中的the middleware functionality 使我们能够拦截用户与机器人之间交换的所有消息,您可以参考以下代码 sn-p 来实现相同的要求。

public class MyActivityLogger : IActivityLogger
{
    public async Task LogAsync(IActivity activity)
    {
        if (activity.From.Name!= "{your_botid_here}")
        {
            var uid = activity.From.Id;
            var uname = activity.From.Name;

            var userinput = (activity as IMessageActivity).Text?.ToString();

            //extract other data from "activity" properties

            //your code logic here
            //store data in your table storage

            //Note: specifcial scenario of user send attachment

        }
    }
}

【讨论】:

  • 感谢您的回复,我该如何将它放入我的 Azure 表存储中? @FeiHan
  • 就像将用户输入变量加载到表存储中一样
  • how would I go about putting this into my Azure table storage? 您可以参考this article 将其作为实体添加到您的表格中。
  • 如何将其应用于将机器人响应用作触发器?
猜你喜欢
  • 2018-10-15
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2022-01-23
  • 1970-01-01
相关资源
最近更新 更多