acceptable-kangaroo-64719
10/24/2023, 11:25 AMevent.userId
is a system-generated ID that is based on the user's browser and device. It is, however, immutable so you cannot set it with another value. If you want to have a way to authenticate users, you should set that up within your website and pass the user ID in via the init()
script. However an easy (but not secure) way to check if the user is returning or not is to save the userId to a table, and then check in the table at the start of the conversation for that userIdfew-area-98148
10/27/2023, 8:15 AMacceptable-kangaroo-64719
10/27/2023, 10:55 AMacceptable-kangaroo-64719
10/27/2023, 10:55 AMacceptable-kangaroo-64719
10/27/2023, 10:55 AMacceptable-kangaroo-64719
10/27/2023, 10:56 AMwindow.botpressWebChat.init()
, which starts the web chat. A lot of data is passed into this function to make it work, and we can pass additional, custom data as shown in our documentation here https://botpress.com/docs/developers/webchat/controlling-webchat-using-js/#send-user-data-from-your-website-to-botpressacceptable-kangaroo-64719
10/27/2023, 10:56 AMjs
window.botpressWebChat.init({
userData: {
name: 'Jack Black',
},
})
acceptable-kangaroo-64719
10/27/2023, 10:57 AMacceptable-kangaroo-64719
10/27/2023, 10:58 AMacceptable-kangaroo-64719
10/27/2023, 10:59 AMacceptable-kangaroo-64719
10/27/2023, 10:59 AMacceptable-kangaroo-64719
10/27/2023, 11:00 AMhtml
<!DOCTYPE html>
<html>
<head>
<title>My First HTML Page</title>
</head>
<body>
<h1>Welcome to My Website</h1>
<p>This is a basic example of an HTML page.</p>
<ul>
<li>Item 1</li>
<li>Item 2</li>
<li>Item 3</li>
</ul>
<p>Thank you for visiting!</p>
</body>
<script src="https://cdn.botpress.cloud/webchat/v0/inject.js"></script>
<script>
window.botpressWebChat.init({
"composerPlaceholder": "Chat with bot",
"botConversationDescription": "This chatbot was built surprisingly fast with Botpress",
"botId": "5fcacb4c-baae-4061-a258-0a7d47b060d3",
"hostUrl": "https://cdn.botpress.cloud/webchat/v0",
"messagingUrl": "https://messaging.botpress.cloud",
"clientId": "5fcacb4c-baae-4061-a258-0a7d47b060d3",
"lazySocket": true,
"frontendVersion": "v0",
"useSessionStorage": true,
"enableConversationDeletion": true,
"showPoweredBy": true,
"theme": "prism",
"themeColor": "#2563eb"
});
</script>
</html>
acceptable-kangaroo-64719
10/27/2023, 11:00 AMwindow.botpressWebChat.init()
function with whatever data you want to pass to the botacceptable-kangaroo-64719
10/27/2023, 11:03 AMhtml
<!DOCTYPE html>
<html>
<head>
<title>My First HTML Page</title>
</head>
<body>
<h1>Welcome to My Website</h1>
<p>This is a basic example of an HTML page.</p>
<ul>
<li>Item 1</li>
<li>Item 2</li>
<li>Item 3</li>
</ul>
<p>Thank you for visiting!</p>
</body>
<script src="https://cdn.botpress.cloud/webchat/v0/inject.js"></script>
<script>
window.botpressWebChat.init({
"userData":{
"platform":"discord",
"userNames":"Mieczysław"
},
"composerPlaceholder": "Chat with bot",
"botConversationDescription": "This chatbot was built surprisingly fast with Botpress",
"botId": "5fcacb4c-baae-4061-a258-0a7d47b060d3",
"hostUrl": "https://cdn.botpress.cloud/webchat/v0",
"messagingUrl": "https://messaging.botpress.cloud",
"clientId": "5fcacb4c-baae-4061-a258-0a7d47b060d3",
"lazySocket": true,
"frontendVersion": "v0",
"useSessionStorage": true,
"enableConversationDeletion": true,
"showPoweredBy": true,
"theme": "prism",
"themeColor": "#2563eb"
});
</script>
</html>
acceptable-kangaroo-64719
10/27/2023, 11:04 AMacceptable-kangaroo-64719
10/27/2023, 11:12 AMacceptable-kangaroo-64719
10/27/2023, 11:12 AMacceptable-kangaroo-64719
10/27/2023, 11:13 AMwindow.botpressWebChat.init()
function. We pass event.userId
as input and define a workflow variable as outputacceptable-kangaroo-64719
10/27/2023, 11:13 AMacceptable-kangaroo-64719
10/27/2023, 11:14 AMacceptable-kangaroo-64719
10/27/2023, 11:14 AMacceptable-kangaroo-64719
10/27/2023, 11:15 AMacceptable-kangaroo-64719
10/27/2023, 11:15 AMfew-area-98148
10/29/2023, 9:46 PMacceptable-kangaroo-64719
10/30/2023, 10:33 AMfamous-jewelry-85388
10/30/2023, 6:02 PMfew-area-98148
10/30/2023, 7:48 PMfamous-jewelry-85388
10/30/2023, 8:05 PMfamous-jewelry-85388
10/30/2023, 8:05 PMfamous-jewelry-85388
10/30/2023, 8:08 PMfamous-jewelry-85388
10/30/2023, 8:09 PMfamous-jewelry-85388
10/30/2023, 8:10 PMfew-area-98148
10/31/2023, 7:01 AMfamous-jewelry-85388
10/31/2023, 2:17 PMfamous-jewelry-85388
10/31/2023, 2:18 PMfamous-jewelry-85388
10/31/2023, 2:18 PMfamous-jewelry-85388
10/31/2023, 2:18 PMfew-area-98148
11/01/2023, 1:29 PMfamous-jewelry-85388
11/01/2023, 2:04 PMfamous-jewelry-85388
11/01/2023, 2:15 PMfamous-jewelry-85388
11/01/2023, 2:16 PMfew-area-98148
11/01/2023, 6:52 PMfew-area-98148
11/01/2023, 7:01 PMfamous-jewelry-85388
11/01/2023, 9:26 PMfamous-jewelry-85388
11/01/2023, 9:26 PMfamous-jewelry-85388
11/01/2023, 9:26 PMfamous-jewelry-85388
11/01/2023, 9:26 PMfew-area-98148
11/02/2023, 7:34 AMfamous-jewelry-85388
11/03/2023, 10:24 PMfamous-jewelry-85388
11/03/2023, 10:25 PMfamous-jewelry-85388
11/03/2023, 10:25 PMfew-area-98148
11/04/2023, 8:16 AMglamorous-market-25131
11/04/2023, 6:18 PMacceptable-kangaroo-64719
11/06/2023, 11:02 AMjs
function generateRandomUserId() {
const chars = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ';
return Array.from({ length: 10 }, (_, i) =>
chars[Math.floor(Math.random() * (i < 8 ? 10 : chars.length))]
).join('');
}
//Call the function like this:
workflow.randomUserId = generateRandomUserId();
glamorous-market-25131
11/07/2023, 8:59 AMglamorous-market-25131
11/07/2023, 9:00 AMacceptable-kangaroo-64719
11/07/2023, 12:39 PMacceptable-kangaroo-64719
11/07/2023, 1:21 PMglamorous-market-25131
11/07/2023, 5:42 PMfamous-jewelry-85388
11/07/2023, 8:11 PMglamorous-market-25131
11/08/2023, 9:38 AMglamorous-market-25131
11/08/2023, 9:39 AMfamous-jewelry-85388
11/08/2023, 6:46 PMfamous-jewelry-85388
11/08/2023, 6:46 PMfamous-jewelry-85388
11/08/2023, 6:46 PMfamous-jewelry-85388
11/17/2023, 7:37 PMfamous-jewelry-85388
11/17/2023, 7:38 PMfamous-jewelry-85388
11/17/2023, 7:38 PMfew-area-98148
11/18/2023, 5:04 PMfamous-jewelry-85388
11/18/2023, 5:14 PMfamous-jewelry-85388
11/18/2023, 5:15 PMfew-area-98148
11/19/2023, 11:56 AMfamous-jewelry-85388
11/20/2023, 6:43 PMfew-area-98148
11/21/2023, 7:48 AMfamous-jewelry-85388
11/21/2023, 12:26 PMfew-area-98148
11/21/2023, 1:42 PMfew-area-98148
11/25/2023, 11:14 AM