Is there something wrong with it?
Nothing wrong. Just repetitive.
There is a place where I can define custom functions?
I tryed, with no success, define a function inside a script block.
What I imagine that could be possible is something like:
Script block: const r = (x) => x.toLocaleString('pt-br', { style: 'currency', currency: 'BRL'})
Text block: {{= r(123456) =}}
Have you read the Set variable doc? Can you let me know what is unclear?
All you have to do is add a Set variable block, select Custom value and paste: {{variable}}.toLocaleString('pt-br', { style: 'currency', currency: 'BRL'})
My goal is not to store a formatted value.
My goal is to define a format function that I can reuse later with different variables.
I'm using many monetary variables, that change values over the course of the conversation.
So, at the moment, this formatting code is replicated over an over in different blocks.
That's what I'm trying to avoid.
Just compute everything in several variables and finally have a block that generates the end content?
Let me reformulate.
The question is:
Is it possible to have user defined functions?
I guess not, right?
what @Vilela™ is trying to say is if its possible to create a global function in one of the script block that will be accessible by all the other blocks
is that correct?
It don't have to be in the script block, can be anywhere.
But yes, you got the point. 👍
What you think you need can be wrong so I’m trying to understand the issue you have so that I can provide the best solution 🙂
Hey so sorry @Vilela™, I actually thought I was an another thread so my answers don't make sense 🙏
save your function in the window at the start (make sure to execute it in client)
then just call it in any of the set variable block after it.
Issue with this work around?
Has to be run on client
Solution proposed for Baptiste:
Allow adding a script block in typebot settings where the script will be automatically added to the viewer file