Share feedback, ideas and get community help

Home
Members
Russ Webb
R
Russ Webb
Offline, last seen 3 months ago
Joined September 13, 2024
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;
3 comments
R
B
Is there a way, with code or any other means, to clear the chat window of existing messages? When a user clicks a button to restart the conversation, I already empty the chat history, but I would also like to clear the chat container.
2 comments
B
Probably a silly question but, do we manually append user and assistant messages to the chat history, or does that happen automatically?
2 comments
R
B
Is it possible to turn an input into a color picker? I know this can be done in HTML by using JavaScript to change the input type but I'm not sure if there's a way to do this within a bot.
3 comments
R
B
It is possible to use variables in the js script for things like the bubble background color, avatar URL, and even the typebot name? I want to be able to add the JS to the head of a website, but have different bots load on different pages based on the URL that I pull into the bot with a set variable block with the JS function in the custom value to pull the host url. Right now, I pull in the URL, split it and check with a webhook in a first step of a flow. I'm wanting to then change the bubble color based on the webhook returned values. In other words, if URL subpage is a specific product category of an eCommerce store, checked with a webhook to an automation that checks a postgresql db for the values, I want to change to a red bubble and run a specific bot.
4 comments
R
B
I understand how to get the main document url from the page hosting the bot, and can run a webhook to validate the url but, is there a way to "hide" or disable the bubble/bot after checking, if the url doesn't meet criteria? I can easily put a path in the bot flow that routes to a "You are not authorized to use this bot" message displayed, but I'm wanting to hide even the bubble if the url doesn't even meet criteria that I check with a webhook as the first step in the bot.
1 comment
R
Is it possible (or could it be) to set up some sort of timer that waits for a user's input but then either populates a variable that can be fed into a condition block or even just routes from the user input after a certain time with no input?

I'd like to keep a conversation going with a user with my 'Ask Assistant' block but then get the total thread token usage from OpenAI after the conversation is done (after a certain time with no user interaction) and potentially also send a final message and reset the thread.

Other applications of this could also include triggering a subsequent "Are you still there?" message, etc.
1 comment
B
I'm probably just missing something silly but, my webhook fires immediately upon starting the bot, so the variables it is being sent (location_id, main_page, sub_page) are not yet populated. What am I doing wrong?
2 comments
B
R
I just wanted to share, in case anyone else gets value from this...

I wanted to be able to run multiple instances of the viewer to ensure if the connection to the viewer goes down or gets overloaded. I solved this in a docker swarm configuration (a personal favorite). I used the same docker-compose.yml file and .env files I use to set up a standalone instance, but instead of 'docker compose up -d', I used 'docker stack deploy -c docker-compose.yml typebot'. I then changed the publish mode of the resulting viewer and builder services, which are attached to a custom swarm overlay network, to "host" instead of "ingress" (for external access). Now I have replication and failover for both the builder and viewer. In the end, I reduced the replicas for the builder to 0 and set the viewer at 1 for now, but I can easily scale. I've tied in my load balancer so it will automatically scale with new containers. I use Portainer to manage my swarm and have my swarm spread over one master+worker and three other worker nodes.
I'm looking to get the url of the host page for an embedded bot, using JS added to the typebot embed code and set along with the other parameters. Just looking for feedback, is this the most sensible way to send the url to the bot server? I'm trying to build contextual responses based on the url the user is on.
2 comments
R
B
I have the following JS in a Create Variable block that was working fine to parse the URL of the browser but it seems to have stopped working. It was working fine before. The variable "location" is not populating with anything. There are no console errors:

Create Variable block sets first result as currentURL:

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;
-------

Then, in a second Create Variable block ("location"), I have:

{{={{currentURL}}[1]=}}

Any ideas why it would have stopped working?
6 comments
B
R
I think I've tried every possible variation, and even turned to ChatGPT to help, to avail. I am trying to use the 'set variable' block to trigger a webhook, return a response, and save the response to the variable but I'm not getting anything to display. Here's the code inside the 'set variable' block with a variable name of 'authorization':

const webhookUrl = 'https://api.pbt.io/v2/96d049d4-613c-4623-8f5a-3c8cc577da54';
const response = await fetch(webhookUrl, {
method: 'POST', // or 'PUT'
headers: {'Content-Type': 'application/json'},
body: JSON.stringify({
'location': {{location}},
'authorization_code': {{authorization_code}}
})
});
const authorization = await response.json;
return JSON.stringify(authorization);

The values being sent to the webhook are working perfectly. The value being returned from the webhook is a simple JSON as follows:

[
{
"authorization": "authorization failed"
}
]

I then have another block right after where I display the 'authorization' in a text block but it comes up blank. Nothing appears in the console for errors or anything else.

All I want to do is populate the 'authorization' variable with the response value from the webhook.
5 comments
B
R