šŸ›’šŸ’¬ Shia E-Commerce Chatbot

šŸ¤– Transforming E-commerce with Intelligent Conversation šŸ›ļø

Powered by Google Cloud & Dialogflow CX

šŸ“‹ Project Overview

Shia is an advanced e-commerce chatbot built with Dialogflow CX, powered by Google Cloud Functions, and utilizing BigQuery for data storage and analytics. This conversational agent provides customers with a seamless shopping experience through natural language interactions.

šŸ’” Core Purpose: To enhance customer experience by providing a conversational interface for e-commerce operations including product browsing, order tracking, account management, and customer support.

✨ Key Features - šŸ” **Intelligent Product Search** - Natural language product discovery - šŸ“¦ **Order Tracking** - Real-time updates on customer orders - šŸ› ļø **Customer Support** - Automated issue resolution and complaint handling - šŸ‘¤ **Account Management** - User profile viewing and editing - šŸ·ļø **Personalized Offers** - Custom promotions based on user preferences - šŸ“Š **Analytics Dashboard** - Comprehensive conversation insights

šŸ—ļø Architecture

High-Level Components

graph TD
    A[Dialogflow CX Agent] <--> B[Cloud Functions]
    B <--> C[BigQuery Database]
    A <--> D[User Interface]
    C <--> E[Analytics Dashboard]

    style A fill:#f9f,stroke:#333,stroke-width:2px
    style B fill:#bbf,stroke:#333,stroke-width:2px
    style C fill:#bfb,stroke:#333,stroke-width:2px
    style D fill:#fbb,stroke:#333,stroke-width:2px
    style E fill:#fbf,stroke:#333,stroke-width:2px

šŸ”„ Flow Structure

The chatbot is organized around a hub-and-spoke model with the following main flows:

Flow Name Icon Description Primary Functions
Start Page 🚪 Entry point and routing hub Welcome, intent detection
MAIN_MENU 🧭 Primary navigation Options presentation, routing
ORDER_STATUS šŸ“¦ Order tracking Order lookup, status updates
BROWSE_PRODUCTS šŸ” Product discovery Catalog search, filtering, recommendations
COMPLAINT āš ļø Issue resolution Complaint logging, escalation
MY_ACCOUNT šŸ‘¤ User profile management Profile viewing/editing, preferences
OFFER šŸ·ļø Promotions and deals Personalized offers, discount codes

šŸ”§ Technical Components

1. 🧠 Dialogflow CX

Shia leverages Dialogflow CX's advanced conversation management capabilities:

šŸ”„ State-based conversation management

Complex, multi-turn conversations

šŸ·ļø Advanced entity handling

Product catalogs, user profiles, order details

šŸ“Š Flow-based design

Independent conversation modules with clear transitions

šŸ’¬ Rich response types

Text, cards, carousels, quick replies

Agent Structure

shia-ecommerce-agent/
ā”œā”€ā”€ šŸ“ flows/
│   ā”œā”€ā”€ 🚪 start.flow
│   ā”œā”€ā”€ 🧭 main_menu.flow
│   ā”œā”€ā”€ šŸ“¦ order_status.flow
│   ā”œā”€ā”€ šŸ” browse_products.flow
│   ā”œā”€ā”€ āš ļø complaint.flow
│   ā”œā”€ā”€ šŸ‘¤ my_account.flow
│   └── šŸ·ļø offer.flow
ā”œā”€ā”€ šŸ“ intents/
│   ā”œā”€ā”€ navigation_intents.json
│   ā”œā”€ā”€ product_intents.json
│   ā”œā”€ā”€ order_intents.json
│   └── ...
ā”œā”€ā”€ šŸ“ entities/
│   ā”œā”€ā”€ product_type.json
│   ā”œā”€ā”€ order_status.json
│   └── ...
└── šŸ“ webhooks/
    ā”œā”€ā”€ product_lookup.json
    ā”œā”€ā”€ order_fetch.json
    └── ...

2. ⚔ Cloud Functions

Cloud Functions serve as the backend processing layer, handling:

  • šŸ”Œ Webhook fulfillment: Dynamic responses based on database queries
  • šŸ”— API integration: Connections to inventory, order management, and payment systems
  • šŸ”„ Data processing: Formatting and transforming data for both BigQuery and Dialogflow
  • šŸ”’ Authentication: Secure user verification and session management

Key Functions

šŸ“‹ View Example Code ```javascript // Example of a product search function exports.productSearch = (req, res) => { const parameters = req.body.queryResult.parameters; const productType = parameters.product_type; const priceRange = parameters.price_range; // Query products from database return queryProducts(productType, priceRange) .then(products => { // Format response for Dialogflow res.json({ fulfillmentMessages: formatProductResults(products) }); }) .catch(err => { console.error('Error querying products:', err); res.status(500).send('Internal Server Error'); }); }; ```

3. šŸ’¾ BigQuery Database

BigQuery provides a scalable data storage solution with powerful analytics capabilities:

  • šŸ“ Schema Design: Optimized for e-commerce data and conversation history
  • ⚔ Real-time Analytics: Monitoring conversation performance and user behavior
  • šŸ”„ Data Integration: Connected to product catalog, order system, and user profiles
  • šŸ“ Conversation Logging: Complete history for improvement and personalization

Core Tables

Table Name Icon Purpose Key Fields
products šŸ›ļø Product catalog product_id, name, price, category, inventory
orders šŸ“¦ Order tracking order_id, user_id, status, items, total
users šŸ‘¤ Customer profiles user_id, name, preferences, history
conversations šŸ’¬ Chat history session_id, timestamp, input, response, intent
complaints āš ļø Issue tracking complaint_id, user_id, type, status, resolution

šŸš€ Setup & Installation

Prerequisites

🌐 Google Cloud Platform account with billing enabled
šŸ¤– Dialogflow CX API access for agent creation and management
šŸ“¦ Node.js v14+ and npm for Cloud Functions
āŒØļø gcloud CLI for deployment and configuration

Installation Steps

šŸ”§ Step 1: GCP Project Setup ```bash # Create a new GCP project gcloud projects create shia-ecommerce-chatbot --name="Shia E-commerce Chatbot" # Set the project as current gcloud config set project shia-ecommerce-chatbot # Enable required APIs gcloud services enable dialogflow.googleapis.com gcloud services enable cloudfunctions.googleapis.com gcloud services enable bigquery.googleapis.com ``` šŸ’¾ Step 2: BigQuery Setup ```bash # Create dataset bq mk --dataset ecommerce_data # Create tables from schema files bq mk --table ecommerce_data.products schema/products_schema.json bq mk --table ecommerce_data.orders schema/orders_schema.json bq mk --table ecommerce_data.users schema/users_schema.json bq mk --table ecommerce_data.conversations schema/conversations_schema.json ``` ⚔ Step 3: Cloud Functions Deployment ```bash # Navigate to functions directory cd cloud_functions # Install dependencies npm install # Deploy product search function gcloud functions deploy productSearch \ --runtime nodejs14 \ --trigger-http \ --allow-unauthenticated # Deploy other functions similarly gcloud functions deploy orderStatus \ --runtime nodejs14 \ --trigger-http \ --allow-unauthenticated ``` šŸ¤– Step 4: Dialogflow CX Setup 1. Create a new agent in Dialogflow CX console 2. Import the provided agent zip file from `dialogflow/shia-agent.zip` 3. Configure webhook URLs to point to your deployed Cloud Functions 4. Test the agent in the Dialogflow simulator

šŸ“ Implementation Details

Conversation Flows

🚪 Start Page

The entry point for all conversations, responsible for:

  • šŸ‘‹ Welcoming users
  • 🧠 Collecting basic context
  • 🚦 Routing to appropriate specialized flows

🧭 Main Menu Flow

flowchart TD
    A[Welcome Page] --> B{Intent Recognition}
    B -->|browse_products| C[BROWSE_PRODUCTS]
    B -->|check_order| D[ORDER_STATUS]
    B -->|file_complaint| E[COMPLAINT]
    B -->|view_account| F[MY_ACCOUNT]
    B -->|check_offers| G[OFFER]
    B -->|fallback| H[Fallback Response]

šŸ“¦ Order Status Flow

Step Process Details
Order Identification • By Order Number
• By Recent Orders
"What's your order number?"
"Here are your recent orders..."
Status Retrieval Webhook: orderStatusLookup Cloud Function processes the request
Status Communication • Status update
• Delivery ETA
• Tracking information
"Your order #12345 is currently being shipped."

Database Schema Details

šŸ“‹ Products Table Schema ```json [ {"name": "product_id", "type": "STRING", "mode": "REQUIRED"}, {"name": "name", "type": "STRING", "mode": "REQUIRED"}, {"name": "description", "type": "STRING", "mode": "NULLABLE"}, {"name": "price", "type": "FLOAT", "mode": "REQUIRED"}, {"name": "category", "type": "STRING", "mode": "REQUIRED"}, {"name": "subcategory", "type": "STRING", "mode": "NULLABLE"}, {"name": "inventory_count", "type": "INTEGER", "mode": "REQUIRED"}, {"name": "image_url", "type": "STRING", "mode": "NULLABLE"}, {"name": "last_updated", "type": "TIMESTAMP", "mode": "REQUIRED"} ] ```

šŸ”Œ Integration Guide

Webhook Configuration

Connect your Dialogflow CX agent to Cloud Functions by configuring webhooks:

1

In Dialogflow CX console, navigate to Manage tab

2

Select Webhooks

3

Create a new webhook for each function:

URL: https://[REGION]-[PROJECT_ID].cloudfunctions.net/[FUNCTION_NAME]
Method: POST
Request Format: Dialogflow CX Webhook Request

Testing Locally

For local development and testing:

# Install the Dialogflow CX CLI
npm install -g @google-cloud/dialogflow-cx

# Run local webhook server
npm run dev-server

# Test with simulated requests
dialogflow-cx simulate --project-id=shia-ecommerce-chatbot

šŸ“Š Performance Monitoring

Key Metrics

Monitor these essential metrics:

Metric Description Target
šŸŽÆ Conversation Completion Rate % of conversations reaching successful resolution >85%
🧠 Intent Recognition Accuracy % of correctly identified user intents >90%
āš ļø Fallback Rate % of queries resulting in fallback responses <15%
šŸ“ Average Conversation Length Number of turns to complete common tasks <5 turns
😊 User Satisfaction Post-conversation ratings >4.2/5

Monitoring Dashboard

graph LR
    A[Conversation Data] --> B[BigQuery]
    B --> C[Data Studio]
    C --> D[Monitoring Dashboard]
    D --> E[Performance KPIs]
    D --> F[User Satisfaction]
    D --> G[Technical Metrics]

Example Monitoring Query

šŸ“‹ Daily Fallback Rate Query ```sql -- Example BigQuery 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; ```

🌐 Deployment

Production Deployment Checklist

Ensure all entity types are thoroughly tested Verify all webhook connections are operational Test full conversation flows from start to completion Configure proper IAM permissions Set up monitoring alerts Establish CI/CD pipeline for agent updates

Integration Options

Platform Icon Integration Method Documentation
Website 🌐 Dialogflow Messenger Documentation
Mobile App šŸ“± Dialogflow API Documentation
Facebook Messenger šŸ’¬ Built-in Integration Documentation
Google Assistant šŸ”Š Built-in Integration Documentation

šŸ” Troubleshooting Guide

Common Issues

Issue Icon Possible Causes Solutions
Intent recognition failures 🧠 Insufficient training phrases Add more varied examples to training phrases
Webhook timeouts ā±ļø Function execution taking too long Optimize database queries, add caching
Entity extraction issues šŸ·ļø Entity definitions too narrow Broaden entity definitions, add synonyms
Conversation loops šŸ”„ Missing exit conditions in flows Add clear exit paths, improve error handling

Debugging Tips

šŸ“‹ View Cloud Function Logs ```bash # View Cloud Function logs gcloud functions logs read productSearch --limit=50 ``` šŸ”Œ Test Webhook Directly ```bash # Test webhook directly curl -X POST \ -H "Content-Type: application/json" \ -d @test-payloads/product-search.json \ https://[REGION]-[PROJECT_ID].cloudfunctions.net/productSearch ```

šŸ”® Future Enhancements

šŸŒ

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


šŸ‘„ Contributing

Contributions are welcome! Please follow these steps:

gitGraph:
    commit id: "Initial Setup"
    branch feature
    checkout feature
    commit id: "New Feature"
    commit id: "Testing"
    checkout main
    merge feature
    commit id: "Release"
  1. Fork the repository
  2. Create a feature branch (git checkout -b feature/amazing-feature)
  3. Commit your changes (git commit -m 'Add some amazing feature')
  4. Push to the branch (git push origin feature/amazing-feature)
  5. Open a Pull Request

See CONTRIBUTING.md for detailed guidelines.


šŸ“„ License

This project is licensed under the MIT License - see the LICENSE file for details.


šŸ™ Acknowledgements

ā˜ļø Google Cloud team for Dialogflow CX and BigQuery 🌐 The open-source community for various tools and libraries šŸ‘„ All contributors and testers who helped shape this project

Made with ā¤ļø by the Shia Team

GitHub • Documentation • Contact

Built With

Share this project:

Updates