white-hamburger-48697
05/16/2024, 9:17 PMnice-airplane-37559
05/16/2024, 9:36 PMwhite-hamburger-48697
05/16/2024, 9:47 PMuser
is part of the BotPress session state
async function postToBrowseAI() {
const url = 'https://api.browse.ai/v2/robots/bot.botID/tasks';
const headers = {
'Authorization': 'Bearer bot.browseaitoken',
'Content-Type': 'application/json'
};
const body = JSON.stringify({
inputParameters: {
originUrl: user.grouponformattedURL // Use the URL from the user object
}
});
try {
const response = await fetch(url, {
method: 'POST',
headers: headers,
body: body
});
if (!response.ok) {
throw new Error(HTTP error! status: ${response.status}
);
}
const data = await response.json();
console.log('Full response from Browse AI:', data);
// Check if data.result and data.result.id are defined
if (data.result && data.result.id) {
// Log the task ID to verify it's being accessed correctly
console.log('Task ID from response:', data.result.id);
// Save the task ID to the user object
user.browseaitaskID = data.result.id;
console.log('Task ID saved to user.browseaitaskID:', user.browseaitaskID);
// Update the BotPress session state
event.state.user = user;
// Log the updated user object
console.log('Updated user object:', user);
} else {
console.error('Response did not contain a task ID');
}
} catch (error) {
console.error('Error making POST request:', error);
}
}
// Call the function to make the API request
postToBrowseAI();white-hamburger-48697
05/16/2024, 10:18 PMnice-airplane-37559
05/16/2024, 10:48 PMnice-airplane-37559
05/17/2024, 2:24 AMgifted-house-97450
07/04/2024, 11:47 PM