Define site action
Site-specific tasks (add to cart, appointment form, coupon) are defined with SmartOperator.eylemTanimla. The agent can only call defined actions.
- Developer
How to define a site action?
Site-specific tasks (add to cart, appointment form, coupon) are defined with SmartOperator.eylemTanimla. Who can do this: Developer. The agent can only call defined actions. Parameters are validated against your definition before reaching the handler: fields not in the definition are discarded; if type, en_az, or secenekler do not match, the handler is not called and a gecerersiz_parametre error is returned to the agent.
<script>
SmartOperator.eylemTanimla("sepeteEkle", {
aciklama: "Ürünü sepete ekler",
parametreler: {
urunId: { tur: "metin" },
adet: { tur: "sayi", en_az: 1 }
},
onayGerekir: false
}, async function ({ urunId, adet }) {
await sepet.ekle(urunId, Number(adet) || 1);
return { tamam: true, sepetAdedi: sepet.adet() };
});
</script>
Steps
Define the action on your pages, before or after the script tag; the tag's preparation line queues early calls.
aciklama: a short description so the agent understands when to use the action.parametreler: for each parameter,tur(metinorsayi); optionalen_azandsecenekler(list of allowed values).onayGerekir: iftrue, the action does not execute unless the visitor clicks “Confirm” in the chat.The handler returns a result object (e.g.,
{ tamam: true }); the result is passed to the agent. If an error is thrown, it is passed as{ tamam: false, hata }.
en_az, or secenekler do not match, the handler is not called and a gecersiz_parametre error is returned to the agent. Business rules such as product availability should still be checked in your handler.