将对话历史记录从MS bot保存到cosmos db [英] Save conversation history from MS bot to cosmos db

查看:79
本文介绍了将对话历史记录从MS bot保存到cosmos db的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在开发的机器人取代了希望与公司联系的潜在客户的联系表格,因此用户输入必须保存在数据库中.我已成功将Cosmos DB连接到我的机器人,该机器人在使用机器人时会收集状态数据.我有一个对话框堆栈,每个用户输入(名称,电子邮件和用户要离开的消息)只有一个对话框.

The bot I'm developing is a replacement for a contact form for potential clients that want to be contacted by a company, so the user inputs have to be saved in a database. I have successfully connected a Cosmos DB to my bot which collect the state data when the bot is used. I have a dialog stack with one dialog per user input (Name, email and the message the user want to leave).

我找不到任何有关如何保存用C#编写的机器人的对话历史记录的有用文档.谁能帮我吗?我仍然是Bot Framework和C#的初学者.

I can't find any helpful documentation on how to save conversation history for bots written in C#. Can anyone help me out? I'm still a beginner in Bot Framework and C#.

这是我的global.asax文件:

Here is my global.asax file:

 public class WebApiApplication : System.Web.HttpApplication
{
    protected void Application_Start()
    {
        GlobalConfiguration.Configure(WebApiConfig.Register);
        var uri = new Uri(ConfigurationManager.AppSettings["DocumentDbUrl"]);
        var key = ConfigurationManager.AppSettings["DocumentDbKey"];
        var store = new DocumentDbBotDataStore(uri, key);

        Conversation.UpdateContainer(
                    builder =>
                    {
                        builder.Register(c => store)
                            .Keyed<IBotDataStore<BotData>>(AzureModule.Key_DataStore)
                            .AsSelf()
                            .SingleInstance();

                        builder.Register(c => new CachingBotDataStore(store, CachingBotDataStoreConsistencyPolicy.ETagBasedConsistency))
                            .As<IBotDataStore<BotData>>()
                            .AsSelf()
                            .InstancePerLifetimeScope();

                    });

    }
}

这是我的NameDialog,用于收集用户名:(其他对话框几乎与此相同)

Here is my NameDialog to collect the user's name: (the other dialogs are almost identical to this)

[Serializable]
public class NameDialog : IDialog<string>
{
    private int attempts = 3;

    public async Task StartAsync(IDialogContext context)
    {
        await context.PostAsync("What's your name?");

        context.Wait(this.MessageReceivedAsync);
    }

    private async Task MessageReceivedAsync(IDialogContext context, IAwaitable<IMessageActivity> result)
    {
        var message = await result;


        if ((message.Text != null) && (message.Text.Trim().Length > 0))
        {

            context.Done(message.Text);
        }

        else
        {
            --attempts;
            if (attempts > 0)
            {
                await context.PostAsync("I couldn't understand, can you try again?");

                context.Wait(this.MessageReceivedAsync);
            }
            else
            {

                context.Fail(new TooManyAttemptsException("This is not a valid input"));
            }
        }
    }
}

推荐答案

我提交了几条评论,要求您对所要查找的内容进行澄清,但我想我也可能会提供一个全面的答案.

I submitted a couple of comments asking for clarification in what you're looking for, but figured I may as well just provide an all-encompassing answer.

>

使用V4

如果您的机器人是新机器人,只需使用BotBuilder/BotFramework的V4.更容易,功能更多,支持更好.无论如何,我都会提供答案.

If your bot is new, just use V4 of BotBuilder/BotFramework. It's easier, there's more features, and better support. I'll provide answers for both, anyway.

参考:

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆