Share feedback, ideas and get community help

Updated 11 months ago

How to set a JavaScript Array variable in Typebot?

Hi, I'm struggling to set an Javascript array variable in Typebot. The context is the following. I need to generate an array of messages to send to an API via Webhook.

The Webhook have the following body:

{
"model": "some-model",
"max_tokens": 1024,
"messages": {{messages_hist}},
"stream": false
}

I need to pass in "messages" the following Array:

[{"role": "system","content": "some system message"},{"role": "user","content": "some user message"}]

To achieve this I'm trying to 'Set variable' in the Typebot. A 'Custom' variable by the way, with this:

[{"role": "system","content": "some system message"},{"role": "user","content": "some user message"}]

The problem is that the Webhook does not work because(I think) what's inside the JS Array is being interpreted as a regular string:

["{"role":"system","content":"some system message"}","{"role":"user","content":"some user message"}"]

Any clues on how to handle Array variables in Typebot?
B
A
I
10 comments
Indeed, Typebot variables value only accept strings and list of strings
So if you set this value to a variable: [{"role": "system","content": "some system message"},{"role": "user","content": "some user message"}], it will be converted to ['{"role": "system","content": "some system message"}','{"role": "user","content": "some user message"}']
I'm trying to think of a workaround for this
Alright it should work:

Plain Text
{
    "model": "some-model",
    "max_tokens": 1024,
    "messages": {{={{messages_hist}}.map(JSON.parse)=}},
    "stream": false
}


Unfortunately it currently not working as expected so I just pushed a fix in production.
I see that you are self-hosting so you'll have to wait for the next release (1st of Jan) to be able to do that
Hi Baptiste, thank you! I was installing N8N to try to workaround the issue.
I've tested in the production environment and it is working 🙂
I'm on the latest version and I still can't parse it.
{{=JSON.parse({{my_ob}})=}}

Not work for me
Attachment
image.png
Can you show us what your body value looks like?
Add a reply
Sign up and join the conversation on Discord