The bot on your site can see the cart
The scenario asks the page what the visitor has in their cart, and answers with that in mind.
What the scenario looks like
- Execute + Data
- LLM
A bot that does not know what somebody has already put in their cart answers like a reference book: general words about delivery in general. The visitor is asking about their own order. One node and ten lines on your page close the gap.
What is inside
- Visitor’s question — the entry.
- What is in the cart — a node that calls a function declared on your page and waits for the browser to answer. That is how the scenario learns what only the page knows.
- Answer with the cart in mind — the agent. Both the question and the cart contents go into its prompt.
- Answer in the widget — the exit.
The same trick tells the bot the chosen plan, the city in the header, the checkout step — everything that lives on the page and never reaches a server.
What to set up for yourself
- The function name on the node must match the one declared on your site.
- The agent’s prompt. It currently says not to invent products when the cart is empty and not to name internal identifiers: without that line the bot will one day quote a SKU.
- The timeout. Ten seconds by default. A function that goes to a server itself may not make it, and the step then fails — so keep it simple.
What to connect
No external services; a change on your own site. Next to the widget snippet, declare a function with the same name:
<script>
iternaWidget.defineFunction({
name: "getCart",
handler: () => ({
items: window.cart.items.map((i) => ({ title: i.title, qty: i.qty, price: i.price })),
total: window.cart.total,
currency: "RUB",
}),
});
</script>
It must return a plain object. Only return what you are happy to share: everything it returns goes into the model.