Share feedback, ideas and get community help

D
F
M
a
g

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;
R
B
3 comments
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
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?
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.
Add a reply
Sign up and join the conversation on Discord
Join