https://discord.gg/botpress logo
How to use the userKey
# 🤝help
c
I was informed that the userKey is the CRM key and the field used to search for stored user and conversation variables. Could you please provide an example implementation, some code, or any documentation showing how to use this in a new conversation for a returning user?
l
samplecode: > window.botpress.on('webchat:initialized', () => { // Here, you would fetch the data for your logged-in user. // This is just an example with static data. const returningUserData = { crmId: 'CRM-12345', // This is your unique userKey firstName: 'Jane', lastName: 'Doe', email: 'jane.doe@example.com', }; console.log('Webchat is initialized. Sending user data to the bot.'); // This function sends the user's data to Botpress. window.botpress.updateUser({ data: returningUserData, }); });
- When a known user starts a new conversation, you can provide their data to the bot to create a personalized experience. This is typically done by using the window.botpress.updateUser method when the Webchat on your website is initialized.
Let me know if this helps 😄