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?
4 Replies
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:
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 thatHi Baptiste, thank you! I was installing N8N to try to workaround the issue.
I've tested in the production environment and it is working đŸ™‚
Unknown User•8mo ago
Message Not Public
Sign In & Join Server To View
Can you show us what your body value looks like?