Search code examples
c#botframework

Microsoft Bot State data store to SQL Server database using C#


How to store the bot state data to a SQL Server database? I have this code which performs form flow action and collects user inputs. These data I need to save it to database and show the user with a Request ID for future reference. As I'm new to these things, got struck on this stage.

Below is the code I'm working on.

// Hardware
public enum HardwareOptions
{
    Mouse, Printer, Keyboard, Monitor
};

[Serializable]
public class HardwareQuery
{
    [Prompt("Choose your {&} ? {||}")]
    public HardwareOptions? Hardware;

    [Prompt("Please enter {&}")]
    public string Details { get; set; }

    [Prompt("Please enter {&}")]
    public int Quantity { get; set; }

    [Prompt("Please provide your business need / {&} below")]
    public string Justification { get; set; }

    public static IForm<HardwareQuery> BuildForm()
    {
        return new FormBuilder<HardwareQuery>()
                .Message("Welcome to the PHI Create Hardware Request!")
                .Build();
    }
}

Solution

  • For Bot Framework SDKv4:

    As written here you need to implement the IStorage interface.

    You can take the example I made here as a blueprint.