Make a Shopify Chatbot Customizable with One Config Object
A customizable chatbot shouldn't need code changes every time the store owner wants a new greeting or a different page trigger. Put every option in one config object and let the widget read it.
- The config javascript const botConfig = { name: 'Shop Helper', color: '#0f766e', position: 'right', tone: 'friendly', languages: ['en', 'hi', 'gu'], greeting: { en: 'Questions about delivery or offers? Ask here.', hi: 'डिलीवरी या ऑफर के बारे में पूछें।', gu: 'ડિલિવરી કે ઓફર વિશે પૂછો.', }, showOn: ['/cart', '/products/'], hideOn: ['/checkout'], delaySeconds: 8, handoff: { afterFailedReplies: 2, offlineMessage: 'We will reply by 11 AM tomorrow.' }, };
Store owners edit this object, or a settings page writes it for them. The widget code stays the same.
- Decide where to show it javascript function shouldShow(path, cfg) { if (cfg.hideOn.some(p => path.startsWith(p))) return false; return cfg.showOn.some(p => path.startsWith(p)); }
- Pick the greeting language javascript function getGreeting(cfg) { const lang = (document.documentElement.lang || 'en').slice(0, 2); return cfg.greeting[lang] || cfg.greeting.en; }
Falling back to English means a missing translation never breaks the widget.
- Start the widget javascript function initBot(cfg) { if (!shouldShow(location.pathname, cfg)) return; setTimeout(() => renderWidget({ title: cfg.name, color: cfg.color, position: cfg.position, message: getGreeting(cfg), }), cfg.delaySeconds * 1000); }
initBot(botConfig);
renderWidget is your own function that draws the chat button.
Tips
Validate the config and fall back to safe defaults for missing fields.
Keep content, such as policies and FAQs, separate from display settings.
Test every language and page rule on a phone.
Never hide the human handoff behind a config flag.
Wrap-up
Customization is easiest when behavior lives in data, not code. Start with a small config like this, then add options only when real chats show you need them.
Top comments (0)