Menu

Add an AI Cart Assistant to Shopify That Only Answers From Your Policies
📰

Add an AI Cart Assistant to Shopify That Only Answers From Your Policies

DEV Community: javascript·Aylelite·4 days ago
#eE83cTi8
#devtojavascript#devto#dev#cart#policies
Long article (339 words) — no AI summary yet.
Reading 0:00
15s threshold

Add an AI Cart Assistant to Shopify That Only Answers From Your Policies

A keyword bot breaks when shoppers phrase things differently. An LLM handles "will this reach me by Friday?" fine, but it can also make things up. The fix is to give it your policies and the live cart, and tell it to stick to them.

Send the cart from the storefront

The widget reads /cart.js and posts it with the question to your server.

javascript

async function ask(question) {

const cart = await (await fetch('/cart.js')).json();

const res = await fetch(' https://your-server.com/api/cart-assistant ', {

method: 'POST',

headers: { 'Content-Type': 'application/json' },

body: JSON.stringify({ question, cart }),

});

return (await res.json()).reply;

}

Ground the model on the server javascript import Anthropic from '@anthropic-ai/sdk'; const client = new Anthropic(); // reads ANTHROPIC_API_KEY from env

const POLICIES =

Delivery: 3-5 business days.

COD: available under ₹5,000.

Returns: within 7 days of delivery.

Free shipping…

Continue reading — create a free account

Join HashtagPLUS to read full articles, follow hashtags, vote, and join the conversation.