-
Notifications
You must be signed in to change notification settings - Fork 1
/
indexv2_server.html
125 lines (124 loc) · 4.52 KB
/
indexv2_server.html
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
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
</head>
<body>
<div>
<script src="https://hml-bp-embedded-chatbot.lappis.rocks/assets/modules/channel-web/inject.js"></script>
<script type="module">
function checkCookie(name) {
return Cookies.get(name) !== undefined;
}
import Cookies from 'https://cdn.jsdelivr.net/npm/[email protected]/dist/js.cookie.min.mjs';
if(!checkCookie('webchatShown')){
Cookies.set('webchatShown', 'false');
}
if(!checkCookie('isThereConversation')){
Cookies.set('isThereConversation', 'false');
}
let encerrar = false;
window.botpressWebChat.init({
host: "https://hml-bp-embedded-chatbot.lappis.rocks",
botId: "chatbot_v2_17",
extraStylesheet: "https://hml-bp-embedded-chatbot.lappis.rocks/assets/modules/channel-web/style.css",
layoutWidth: "-",
showPoweredBy: false,
enableTranscriptDownload: false,
enableConversationDeletion: true,
enableReset: false,
showConversationsButton: false,
botName: "Brasil Participativo",
enablePersistHistory: false});
window.addEventListener('message', function(event) {
try{
if(event.data.payload){
if(event.data.payload.text == 'Encerrar atendimento'){
encerrar = true;
Cookies.set('isThereConversation', 'false');
}
}
} catch(error) {
}
if(event.data){
if(Object.keys(event.data).length == 3 && Object.keys(event.data).includes('conversationId') && Object.keys(event.data).includes('__room') && Object.keys(event.data).includes('chatId')){
Cookies.set('isThereConversation', 'false');
if(encerrar && Cookies.get('isThereConversation') == 'false'){
window.botpressWebChat.sendEvent(
{ type: 'createConversation' }
);
window.botpressWebChat.sendEvent({
type: 'proactive-trigger',
channel: 'web',
payload: { text: 'oi' }
});
Cookies.set('isThereConversation', 'true');
} else if(!encerrar && Cookies.get('isThereConversation') == 'false'){
console.log('entrou2');
window.botpressWebChat.sendEvent(
{ type: 'createConversation' }
);
window.botpressWebChat.sendEvent(
{ type: 'createConversation' }
);
window.botpressWebChat.sendEvent(
{ type: 'createConversation' }
);
window.botpressWebChat.sendEvent(
{ type: 'createConversation' }
);
window.botpressWebChat.sendEvent({
type: 'proactive-trigger',
channel: 'web',
payload: { text: 'oi' }
});
Cookies.set('isThereConversation', 'true');
}
encerrar = false;
}
}
async function initializeWebChat(){
if(Cookies.get('webchatShown') == 'false' && Cookies.get('isThereConversation') == 'false'){
document.getElementById('bp-widget').style.display = 'none';
Cookies.set('webchatShown', 'true');
window.botpressWebChat.sendEvent(
{ type: 'show' }
);
}
if (event.data && event.data.name === 'webchatReady' && Cookies.get('isThereConversation') == 'false') {
window.botpressWebChat.sendEvent(
{ type: 'createConversation' }
);
window.botpressWebChat.sendEvent({
type: 'proactive-trigger',
channel: 'web',
payload: { text: 'oi' }
});
window.botpressWebChat.sendEvent(
{ type: 'hide' }
);
Cookies.set('isThereConversation', 'true');
await new Promise(resolve => setTimeout(resolve, 1000));
document.getElementById('bp-widget').style.display = 'inline';
}
}
initializeWebChat();
if (event.data && event.data.name === 'webchatClosed' && encerrar) {
window.botpressWebChat.sendEvent(
{ type: 'createConversation' }
);
window.botpressWebChat.sendEvent({
type: 'proactive-trigger',
channel: 'web',
payload: { text: 'oi' }
});
Cookies.set('isThereConversation', 'true');
encerrar = false;
}
});
</script>
</div>
</body>
</html>