1
votes

I am working on a mini-project for self-development on 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

However, I was wondering if there is a way we can read the Bot Turn Activity from database?

For example:

Bot: Hello!

Me: Hello

Bot: What is your name?

Me: XYZ

So what I want is the activity Texts of Bot like Hello, What is your name?, ... should come from database (preferably SQL). Is this possible?

I am using Bot Framework v4.0 Emulator for local testing.

1
Is my answer acceptable? - Kyle Delaney

1 Answers

1
votes

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.

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. 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. 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.

As far as the Bot Framework side of things goes, please review the Azure Bot Service documentation for more information.