I commented with my question here too:
How do I programmatically update the Zapier Chatbot embed code so that I pass params?
ChatGPT suggested the following :
<script>
function createChatbotEmbed(params) {
const chatbotEmbed = document.createElement(‘zapier-interfaces-chatbot-embed’);
chatbotEmbed.setAttribute(‘is-popup’, ‘false’);
chatbotEmbed.setAttribute(‘chatbot-id’, ‘<Redacted for post>’);
chatbotEmbed.setAttribute(‘height’, ‘600px’);
chatbotEmbed.setAttribute(‘width’, ’90%’);
if (params) {
chatbotEmbed.setAttribute(‘params’, JSON.stringify(params));
}
// Append the embed code to the DOM
document.querySelector(‘.h6’).appendChild(chatbotEmbed);
// Debugging: log the final embed element
console.log(chatbotEmbed.outerHTML);
}
// Check if the logged_in_user object exists and contains a softr_user_email property
if (window.logged_in_user && window.logged_in_user.‘softr_user_email’]) {
// Get the user’s email
const userEmail = window.logged_in_userl‘softr_user_email’];
console.log(“User email:“, userEmail); // Debugging line
// Create the chatbot embed code with parameters
// createChatbotEmbed({ email: userEmail });
createChatbotEmbed({ customParam: userEmail });
} else {
console.log(“User not logged in or email not available”); // Debugging line
createChatbotEmbed(null);
}
</script>
</p>
</div>
The script correctly grabs the logged in user’s email address and updates the embed code but Zapier’s chatbot doesn’t seem to recognize it. IN the code above, I previously had the ‘email’ line instead of the customParam line . But neither are recognized.