When Should Your Shopify Chat Bot Hand Off to a Human? A Small Rules Engine
A live chat AI app is only as good as its handoff. Here's a small, testable function that decides when to pass a chat to your team, and what to do if nobody is online.
Define the rules javascript const ESCALATE_WORDS = /refund|damaged|broken|wrong item|not received|complaint|cancel/i; const ASKS_HUMAN = /human|agent|person|talk to (someone|team)/i;
function shouldHandOff({ message, failedAnswers, botConfident }) {
if (ASKS_HUMAN.test(message)) return 'customer asked';
if (ESCALATE_WORDS.test(message)) return 'sensitive topic';
if (failedAnswers >= 2) return 'bot failed twice';
if (!botConfident) return 'low confidence';
return null;
}
Returning a reason instead of true means you can log why each chat escalated.
Check business hours javascript function isOnline(now = new Date()) { const ist = new Date(now.toLocaleString('en-US', { timeZone: 'Asia/Kolkata' })); const day = ist.getDay(); // 0 = Sunday const hour =…