function output(userData, context) {
const tellescopeData = {
answers: [
{
key: "first_name",
value: userData.first_name,
},
{
key: "last_name",
value: userData.last_name,
},
{
key: "phone",
value: userData.phone,
},
{
key: "email",
value: userData.email,
},
// Add any other user data properties that you want to send to Tellescope here
],
variant_label: "main",
variant_uuid: "<VARIANT_UUID>",
finalized: true,
created_at: generateFormattedDate(),
experiment_uuid: null,
flow_label: "<FLOW_LABEL>",
};
// @TODO: Replace with your actual company name,
// and provide the API key to Embeddables to store securely on the backend
const API_KEY_IDENTIFIER = "{{YOUR_COMPANY_NAME---tellescope---api_key}}";
const formId = "<FORM_ID>";
const endpoint = `https://api.tellescope.com/v1/webhooks/formsort/${API_KEY_IDENTIFIER}?formId=${formId}`;
// Send POST request, using the Embeddables backend proxy to avoid CORS issues
fetch(
`https://proxy-secure.trysavvy.com/?url=${encodeURIComponent(endpoint)}`,
{
method: "POST",
headers: {
"Content-Type": "application/json",
},
body: JSON.stringify(tellescopeData),
}
);
}
function generateFormattedDate() {
const date = new Date();
const isoString = date.toISOString();
return isoString.replace("Z", "+00:00");
}