简体   繁体   English

如何从 Bot Framework 中的数据库中获取 Bot Activity Message?

[英]How to bring the Bot Activity Message from database in Bot Framework?

I am working on a mini-project for self-development on Bot Framework.我正在 Bot Framework 上进行自我开发的小型项目。 Need some help here on my requirement.在我的要求上需要一些帮助。 I want the Bot Conversation (Only bot NOT the user) to be fetched from database.我希望从数据库中获取机器人对话(仅机器人而不是用户)。 I know how to send an activity and get the user response using static text as I have done below.我知道如何发送活动并使用静态文本获取用户响应,就像我在下面所做的那样。

I have this code:我有这个代码:

private static async Task<DialogTurnResult> NameConfirmStepAsync(WaterfallStepContext stepContext, CancellationToken cancellationToken)
    {
        var promptOptions = new PromptOptions
        {
            Prompt = MessageFactory.Text($"Hello ! My name is XYZ and I am the Manager of ABC Dept.")
        };
    return await stepContext.PromptAsync(nameof(TextPrompt), promptOptions, cancellationToken);
    }

    private static async Task<DialogTurnResult> NameStepAsync(WaterfallStepContext stepContext, CancellationToken cancellationToken)
    {
        stepContext.Values["intro"] = ((FoundChoice)stepContext.Result);
        return await stepContext.PromptAsync(nameof(TextPrompt), new PromptOptions { Prompt = MessageFactory.Text("What is your name?") }, cancellationToken);
    }

The above code is for the Bot's activity once User says something上面的代码是针对 Bot 的活动,一旦用户说了些什么

However, I was wondering if there is a way we can read the Bot Turn Activity from database?但是,我想知道是否有办法从数据库中读取 Bot Turn Activity?

For example:例如:

Bot : Hello!机器人:你好!

Me : Hello:你好

Bot : What is your name?机器人:你叫什么名字?

Me : XYZ:XYZ

So what I want is the activity Texts of Bot like Hello , What is your name?所以我想要的是像你好你叫什么名字的 Bot 活动文本 , ... should come from database (preferably SQL) . , ...应该来自数据库(最好是 SQL) Is this possible?这可能吗?

I am using Bot Framework v4.0 Emulator for local testing.我正在使用 Bot Framework v4.0 Emulator 进行本地测试。

The first thing to understand is that bots are just web apps.首先要了解的是,机器人只是网络应用程序。 The question of how to get data into a bot from a database is just the question of how to read data from a database and it has nothing to do with bots.如何从数据库中获取数据到机器人中的问题只是如何从数据库中读取数据的问题,与机器人无关。 Your question fundamentally cannot be answered since you have not chosen a specific database management system.您的问题根本无法回答,因为您没有选择特定的数据库管理系统。 If your data is in a database that your bot has access to somehow (like with a REST API) then the answer is yes.如果您的数据位于您的机器人可以以某种方式访问​​的数据库中(例如使用 REST API),那么答案是肯定的。

Storing data in databases like Cosmos DB is a feature that's already built into the Bot Framework, but that has to do with bot state which is data that helps the bot keep track of specific users and conversations.将数据存储在 Cosmos DB 等数据库中是 Bot Framework 内置的一项功能,但这与机器人状态有关,该状态是帮助机器人跟踪特定用户和对话的数据。 It sounds like what you want is static data that defines the bot and isn't specific to any particular user or conversation.听起来您想要的是定义机器人的静态数据,而不是特定于任何特定用户或对话。 It's common for C# apps to store strings in resource files, and the Bot Framework has an upcoming language generation feature that you might be interested in, but if you really want to pull strings from a database then go ahead. C# 应用程序将字符串存储在资源文件中是很常见的,并且 Bot Framework 具有您可能感兴趣的即将推出的语言生成功能,但如果您真的想从数据库中提取字符串,请继续。 It's up to you to figure out how to do this since you haven't even decided what DBMS you want to use, but I can tell you that the way you do it won't be bot-specific in any case.由您决定如何执行此操作,因为您甚至还没有决定要使用什么 DBMS,但我可以告诉您,在任何情况下,您执行此操作的方式都不会特定于机器人。

As far as the Bot Framework side of things goes, please review the Azure Bot Service documentation for more information.就 Bot Framework 方面而言,请查看Azure Bot 服务文档以获取更多信息。

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

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