A production-ready Shopify app that provides AI-powered customer support using ChatGPT (OpenAI). Features embedded admin UI, theme app extension, billing, and GDPR compliance.
- AI-Powered Support: Uses GPT-4 Turbo for intelligent, context-aware responses
- Theme App Extension: Native Shopify theme integration (no script tags)
- Embedded Admin UI: Built with Polaris and App Bridge
- Billing Integration: GraphQL billing with trials and subscriptions
- GDPR Compliant: Full data management and deletion capabilities
- Production Ready: Security, monitoring, and error handling
- Node.js 18+
- PostgreSQL database
- Shopify Partner account
- OpenAI API key
- Railway account (for hosting)
git clone https://github.com/Parsarf/AI-costumer-service.git
cd AI-costumer-service/backend
npm installCreate .env file:
cp env.example .envUpdate .env with your credentials:
# App Configuration
APP_URL=https://your-app.railway.app
NODE_ENV=development
PORT=3001
# Shopify App Credentials
SHOPIFY_API_KEY=your_api_key_here
SHOPIFY_API_SECRET=your_api_secret_here
SCOPES=read_products,read_orders,read_customers,write_themes
# Database
DATABASE_URL=postgresql://user:pass@localhost:5432/shopify_support_bot
# AI Service
OPENAI_API_KEY=sk-proj-...
# Security
JWT_SECRET=your_jwt_secret_change_in_production
ENCRYPTION_KEY=your_32_character_encryption_key
# Billing Configuration
BILLING_PRICE=9.99
BILLING_TRIAL_DAYS=7
SHOPIFY_BILLING_TEST=true
FREE_PLAN=false# Create database
createdb shopify_support_bot
# Run migrations
npm run prisma:migrate
# Generate Prisma client
npm run prisma:generatenpm run dev- Go to Shopify Partners Dashboard
- Create new app
- Set URLs:
- App URL:
https://your-ngrok-url.ngrok.io - Allowed redirection URL:
https://your-ngrok-url.ngrok.io/auth/callback
- App URL:
- Add webhook subscriptions:
app/uninstalled→https://your-ngrok-url.ngrok.io/webhooks/app_uninstalledcustomers/data_request→https://your-ngrok-url.ngrok.io/webhooks/customers/data_requestcustomers/redact→https://your-ngrok-url.ngrok.io/webhooks/customers/redactshop/redact→https://your-ngrok-url.ngrok.io/webhooks/shop/redact
Visit: https://your-ngrok-url.ngrok.io/auth?shop=your-dev-store.myshopify.com
-
Install Railway CLI:
npm install -g @railway/cli
-
Login and Initialize:
railway login cd backend railway init -
Add PostgreSQL:
railway add postgresql
-
Set Environment Variables:
railway variables set SHOPIFY_API_KEY=your_key railway variables set SHOPIFY_API_SECRET=your_secret railway variables set OPENAI_API_KEY=your_openai_key railway variables set JWT_SECRET=your_jwt_secret railway variables set ENCRYPTION_KEY=your_encryption_key
-
Deploy:
railway up
-
Run Migrations:
railway run npx prisma migrate deploy
-
Get Your URL:
railway domain
Update your app URLs in Shopify Partners Dashboard:
- App URL:
https://your-app.railway.app - Redirect URL:
https://your-app.railway.app/auth/callback
# Install Shopify CLI
npm install -g @shopify/cli
# Login to Shopify
shopify auth login
# Deploy extension
cd extensions/assistant-widget
shopify app generate extension
shopify app deploy- Go to Online Store → Themes
- Click Customize on your active theme
- Go to App embeds
- Enable AI Support Assistant
- Configure colors and position
- Save
The app uses Shopify's GraphQL Billing API:
- Trial Period: 7 days (configurable)
- Price: $9.99/month (configurable)
- Test Mode: Enabled in development
POST /billing/ensure- Create subscriptionGET /billing/status- Check billing status
- HMAC Verification: All webhooks verified
- Rate Limiting: 100 requests per 15 minutes
- CORS Protection: Only allows Shopify domains
- Input Validation: All inputs sanitized
- Error Handling: Comprehensive error management
GET /auth- Initiate OAuthGET /auth/callback- OAuth callback
GET /app- Embedded admin interface
POST /api/chat- Send message (embedded app)POST /aibot/chat- Send message (storefront via app proxy)
POST /billing/ensure- Create subscriptionGET /billing/status- Get billing status
POST /webhooks/app_uninstalled- App uninstalledPOST /webhooks/customers/data_request- GDPR data requestPOST /webhooks/customers/redact- GDPR customer redactPOST /webhooks/shop/redact- GDPR shop redact
GET /health- Health checkGET /ready- Readiness check
npm test# Test app uninstalled
curl -X POST http://localhost:3001/webhooks/app_uninstalled \
-H "Content-Type: application/json" \
-H "X-Shopify-Hmac-Sha256: test_signature" \
-d '{}'
# Test customer data request
curl -X POST http://localhost:3001/webhooks/customers/data_request \
-H "Content-Type: application/json" \
-H "X-Shopify-Hmac-Sha256: test_signature" \
-d '{"customer": {"email": "test@example.com"}}'The theme app extension is fully responsive and works on:
- Desktop browsers
- Mobile Safari (iOS)
- Mobile Chrome (Android)
- Tablet devices
Configure via the embedded admin app:
{
"welcomeMessage": "Hi! How can I help you today?",
"returnPolicy": "30 day returns...",
"shippingPolicy": "Ships in 1-2 days...",
"supportEmail": "support@store.com",
"botPersonality": "friendly", // friendly, professional, efficient
"theme": {
"primaryColor": "#4F46E5",
"position": "bottom-right"
}
}OAuth fails:
- Check APP_URL matches Shopify settings exactly
- Verify API keys are correct
- Ensure redirect URL is whitelisted
Widget not loading:
- Verify theme app extension is deployed
- Check app proxy configuration
- Ensure billing is active
Database errors:
- Run
npm run prisma:migrate - Check DATABASE_URL is correct
- Verify PostgreSQL is running
OpenAI API errors:
- Verify OPENAI_API_KEY is correct
- Check API usage limits
- Ensure billing is active
Set NODE_ENV=development for detailed logging.
- Health:
GET /health- Basic health check - Ready:
GET /ready- Database connectivity check
Uses Winston for structured logging:
- Error logs:
logs/error.log - Combined logs:
logs/combined.log - Console output in development
- Fork the repository
- Create feature branch:
git checkout -b feature/amazing-feature - Commit changes:
git commit -m 'Add amazing feature' - Push to branch:
git push origin feature/amazing-feature - Open Pull Request
This project is licensed under the MIT License - see the LICENSE file for details.
- Documentation: See
/docsdirectory - Issues: GitHub Issues
- Email: support@yourdomain.com
- Multi-language support
- Advanced analytics dashboard
- Custom AI training
- Integration with other support tools
- Voice support
- Proactive messaging
Built with ❤️ for the Shopify merchant community