E-commerce Bot | Part 5 | Working with Azure Cosmos DB Local Emulator to INSERT Product Details

In this bot series, we will create an E-commerce bot for one of the Online Chocolate Store “Naami Chocos“. This bot will have the following functionalities –

  1. Authentication
  2. Add to Cart
  3. Payment Integration
  4. FAQs using QnA Maker
  5. Connect the bot to the Facebook page

The Azure Cosmos DB Emulator provides a local environment that emulates the Azure Cosmos DB service for development purposes. Using the Azure Cosmos DB Emulator, you can develop and test your application locally, without creating an Azure subscription or incurring any costs.

For more information, refer to the Microsoft Documentation.

In this part, we will see the Cosmos DB Emulator functionality and manually add few products to the DB. So that we can READ these products later in our bot development.

Prerequisites

  1. Azure Cosmos DB Local Emulator

Video

Create Database

After installing, open the emulator. It usually runs on localhost:8081. Below is the landing page you get with URI, primary key, and connection strings.

You can learn by choosing a platform and downloading a sample code. We will use the same sample code for .NET Core in our implementation.

You can create the DB using the code, but in this case we will use the UI. Go to the Explorer and click on new database.

Give a name of the DB and click OK. I have given the name as NaamiChocosProductDB.

Create Container

Now, we create a container inside the DB. Click on New Container.

Give a name of the container id and a partition key.

With this, a container gets created. We are now ready to start adding items into the container.

Add Item

Let us now add new items into the container. Click on New Item and add item using the JSON.

{
    "id":"Choc1019",
    "ProductName":"Special Anniversary Bar",
    "price":500,
    "image":"https://res.cloudinary.com/dewiride/image/upload/v1615557203/Naami%20Chocos/IMG-20210217-WA0003_buaa59.jpg"
}

Our product will have following properties –

  1. Unique ID
  2. Product Name
  3. Price
  4. Image URL

You can also add ratings as well. But for now, I will use these properties only. When you click on save, a new item is added.


Query

We can query the container to get all the items or specific items (using filter) from the container. Click on New Query.

Execute the query already present. This gets all the items.

We can create a new chatbot for the admin to add all the products to the database. For more information, refer to my post here.

Thank you All!!! Hope you find this useful.


Up ↑

%d bloggers like this: