What im supposed to do inorder to fetch data from ...
# 🤝help
w
hello fellow botfriends, how do I get parameters values from an URL and save those values as variables to use them in other nodes? for example, if the url is "google.com?name=james", i need to extract the "james" value and save it as a variable so that, for example, the first message of the bot would be "hello james!".
f
document.addEventListener('DOMContentLoaded', function () { let currentUrl = window.location.href; console.log("Current URL: " + currentUrl); let url = new URL(currentUrl); let searchParams = new URLSearchParams(url.search); let name = searchParams.get('name'); if(name) { console.log("Hello " + name + "!"); } else { console.log("Name parameter not found in URL."); } });
Add that JavaScript to your website code.
And you will see something like this
w
thx for the help but the things is that im used the studio version, so basically i need to put this code in a node, i actually read in the docs that i can actually use Hooks to setup action before an event occours. But im trying to figure all out, im i missing something?
f
You can use hooks to setup an action before an event but I don't think that you can read the url from the chatbot
w
so this is the real life scenario, an external file calls the bot via a redirect calling , now before the conversation starts i need to fetch the data in the url and store them(the urls are dynamic)
f
From the website URL that the bot is on or do you have an URL in the redirect calling?
w
the bot is not in the same website, ill try to reformulate the issues: after the redirect, the user lands on the bot page, that page has the URL with the parameters I should fetch
f
If you are trying to do something like this:
@quick-musician-29561 just fixed my problem with it so it now works if you want to try it out🛠️
Make sure to put in your own BotID, ClientID and WebhookID
w
ok thx, one more question where im supposed to put this script? cause as i said im using the cloud version so im actually working with nodes, should i put the function handleUrl inside an "execute code" block?
f
I added an index.html file for you which is just for a template. You would have to add it to your own JavaScript on your website
w
so basically i need to add it on my client side? right? and after that how im supposed to fetch the url?
f
Depends on how your website is setup but yes most likely.
2 Views