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.
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.
Adjust the days and hours to your team's schedule.
if (isOnline()) {
return { action: 'transfer', reason, transcript: chat.history };
}
return {
action: 'collect_contact',
reason,
reply: 'Our team is offline right now. Leave your email or phone and we will reply by 11 AM tomorrow.',
};
}
Always send the transcript with the transfer so shoppers don't repeat themselves.
Quick tests
javascript
console.log(shouldHandOff({ message: 'My order arrived damaged', failedAnswers: 0, botConfident: true }));
// 'sensitive topic'
console.log(shouldHandOff({ message: 'What is the delivery time?', failedAnswers: 0, botConfident: true }));
// null
Tips
Log every handoff reason and review the top ones weekly.
Don't promise a reply time your team can't keep.
Keep the "talk to a person" option visible, not only automatic.
If the shopper writes in an angry tone, escalate early.