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?