← All projects Personal project · Automation · AI

AI Support Desk for Shopify

Support emails arrive with a reply already drafted.

Personal Project · Automation · n8n · Gemini · 2026

Before

Every support email means opening Shopify, checking the policy and typing a reply.

After

Each email arrives with a reply drafted from the real order, ready for a person to approve.

The Project

Small online stores get the same few emails over and over: where is my order, can I return this, does this come in another size. The answers are already in Shopify. Someone just has to open the order, check the policy and type the reply.

This n8n workflow does that groundwork. It reads each new support email, works out what the customer wants and how upset they are, looks up their real order and products in Shopify, applies the store's rules, and saves a reply as a Gmail draft in the customer's thread. A person reads it and presses send. Tickets that need judgment ping the support lead on Discord, and the owner gets a short report every morning.

The screenshots above come from a test run against a Shopify development store with three test orders, using emails sent from a second Gmail account. Test email addresses are blurred. The canvas views at the end are drawn from the exported workflow file, with the same nodes, positions and connections as in the n8n editor.


Key Features

Replies grounded in real order data

If the email mentions an order number, the workflow fetches that order through the Shopify Admin GraphQL API. If not, it finds the customer's most recent orders by their email address. Gemini only sees what Shopify returns (status, items, totals, tracking numbers), and the prompt forbids inventing refunds, discounts or dates.

Business rules decided in code, not by the model

A switch routes each email by intent, and every branch has its own rules. Order status splits on whether it has shipped. Refunds check the days since the order against the store's return window. Product questions pull live product data. Complaints always go to a human. The AI writes the wording; the workflow decides the outcome.

A quality gate before anything reaches the inbox

A code step checks every draft for empty output, leftover placeholders and excessive length, then decides whether a person must review it: a policy escalation, a very unhappy customer, high urgency, a high-value order, a repeat contact that week, or AI confidence below 0.6 all flag the ticket. Flagged drafts get a "Needs Human" label and a Discord alert with the reasons.

Morning report and failure alerts

At 8:00 the workflow reads the last 24 hours of tickets from Google Sheets, counts them by intent and category, finds the unhappiest customers, asks Gemini for trends, and emails an HTML report to the owner. A separate error workflow posts any failure to Discord with the node that failed and logs it to an Errors sheet.


My Contribution

Solo project. I designed the flow and built both workflows, 54 nodes in total:

  • Email intake that strips quoted history and signatures, extracts order numbers, and skips auto-replies, bounces and newsletters so the desk never replies to a robot.
  • Two Gemini calls with structured JSON output: one to classify intent, sentiment and urgency, one to draft the reply. Both are validated in code with safe fallbacks.
  • Shopify GraphQL queries for orders and products, authenticated with a short-lived token from the client-credentials grant.
  • The intent router and its rule branches, the quality gate, threaded Gmail drafts with labels, and the Sheets ticket log.
  • The daily report, Discord alerts and the error-handling workflow.
  • Setup documentation, test emails and sheet templates so someone else can run it from the exported files.

The Challenge

The Problem

An AI reply that sounds confident but is wrong costs a store more than a slow reply. A model left to itself will happily promise a refund the policy doesn't allow, or guess at a delivery date. And a model's output format isn't guaranteed, so one chatty answer can break everything downstream.

The Decision

I kept the model's job narrow. It classifies and it writes; it doesn't decide. Facts come from Shopify, eligibility comes from IF and code nodes, every AI response is parsed and validated before use, and nothing is sent automatically. Every reply lands as a draft, and anything risky is labelled and escalated.

The Tradeoff

Drafts-only means a person still presses send on every email, so the store saves the lookup and writing time but not the review. I chose that on purpose: it's the safe default until the drafts have a track record. Separately, the first version sent alerts through Telegram, but the Telegram API was unreachable from my network, so I moved alerts to Discord webhooks. That also removed a bot token from the setup.

The Result

I ran it end to end on a Shopify development store with six test emails, one per scenario. Each one landed where the rules said it should. The shipping question got a draft with the real DHL tracking link. The sizing question was answered from the product description. The angry complaint and the $180 return were labelled Needs Human and posted to Discord. The out-of-office auto-reply was skipped. The morning report counted 5 emails handled and 3 flagged.

The test runs also turned up four bugs, and I fixed each one in the workflow. Product search returned nothing for plurals ("linen shirts" didn't match "Linen Shirt"), so keywords are now stemmed into prefix searches. A product without a store URL put the word "null" in a reply, so empty links are dropped and the quality check now catches "null". Gemini added its own sign-off on top of the store signature. And the repeat-contact rule flagged any second email from the same customer, so now it only counts a ticket about the same order or the same conversation.


Technical Details

n8n runs self-hosted in Docker. Gmail is polled every minute for unread mail, and a loop processes one email at a time so a single bad message can't take down the batch. Everything store-specific (shop domain, return window, high-value threshold, policy text, signature, label IDs) lives in one config node.

Shopify calls go to the Admin GraphQL API. Each run starts by exchanging the app's client ID and secret for a fresh access token, so the access token itself only lives for the length of the run. Gemini is called over plain HTTP with an API key header and asked for JSON; the validator strips code fences, rejects unknown intents, clamps sentiment to −1…1 and falls back to "other" and "medium" if parsing fails.

Every ticket is appended to Google Sheets with its intent, sentiment, urgency, order, AI confidence and review reasons. The same sheet supplies each customer's history for repeat-contact detection and feeds the morning report.

n8n Google Gemini API Shopify GraphQL Gmail API Google Sheets Discord Webhooks JavaScript Docker

What I'd change today

I'd move the Shopify client secret out of the config node into an n8n credential. Keeping all settings in one node makes setup easy, but it means the secret travels with every workflow export.

I'd also replace Gmail polling with a push trigger through Gmail's watch API and Pub/Sub. Polling every minute is simple and reliable, but it adds up to a minute of delay and burns API calls when the inbox is quiet.