Share feedback, ideas and get community help

Updated 3 months ago

Issues with Return Function After GET Request in Typebot Open Ai Assistant Functions

Hello, I’m encountering an issue with implementing a return function within Typebot after making a GET request. The aim is to call a webhook and use the response to guide the conversation flow. The GET request seems to be working fine, but the issue arises with getting the function return to be properly recognized by Typebot.Below is the code I’m using within an asynchronous function in Typebot:

const url = https://primary-production-ae3d.up.railway.app/webhook/643e6dfc-786f-480a-a201-cef249e50f6b?search=${encodeURIComponent(search)};

// Main async function that performs the GET request
async function main() {
try {
const response = await fetch(url);
console.log("Response status:", response.status);

if (!response.ok) {
throw new Error(HTTP Error: ${response.status});
}

const data = await response.json();
console.log("JSON data received:", JSON.stringify(data));

if (data.text) {
console.log("Text found:", JSON.stringify(data.text));
return JSON.stringify(data.text);
} else {
console.log("'text' field not found in data.");
return "";
}
} catch (error) {
console.error("Error fetching data or processing the data:", error);
return "";
}
}

// Calling the main function and processing the returned text
main().then(text => {
console.log('Returned text:', text);
});

The GET request works, and the console logs confirm that data is being received correctly. However, the return from the main function doesn’t seem to be carried forward as expected, and the bot is not responding in line with the call function's response.

Could anyone assist me in understanding what might be going wrong? How can I ensure that the return from my asynchronous function is correctly used by Typebot to direct the response?
Add a reply
Sign up and join the conversation on Discord