Tags: ai-customer-support email-automation textile-manufacturing python gmail-api gemini-ai sqlite order-processing conversation-tracking workflow-automation
An intelligent email customer support assistant that automatically processes order inquiries, extracts order details using Gemini AI, stores data in SQLite database, and sends appropriate responses[...]
- Gmail Integration: Automatically monitors and responds to customer emails
- AI-Powered Processing: Uses Google Gemini AI to extract order information from emails
- Database Storage: Stores order data in SQLite database with conversation history
- Automated Responses: Generates professional responses based on order completeness
- Order Tracking: Tracks order status and missing information
- Conversation Threading: Maintains email thread context for ongoing conversations
- Python 3.11 or higher
- pip (Python package installer)
- Google Cloud account with Gmail API and Gemini AI access
- Modern web browser (Chrome, Firefox, Safari, Edge)
- workflow-manager project set up (see Textile Supply Chain Workflow Manager)
# If using git
git clone https://github.com/Petrinax/customer_support.git
cd customer_support
# Or download and extract the project files# Create virtual environment
python3 -m venv python-venv
# Activate virtual environment
# On macOS/Linux:
source python-venv/bin/activate
# On Windows:
python-venv\Scripts\activate# Install Python dependencies
pip install -r requirements.txt
# Create environment file
cp .env.example .envFollow the steps in Gmail API Setup to create OAuth 2.0 credentials and download credentials.json.
-
Get your API key from Google AI Studio
-
GEMINI_API_KEY=your_gemini_api_key_here
As a part of the workflow-manager project setup, the SQLite database should already be present at:
<workflow_manager_base_path>/instance/supply_chain.db
If not, set up the project first.
Add the database path to your .env file:
DATABASE_PATH=path_to_supply_chain_db
# Complete setup
python manage.py setup
# Start the assistant
python manage.py start# Install dependencies only
python manage.py install
# Check database status
python manage.py check-db
# View specific order details
python manage.py view-order --order-id 1
# Gmail setup instructions
python manage.py gmail-setupYour AI Assistant will start monitoring emails and processing orders.
First time you run it, a browser window will open asking you to log in to your Google account. Follow the prompts to complete the authorization.
As the app is currently under testing mode, only authorized Gmail accounts can be used to attach this assistant.
To add yourself as an authorized user, add your email to the Test users list in Google Cloud Console:
APIs & Services -> OAuth Consent Screen -> Audiance.
(For Development Phase)
To prevent processing unwanted emails, add authorized sender email addresses to the ALLOWED_SENDERS list in .env.
Send order inquiry emails: From: Sender Account To: Assistant Account.
The assistant will automatically process and respond. Once the assistant has all the required information after a couple of QnA replies, it will:
- Send a confirmation email.
- Add Order details to Workflow Manager database & Dashboard.
Watch Demonstration for detailed flow.
- Email Monitoring: Continuously monitors Gmail for unread emails
- Content Extraction: Extracts email content and conversation history
- AI Processing: Uses Gemini LLMs to analyze and extract order information
- Database Storage: Saves order data with status ("Missing Info" or "Complete")
- Response Generation: Creates appropriate email responses
- Thread Management: Maintains conversation context across email exchanges
When critical order details are missing, the system sends a clarification email requesting specific information.
When all required information is provided, the system sends a confirmation email with order summary and next steps.
id: Primary keycustomer_name: Customer namecustomer_email: Customer email addressorder_data: JSON string with complete order detailsstatus: Order status ("Missing Info" or "Complete")created_at: Record creation timestampupdated_at: Last update timestampemail_thread_id: Gmail thread ID for conversation trackingconversation_history: Complete email conversation history
The system logs all activities to:
- Console output
email_assistant.logfile
Log levels: INFO, WARNING, ERROR
- Gmail API errors: Logged and handled gracefully
- Gemini AI failures: Fallback response generation
- Database errors: Comprehensive error logging
- Network issues: Automatic retry mechanisms
- OAuth 2.0 authentication for Gmail access
- API keys stored in environment variables
- Local database storage
- Email content processed securely
-
Gmail authentication fails
- Ensure credentials file is properly named and placed
- Check OAuth 2.0 client configuration
- Verify Gmail API is enabled
-
Gemini AI errors
- Verify API key is correct and active
- Check API quotas and limits
- Ensure proper internet connectivity
-
Database connection issues
- Check file permissions for database directory
- Verify SQLite is properly installed
customer_support/
├── app.py # Main application
├── config.py # Configuration settings
├── manage.py # Management utility
├── secrets/ # Secrets directory
│ └── credentials.json # Gmail OAuth client secret
│ └── token.json # Gmail OAuth token (auto-generated)
├── requirements.txt # Python dependencies
└── .env # Environment variables
Contributions are welcome! Please feel free to submit a Pull Request. For major changes, please open an issue first to discuss what you would like to change.
This project is licensed under the MIT License - see the LICENSE file for details.
- Textile Supply Chain Workflow Manager - Complete workflow management system for textile manufacturing
