访客在店铺每个页面上点按钮就能和你的 Agent 通话。你需要一个已发布的 Agent,以及 Agent → 发布 → 网站挂件里的嵌入代码。
layout/theme.liquid,把嵌入代码粘贴到 </body> 之前:<script src="https://evasay.com/voice-widget.js" data-agent="AGENT_SLUG" async></script>
在 Agent → 发布 → 允许的网站里,每行填一个店铺会用到的网址,例如 https://your-store.myshopify.com 和 https://www.example.com。带 www 和不带是两个不同的网址。只有这些网站能把变量和函数传给 Agent。
在 theme.liquid 的嵌入代码下面,把页面知道的信息交给下一通电话。Liquid 在 Shopify 那边填入这些值;这些值来自访客的浏览器,Agent 会把它们当作未经验证的信息。
<script>
window.evasay = window.evasay || [];
evasay.push(function (agent) {
agent.setVariables({
customer_name: {{ customer.first_name | default: '' | json }},
page: location.pathname
});
agent.update('Cart: {{ cart.item_count }} items', { key: 'cart' });
});
</script>
给 Agent 加一个类型为在你的网页上运行、名为 add_to_cart 的函数,带一个 variant_id 参数,在页面上用 Shopify 的购物车接口应答:
<script>
window.evasay = window.evasay || [];
evasay.push(function (agent) {
agent.registerTool('add_to_cart', async function (args) {
const response = await fetch('/cart/add.js', {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({ items: [{ id: Number(args.variant_id), quantity: 1 }] })
});
if (!response.ok) throw new Error('Could not add it to the cart');
return { ok: true, checkout: '/checkout' };
});
});
</script>
在知识库或指令里告诉 Agent 它可以推荐的商品和款式 ID。更换或更新模板后,检查代码是否还在 theme.liquid 里。