-
Notifications
You must be signed in to change notification settings - Fork 23
/
Copy pathindex.html
274 lines (248 loc) · 9.02 KB
/
index.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
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<meta http-equiv="X-UA-Compatible" content="ie=edge" />
<title>BlipChat widget</title>
</head>
<body>
<script
src="https://unpkg.com/blip-chat-widget@1.5.2"
type="text/javascript"
></script>
<div class="container">
<div class="column">
<div class="row">
<h1>BlipChat Sandbox</h1>
<p>Set your environment and app key</p>
<label for="app-key">App Key:</label>
<input type="text" id="app-key" name="app-key" />
<label for="environment">Environment:</label>
<input
type="text"
id="environment"
name="environment"
value="production"
/>
<p>Use buttons bellow to see different behaviours of BLiP Chat</p>
<button onclick="buildChat({authType:BlipChat.GUEST_AUTH})">
Build SDK as GUEST (Default)
</button>
<button onclick="buildChat({authType:BlipChat.DEV_AUTH})">
Build SDK as DEV
</button>
<button onclick="changeSDK()">Change SDK Template</button>
<button onclick="toogleChat()">Toogle open chat</button>
<button onclick="destroyChat()">Destroy SDK</button>
</div>
<div class="row">
<label for="test-message">Write bellow your test message:</label>
<textarea
id="test-message"
style="width: 100%; height: 100px;"
></textarea>
<button onclick="sendMessage()">Send test message</button>
<br />
<label for="test-command">Write bellow your test command:</label>
<textarea
id="test-command"
style="width: 100%; height: 100px;"
></textarea>
<button onclick="sendCommand()">Send test command</button>
</div>
<div class="row">
<h1>For authentication type DEV</h1>
<p>
Enter the name and email of the client (We will create a random
identifier and password for them)
</p>
<form>
Full Name: <input type="text" id="fullName" /> <br />
Email: <input type="text" id="email" /> <br />
Id: <input type="text" id="userId" value="testdevuser" /> <br />
Password: <input type="text" id="userPass" value="123456" /> <br />
</form>
</div>
<div class="row">
<h1>For connection data tests (*optional)</h1>
<p>
Enter with port, hostName and domain informations for BLiP
connection
</p>
<form>
Domain: <input type="text" id="domain" value="0mn.io" /> <br />
HostName: <input type="text" id="hostName" value="hmg-ws.0mn.io" />
<br />
Port: <input type="text" id="port" value="443" />
</form>
</div>
</div>
</div>
<div id="sdk-target" style="height:550px; width: 50%"></div>
<script>
var sendMessage
var destroyChat
var buildChat
var target
var builder
;(function() {
window.onload = function() {
toogleChat = function() {
builder.toogleChat()
}
sendMessage = function() {
let msgFieldValue
try {
msgFieldValue = JSON.parse(
document.getElementById('test-message').value
)
} catch (error) {
msgFieldValue = document.getElementById('test-message').value
}
builder.sendMessage(msgFieldValue)
}
sendCommand = function() {
try {
const command = JSON.parse(
document.getElementById('test-command').value
)
builder.sendCommand(command)
} catch (error) {
alert('Comando invalido')
}
}
destroyChat = function() {
builder.destroy()
builder = null
}
buildChat = function(authConfig) {
if (builder) {
destroyChat()
}
if (authConfig && authConfig.authType == BlipChat.DEV_AUTH) {
;(authConfig.userIdentity = document.getElementById('userId')
.value
? document.getElementById('userId').value
: '01684334-71c7-40e0-ad1a-5ce372de1a08'), // Required
(authConfig.userPassword = document.getElementById('userPass')
.value
? document.getElementById('userPass').value
: 'MjU2OWNmOTItYmRjZi00Njg0LTljZDktMWQxNjQxYmYxMGU1'), // Required
(authConfig.userName = document.getElementById('fullName').value
? document.getElementById('fullName').value
: ''), // Optional
(authConfig.userEmail = document.getElementById('email').value
? document.getElementById('email').value
: '') // Optional
}
const environment = document.getElementById('environment').value
? document.getElementById('environment').value
: 'homolog'
const appKey =
document.getElementById('app-key').value ||
'YmxpcHRlc3RjYXJkczo3YTcwZTUyNi04YzNjLTRmNGQtYWZjYi00ZWFmNzk5ZDFmNjk='
const connectionData = {
port: document.getElementById('port').value,
hostName: document.getElementById('hostName').value,
domain: document.getElementById('domain').value
}
const customStyle = `
body {
background: transparent;
}
#blip-chat-welcome-container {
background-color: transparent;
}
#blip-chat-welcome-container ~ #message-input {
display: none;
}
#blip-chat-header {
display: none;
}
#app {
padding-top: 0;
height: 100%;
background-color: transparent !important;
}
.blip-container {
margin-bottom: 0;
}
.blip-card-container, .blip-card .bubble {
font-size: 12px;
}
#message-input {
box-sizing: border-box;
border: 1px solid #0CC8CC;
border-radius: 6px;
background: #252B39;
}
#message-input textarea {
background: #252B39;
font-size: 12px;
color: white;
}
#message-input .message-options {
display: none;
}
`
builder = new BlipChat()
.withAppKey(appKey)
.withButton({
color: '#2f8413'
})
.withTarget(target)
.withEnvironment(environment)
.withConnectionData(connectionData)
.withAuth(authConfig)
.withAccount({
fullName: 'User name',
phoneNumber: '+15055034455',
email: 'test@test.com',
encryptMessageContent: true
})
.withCustomStyle(customStyle)
.withEventHandler(BlipChat.ENTER_EVENT, function() {
console.log('enter')
})
.withEventHandler(BlipChat.LEAVE_EVENT, function() {
console.log('leave')
})
.withEventHandler(BlipChat.LOAD_EVENT, function() {
console.log('chat loaded')
})
.withEventHandler(BlipChat.CREATE_ACCOUNT_EVENT, function() {
console.log('account created')
})
.withCustomMessageMetadata({
x: 'y'
})
.withCustomCommonUrl(
''
)
builder.build()
}
changeSDK = function() {
if (target) {
target = null
} else {
target = 'sdk-target'
}
buildChat()
}
applyValues = function() {
options.window.title = document.getElementById('title').value
options.window.iconPath = document.getElementById('iconPath').value
options.window.widgetColor = document.getElementById(
'widgetColor'
).value
options.window.hideMenu = !document.getElementsByName('hideMenu')[1]
.checked
buildChat(options.config.authType)
}
buildChat()
}
})()
</script>
</body>
</html>