-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbot1.js
72 lines (63 loc) · 2.99 KB
/
bot1.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
window.botpressWebChat.init({
'botName': 'Fin',
'composerPlaceholder': 'Enter text here',
'botConversationDescription': 'Credit Pull Search',
'botId': '0e38537e-381d-4e4a-9d27-9fab185f97dd',
'hostUrl': 'https://cdn.botpress.cloud/webchat/v0',
'messagingUrl': 'https://messaging.botpress.cloud',
'clientId': '0e38537e-381d-4e4a-9d27-9fab185f97dd',
'enableConversationDeletion': true,
'showPoweredBy': false,
'className': 'webchatIframe',
'containerWidth': '100%25',
'layoutWidth': '100%25',
'hideWidget': true,
'showCloseButton': false,
'useSessionStorage': true,
'disableAnimations': true,
'closeOnEscape': false,
'showConversationsButton': false,
'enableTranscriptDownload': false,
'stylesheet':'https://webchat-styler-css.botpress.app/prod/code/d6785494-e152-4680-9297-df47661401ab/v39687/style.css'
});
window.addEventListener('beforeunload', function() {
sessionStorage.clear();
localStorage.clear();
});
window.botpressWebChat.onEvent(function (event) {
if (event.type === 'LIFECYCLE.LOADED') {
console.log('LIFECYCLE.LOADED event triggered');
window.botpressWebChat.sendEvent({ type: 'show' });
setTimeout(function() {
window.botpressWebChat.sendPayload({
type: 'trigger',
payload: {
BID: 'Pull'
}
});
}, 1000);
} else if (event.type === 'MESSAGE.RECEIVED') {
console.log('MESSAGE.RECEIVED event received', event);
// Check for button choices
if (event.value.payload?.choices?.length > 0) {
console.log('choices detected');
window.botpressWebChat.mergeConfig({
stylesheet: 'https://webchat-styler-css.botpress.app/prod/code/d6785494-e152-4680-9297-df47661401ab/v39687/style.css'
});
// Check for a dropdown
} else if (event.value.payload?.type === 'dropdown') {
console.log('Dropdown message received');
window.botpressWebChat.mergeConfig({
stylesheet: 'https://webchat-styler-css.botpress.app/prod/code/d6785494-e152-4680-9297-df47661401ab/v39687/style.css'
});
// Add any specific handling for dropdown messages here
// Handle messages that are neither choices nor dropdown
} else {
console.log('No choices or dropdown detected');
window.botpressWebChat.mergeConfig({
stylesheet: 'https://webchat-styler-css.botpress.app/prod/code/2bfd2d3e-9830-442a-859c-0a69c2642bed/v50560/style.css'
});
}
}
}, ['LIFECYCLE.LOADED', 'MESSAGE.RECEIVED']);
console.log('Botpress Web Chat initialized');