1. Operational Store for Bot Framework on Azure Cosmos DB


    To create an operational store for a Bot Framework using Azure Cosmos DB, we need to set up a Cosmos DB account and create the necessary database containers that the bot can use for its operations. The Cosmos DB service provides several APIs, such as SQL (DocumentDB), MongoDB, Cassandra, etc., for working with data that can be best chosen based on the specific requirements of the bot and the developer’s experience.

    The example below uses the Azure Cosmos DB SQL API for its ease of use and familiarity for those coming from a SQL background, though other APIs are equally viable.

    First, we need to define several components:

    1. Cosmos DB Account: This is the primary resource needed to work with Cosmos DB.
    2. Database: Within a Cosmos DB account, we will create a database to contain our collections.
    3. Container: A container, sometimes called a collection, is where the data is actually stored in the form of JSON documents. For our bot's operational store, we may define one or more containers depending on how we want to categorize the data.
    4. Optionally, we can configure settings such as throughput, partition keys, etc., to optimize for performance based on the expected workload.

    The program below outlines how you could set up an operational store for Bot Framework on Azure Cosmos DB using Pulumi with Python:

    import pulumi import pulumi_azure_native.documentdb as documentdb # Configuration variables for the Cosmos DB Account resource_group_name = 'myResourceGroup' # Replace with your resource group name account_name = 'myCosmosDbAccount' # Replace with your desired Cosmos DB account name database_name = 'botDatabase' # Replace with your desired database name container_name = 'botContainer' # Replace with your desired container name # Create an Azure Resource Group resource_group = documentdb.ResourceGroup(f"resource_group", resource_group_name=resource_group_name) # Create a Cosmos DB Account cosmos_db_account = documentdb.DatabaseAccount(f"cosmos_db_account", resource_group_name=resource_group.name, account_name=account_name, locations=[documentdb.LocationArgs( location_name="West US", # Choose the location appropriate for your use case failover_priority=0, )], database_account_offer_type=documentdb.DatabaseAccountOfferType.STANDARD, # Set the offer type ) # Create a SQL Database within the Cosmos DB Account sql_database = documentdb.SqlResourceSqlDatabase(f"sql_database", resource_group_name=resource_group.name, account_name=cosmos_db_account.name, database_name=database_name, options=documentdb.CreateUpdateOptionsArgs( throughput=400, # Adjust the throughput as needed ), ) # Create a Container within the SQL Database sql_container = documentdb.SqlResourceSqlContainer(f"sql_container", resource_group_name=resource_group.name, account_name=cosmos_db_account.name, database_name=sql_database.name, container_name=container_name, resource=documentdb.SqlContainerResourceArgs( id=container_name, # Unique identifier for the container partition_key=documentdb.ContainerPartitionKeyArgs( paths=["/partitionKey"], # Define partition key for improved performance kind="Hash", ), ), options=documentdb.CreateUpdateOptionsArgs( throughput=400, # Adjust the throughput as needed ), ) # Export the Cosmos DB endpoint and primary key so they can be used in your application primary_connection_string = pulumi.Output.all(cosmos_db_account.name, resource_group.name).apply( lambda args: documentdb.list_database_account_connection_strings(resource_group_name=args[1], account_name=args[0])).apply( lambda account: account.connection_strings[0]) pulumi.export('cosmos_db_endpoint', cosmos_db_account.document_endpoint) pulumi.export('primary_connection_string', primary_connection_string)

    In the above program, replace the placeholder values ('myResourceGroup', 'myCosmosDbAccount', 'botDatabase', 'botContainer') with values appropriate for your setup.

    This Pulumi program sets up an Azure Resource Group, a Cosmos DB Account, a SQL Database, and a Container within that database. These are essential components to get started with storing operational data for your bot. The partition_key configuration should be chosen carefully, based on the data access patterns of your bot to ensure efficient querying.

    Once you've deployed this Pulumi code, you can use the exported Cosmos DB endpoint and primary connection string in your bot framework application to interact with your new Cosmos DB operational store. Make sure to handle these sensitive details securely in your application's configuration.