Share feedback, ideas and get community help

Updated 3 weeks ago

What are the available functions to interact with the typebot enviroment in the Script Block

At a glance

The community member is asking if there are any functions to retrieve data from the environment, specifically the "Moment of the day", to use inside a script block. The comments suggest two ways to achieve this: using a Set variable block with the "Moment of the day" option and accessing it in the script block, or manually parsing the JavaScript code that calculates the "Moment of the day" variable. The answer provided indicates that all pre-defined set variable values, including "Moment of the day", are JavaScript code that can be parsed manually.

Useful resources
I saw in the documentation the setVariable function in the script block, are there any other functions to retrieve data from the enviroment? because i want to pull data in the script like 'Moment of the day' inside the script block
Marked as solution
In the end, all pre-defined set variable values is Javascript code that you could parse manually yourself. For Moment of the day for example:

https://github.com/baptisteArno/typebot.io/blob/86970576f1127231591b608152365ed80cf39438/packages/bot-engine/src/blocks/logic/setVariable/executeSetVariable.ts#L266-L281
View full solution
A
P
B
4 comments
There are 2 ways you can achieve this:
  1. Use a Set variable block with the Moment of the day option, and use that variable inside of your Script block. (Easiest method)
  2. Use a Script block to calculate the moment of the day in JavaScript directly. It's tedious and quite useless if you seek the same result as what returns Moment of the day in Set variable, but if you need something more custom, then this is the way. (Harder method)
What i was asking is if I can pull the moment of the day variable inside the script block, the equivalent of a 'getVariable' function in the script block, because there is no documentation about how to access System variables besides the set variable block
Mhm, I understood that, and if you first saved System variables like Moment of the day in a Typebot variable, you can access it in a Script block using {{variable_name}}
In the end, all pre-defined set variable values is Javascript code that you could parse manually yourself. For Moment of the day for example:

https://github.com/baptisteArno/typebot.io/blob/86970576f1127231591b608152365ed80cf39438/packages/bot-engine/src/blocks/logic/setVariable/executeSetVariable.ts#L266-L281
Add a reply
Sign up and join the conversation on Discord