Yash kavaiya

May 19, 2025 • 4 min read

Building a Smart E-Commerce Chatbot with Dialogflow CX and Google Cloud

Building a Smart E-Commerce Chatbot with Dialogflow CX and Google Cloud

Building a Smart E-Commerce Chatbot with Dialogflow CX and Google Cloud

E-commerce businesses are constantly looking for ways to improve customer experience and streamline operations. In this article, I'll walk you through building "Shia" - an advanced e-commerce chatbot powered by Google Cloud technologies that provides customers with natural language interactions for shopping, order tracking, and support.

The Problem

Online retailers face several challenges when scaling customer service:

  • Handling repetitive customer inquiries (order status, product questions, etc.)

  • Providing 24/7 support without massive staffing costs

  • Delivering personalized experiences at scale

  • Managing consistent communication across multiple channels

Enter Shia: A Conversational Agent for E-Commerce

Shia is a state-of-the-art e-commerce chatbot built with Dialogflow CX and backed by Google Cloud infrastructure. It provides a seamless shopping experience through natural language interactions, handling everything from product browsing to order tracking and customer support.

Core Capabilities

  • 🔍 Product Discovery: Catalog search with filtering and recommendations

  • 📦 Order Management: Tracking and status updates

  • 👤 Account Management: Profile handling and preferences

  • ⚠️ Issue Resolution: Complaint logging and escalation

  • 🎁 Personalized Offers: Custom promotions and discount codes

Architecture: How It All Works

Shia follows a hub-and-spoke architecture with three main components:

  1. Dialogflow CX - The conversational brain

  2. Cloud Functions/Cloud Run - The backend processing layer

  3. BigQuery - The data storage and analytics engine

Let's break down each component:

Dialogflow CX: Advanced Conversation Design

Dialogflow CX provides state-based conversation management, allowing Shia to handle complex multi-turn dialogues. The agent is structured around flows:

- 🏠 Start Page (Entry and routing)
- 📂 MAIN_MENU (Navigation hub)
- 📦 ORDER_STATUS (Order tracking)
- 🔍 BROWSE_PRODUCTS (Discovery)
- ⚠️ COMPLAINT (Issue resolution)
- 👤 MY_ACCOUNT (Profile management)
- 🎁 OFFER (Promotions)

This modular design makes the conversation logic easy to maintain and extend.

Cloud Functions: Serverless Backend

The webhook fulfillment code handles:

  1. Database queries to BigQuery

  2. Integration with order/inventory systems

  3. Dynamic response generation

For example, here's how the order status webhook works:

def get_order_details(request_json):
    # Extract order_id from the request
    order_id = request_json["sessionInfo"]["parameters"]["order_id"]
    
    # Query BigQuery for order details
    client = bigquery.Client()
    query = f"""
        SELECT order_id, customer_id, order_date, status, 
               tracking_number, shipping_address
        FROM `project.dataset.orders`
        WHERE order_id = '{order_id}'
    """
    
    # Format and return response to Dialogflow
    # ...

This serverless approach provides scalability without infrastructure management.

BigQuery: Scalable Data Storage

BigQuery stores all the necessary data for the chatbot:

  • Product catalog

  • Order information

  • Customer profiles

  • Conversation history

  • Analytics

This enables powerful features like personalized recommendations and conversation analytics.

Implementation Highlights

Conversation Flow Design

The main menu flow demonstrates how Shia routes user requests:


Dynamic Offer Generation

One interesting feature is the personalized offer generator:

def generate_offer(request_json):
    # User provides a number between 1-9
    user_number = int(request_json["sessionInfo"]["parameters"]["user_number"]["original"])
    
    # Generate a personalized offer based on the number
    offers = {
        1: "Get 10% off your next purchase! Use code TRR10 at checkout.",
        2: "Free shipping on orders over $50! Use code FREESHIP50 at checkout.",
        # ...more offers
    }
    
    return offers[user_number]

This simple mechanism creates an engaging experience that encourages repeat usage.

Monitoring and Analytics

To ensure Shia performs well, I've implemented monitoring for key metrics:

  • 🎯 Conversation Completion Rate (target: >85%)

  • 🧠 Intent Recognition Accuracy (target: >90%)

  • ⚠️ Fallback Rate (target: <15%)

  • 🔄 Average Conversation Length (target: <8 turns)

  • 😊 User Satisfaction (target: >4.2/5)

BigQuery enables powerful analytics through SQL queries like:

-- Example monitoring query for daily fallback rate
SELECT
  DATE(timestamp) as date,
  COUNT(CASE WHEN intent = 'Default Fallback Intent' THEN 1 END) / COUNT(*) * 100 as fallback_rate
FROM
  ecommerce_data.conversations
GROUP BY
  date
ORDER BY
  date DESC
LIMIT 14;

Setting Up Your Own E-Commerce Chatbot

If you want to build a similar system, here's a simplified setup process:

  1. Create a GCP project and enable APIs

    gcloud projects create your-project-id
    gcloud services enable dialogflow.googleapis.com cloudfunctions.googleapis.com bigquery.googleapis.com
    
  2. Set up BigQuery tables for products, orders, users, and conversations

  3. Deploy the webhook code to Cloud Functions or Cloud Run

    gcloud functions deploy orderStatus --runtime python39 --trigger-http
    
  4. Create and configure your Dialogflow CX agent

    • Design conversation flows

    • Define intents and entities

    • Connect webhooks

  5. Integrate with your website, mobile app, or messaging platforms

Future Enhancements

The beauty of this architecture is how easily it can be extended. Future plans include:

  • 🌐 Multi-language Support - Expanding to additional languages

  • 🔊 Voice Interface - Adding telephony integration

  • 🎯 Personalization Engine - Improved product recommendations

  • 💳 Payment Processing - Direct checkout capabilities

  • 😊 Sentiment Analysis - Real-time customer satisfaction monitoring

Conclusion

Building an e-commerce chatbot with Dialogflow CX and Google Cloud provides an exceptional customer experience while reducing operational costs. The serverless architecture ensures scalability, while the conversational design creates human-like interactions.

The modular approach makes it adaptable to various business needs, from small online stores to enterprise retailers. As AI and NLP technology continues to advance, conversational commerce will only become more important in the e-commerce landscape.

Have you implemented conversational AI in your business? I'd love to hear about your experiences in the comments!


This article is based on the Shia E-Commerce Chatbot project. The full implementation details, including code and setup instructions, are available on GitHub.

Join Yash on Peerlist!

Join amazing folks like Yash and thousands of other people in tech.

Create Profile

Join with Yash’s personal invite link.

0

6

1