Functions Pro
Functions turn an answer into an action. When a visitor asks for something your site can do, for example "talk to a person", the assistant shows a button. Clicking it runs a JavaScript function on your page with the details the assistant collected.
Important: functions run your own code. Validate the inputs, ask for confirmation before doing anything irreversible, and test in the Test environment before publishing.
How it works
- You describe the function in Functions: when to use it, the button label, the parameters to collect, and the handler reference, the name of a JavaScript function on your page.
- When a question matches, the assistant answers and shows the button.
- When the visitor clicks, the widget calls your handler with one object:
{ name, arguments, conversationId, history }.
Example: hand off to a person
1) Create the function in the dashboard
| Field | Example |
|---|---|
| Name | handoff_to_human |
| Description | When the visitor asks for a person, suggest a handoff to support. |
| Button label | Contact support |
| Handler reference | AskvioHandlers.contactSupport |
| Parameters (JSON schema) | {"type":"object","properties":{"reason":{"type":"string"}},"required":["reason"]} |
2) Define the handler on your site
Add it to the same page as the widget (directly or in a tag manager tag). The handler reference must be a plain dotted path to a function on window.
<script>
window.AskvioHandlers = {
contactSupport: async ({ name, arguments: args, conversationId, history }) => {
await fetch("/api/support-handoff", {
method: "POST",
headers: { "Content-Type": "application/json" },
body: JSON.stringify({ reason: args.reason, conversationId })
});
}
};
</script>
3) Test it
- In the preview, ask "I need to talk to a person about my order".
- Check that the answer shows the Contact support button.
- Click it and check that your handler runs. If nothing happens, the console shows
[AskVio] Handler not foundwhen the handler reference doesn't match a function on the page.
Each click is also sent to GA4 as function_invoked. Free plans don't include functions; Pro includes 3, Business and above unlimited.