Share feedback, ideas and get community help

Home
Members
Azeemuddin
A
Azeemuddin
Offline, last seen 3 months ago
Joined September 13, 2024
setVariable({{console_log}}, 'Console Log')

const accessTokens = {
'hussan.hussain@maqsad.io': 'token'
};

const apiUrl = 'https://chatwoot.com/api/v1/accounts/2/conversations/meta?labels="mdcat-landing-page-get-guidance-now"&status=open';

let foundEmail = null;

for (const email in accessTokens) {
if (accessTokens.hasOwnProperty(email)) {
const token = accessTokens[email];
try {
const response = await fetch(apiUrl, {
method: 'GET',
headers: {
'api_access_token': ${token}
}
});

if (!response.ok) {
setVariable({{console_log}}, HTTP error! Status: ${response.status})
throw new Error(HTTP error! Status: ${response.status});
}

const data = await JSON.parse();

if (data.meta && data.meta.mine_count < 200) {
foundEmail = email;
setVariable({{console_log}}, Found email: ${email} with mine_count: ${data.meta.mine_count})
break; // Exit the loop once the condition is met
}
} catch (error) {
setVariable({{console_log}}, Error fetching data for email ${email}: ${error}})
throw new Error(Error fetching data for email ${email}:, error);
}
} else {
setVariable({{console_log}}, Own property not found)
}
}

if (foundEmail) {
setVariable({{agent_email}}, foundEmail)
setVariable({{console_log}}, Email with mine_count < 200: ${foundEmail})
} else {
setVariable({{console_log}}, No email found with mine_count < 200)
}

i am trying to run this script on typebot and would appreciate if someone can tell me what i am doing wrong?
3 comments
B
A
hi i need help with type, basically i have a webhook that returns a JSON string which i save in a variable but i want to use that JSON string in body of my next webhook

""custom_attributes": {
"TypeBot Session": "123abc456def789ghi",
"Attribute 1": "abc"
}" returned string from my first webhook

removed typebot session with the help of string.replace but now i want to convert it to JSON so that i can use it in body of my next Webhook
1 comment
L