Share feedback, ideas and get community help

Updated last year

Create object variables in prefilledVariables on start bot

At a glance

The community member asks if it is possible to pass an object in the prefilledVariables parameter, specifically the contact object, and how to access contact.name in their flow. Another community member responds that this is not possible, as variables only work with strings or lists of strings.

Another community member provides an example of converting a JSON object to a list of text items, which may be helpful for the original poster, but is not directly related to the original question.

The original poster thanks the community members and indicates they will try the provided example.

His, is possible to pass an object in prefilledVariables, as the 'contact' below?
If yes, how can I access 'contact.name' into my flow?
const reqData = { typebot: TypebotName, prefilledVariables: { number: '929292920000', contact: {id:1, name:'John', address:'xxx',...others keys} } }; const { data } = await axios.post( TypebotUrl, reqData );
B
R
L
4 comments
No, that's not possible, variables only work with string or a list of strings πŸ™
Have a look a this json to list:

const json = {
"data": [
{ "name": "🍎 Manzana" },
{ "name": "πŸ‡ Uvas" },
{ "name": "πŸ‰ Sandia" },
{ "name": "πŸ’ Cerezas" },
{ "name": "🍐 Pera "}
]
};

function convertJSONToList(jsonData) {
if (!jsonData

!jsonData.data

!Array.isArray(jsonData.data)) {
return "JSON invΓ‘lido";
}

const items = jsonData.data.map((item, index) => ${index + 1} - ${item.name});
return items.join("\n");
}

const listaDeTexto = convertJSONToList(json);
return listaDeTexto;
Thank you, I will try it
Make sure to create a variable to call the script
Add a reply
Sign up and join the conversation on Discord