T
TypebotRuss Webb

Run function JS on client

Is it possible to use a JS snippet in an Ask Assistant Function block to: a} run the code below on the client or b) execute a block in the flow that currently does this already? The code: function parseURL() { const windowURL = window.location.href; const allSegments = windowURL.split('/'); const relevantSegments = allSegments.slice(4); // slice starts after third '/' const modifiedSegments = relevantSegments.map(function(segment) { return segment.replace(/-/g, ' '); }); return modifiedSegments; } //const splitURL = parseURL(); //const currentURL = JSON.stringify(splitURL); const currentURL = parseURL(); return currentURL;
Russ Webb
Russ Webb17d ago
The AI Assistant calls the function to get the user's current location on the platform, and asks them to navigate to a new place and checks again to confirm. Just trying to make it happen on the typebot side
Baptiste
Baptiste16d ago
Unfortunately your code is referencing the window variable which only available on the client side. And Tools in AI blocks can't be executed on the client 🙁 Maybe you can collect the currentURL into a set variable before calling the assistant?
Russ Webb
Russ Webb16d ago
Ya, I did that so that gets me close. I was hoping that the Assistant could make a call to "update" the current URL if the user navigates to another part of the platform. For example, the AI asks the user to navigate to the applicable section and now it need to check where they are.