@carbon/ai-chat 0.1.1-alpha5 → 0.1.1-react17
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/App.js +933 -55468
- package/dist/Carousel.js +1 -5705
- package/dist/Chat.js +1 -8339
- package/dist/GenesysMessengerServiceDesk.js +1 -579
- package/dist/HumanAgentServiceImpl.js +1 -1122
- package/dist/NiceDFOServiceDesk.js +2 -2097
- package/dist/PDFViewerContainer.js +2 -27439
- package/dist/SFServiceDesk.js +1 -1012
- package/dist/ServiceDeskImpl.js +1 -72
- package/dist/ZendeskServiceDesk.js +1 -649
- package/dist/_commonjsHelpers.js +1 -33
- package/dist/_node-resolve_empty.js +1 -25
- package/dist/agentActions.js +1 -187
- package/dist/aiChatEntry.js +1 -28
- package/dist/aiChatEntry2.js +4 -7022
- package/dist/anonymousUserIDStorage.js +2 -250
- package/dist/ar-dz.js +1 -55
- package/dist/ar-kw.js +1 -55
- package/dist/ar-ly.js +1 -55
- package/dist/ar-ma.js +1 -55
- package/dist/ar-sa.js +1 -55
- package/dist/ar-tn.js +1 -55
- package/dist/ar.js +1 -55
- package/dist/ar2.js +1 -470
- package/dist/cs.js +1 -55
- package/dist/cs2.js +1 -470
- package/dist/de-at.js +1 -55
- package/dist/de-ch.js +1 -55
- package/dist/de.js +1 -55
- package/dist/de2.js +1 -470
- package/dist/domUtils.js +2 -820
- package/dist/en-au.js +1 -55
- package/dist/en-ca.js +1 -55
- package/dist/en-gb.js +1 -55
- package/dist/en-ie.js +1 -55
- package/dist/en-il.js +1 -55
- package/dist/en-nz.js +1 -55
- package/dist/es-do.js +1 -55
- package/dist/es-us.js +1 -55
- package/dist/es.js +1 -55
- package/dist/es2.js +1 -470
- package/dist/export.js +1 -25
- package/dist/export.legacy.js +1 -25
- package/dist/fontUtils.js +1 -1036
- package/dist/fr-ca.js +1 -55
- package/dist/fr-ch.js +1 -55
- package/dist/fr.js +1 -55
- package/dist/fr2.js +1 -470
- package/dist/humanAgentUtils.js +1 -1393
- package/dist/it-ch.js +1 -55
- package/dist/it.js +1 -55
- package/dist/it2.js +1 -470
- package/dist/ja.js +1 -55
- package/dist/ja2.js +1 -470
- package/dist/jstz.min.js +1 -41
- package/dist/ko.js +1 -55
- package/dist/ko2.js +1 -470
- package/dist/messageUtils.js +1 -1338
- package/dist/mockServiceDesk.js +1 -851
- package/dist/moduleFederationPluginUtils.js +2 -5852
- package/dist/nl.js +1 -55
- package/dist/nl2.js +1 -470
- package/dist/pt-br.js +1 -55
- package/dist/pt-br2.js +1 -470
- package/dist/pt.js +1 -55
- package/dist/render.js +1 -88
- package/dist/web-components/cds-aichat-container/index.js +3 -3
- package/dist/web-components/cds-aichat-container/index.js.map +1 -1
- package/dist/web-components/cds-aichat-custom-element/index.js +2 -2
- package/dist/web-components/cds-aichat-custom-element/index.js.map +1 -1
- package/dist/zh-cn.js +1 -55
- package/dist/zh-tw.js +1 -55
- package/dist/zh-tw2.js +1 -470
- package/dist/zh.js +1 -470
- package/package.json +1 -1
package/dist/mockServiceDesk.js
CHANGED
|
@@ -1,851 +1 @@
|
|
|
1
|
-
/*
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
(C) Copyright IBM Corp. 2017, 2024. All Rights Reserved.
|
|
5
|
-
|
|
6
|
-
Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except
|
|
7
|
-
in compliance with the License. You may obtain a copy of the License at
|
|
8
|
-
|
|
9
|
-
http://www.apache.org/licenses/LICENSE-2.0
|
|
10
|
-
|
|
11
|
-
Unless required by applicable law or agreed to in writing, software distributed under the License
|
|
12
|
-
is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
|
|
13
|
-
or implied. See the License for the specific language governing permissions and limitations under
|
|
14
|
-
the License.
|
|
15
|
-
|
|
16
|
-
@carbon/ai-chat 0.1.1-alpha5
|
|
17
|
-
|
|
18
|
-
Built: Oct 24 2024 10:59 am -04:00
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
*/
|
|
23
|
-
import { j as createMessageResponseForText, ak as ErrorType, L as InternalMessageResponseType, a0 as ButtonItemKind, a2 as ButtonItemType } from './messageUtils.js';
|
|
24
|
-
import { n as sleep, a4 as assertType, p as MessageResponseTypes } from './aiChatEntry2.js';
|
|
25
|
-
import '@lit/react';
|
|
26
|
-
import 'react';
|
|
27
|
-
import 'lit';
|
|
28
|
-
import 'lit/decorators.js';
|
|
29
|
-
import 'react-dom';
|
|
30
|
-
|
|
31
|
-
/**
|
|
32
|
-
*
|
|
33
|
-
* IBM Confidential
|
|
34
|
-
*
|
|
35
|
-
* (C) Copyright IBM Corp. 2020, 2023
|
|
36
|
-
*
|
|
37
|
-
* The source code for this program is not published or otherwise
|
|
38
|
-
* divested of its trade secrets, irrespective of what has been
|
|
39
|
-
* deposited with the U. S. Copyright Office
|
|
40
|
-
*
|
|
41
|
-
* US Government Users Restricted Rights - Use, duplication or
|
|
42
|
-
* disclosure restricted by GSA ADP Schedule Contract with IBM Corp.
|
|
43
|
-
*
|
|
44
|
-
*/
|
|
45
|
-
var ConnectInfoType;
|
|
46
|
-
(function (ConnectInfoType) {
|
|
47
|
-
/**
|
|
48
|
-
* The connecting status will not show any information.
|
|
49
|
-
*/
|
|
50
|
-
ConnectInfoType[ConnectInfoType["NONE"] = 1] = "NONE";
|
|
51
|
-
/**
|
|
52
|
-
* The connecting status will show information about the user's position in a queue.
|
|
53
|
-
*/
|
|
54
|
-
ConnectInfoType[ConnectInfoType["LINE"] = 2] = "LINE";
|
|
55
|
-
/**
|
|
56
|
-
* The connecting status will show information about the wait time in minutes for the user.
|
|
57
|
-
*/
|
|
58
|
-
ConnectInfoType[ConnectInfoType["MINUTES"] = 3] = "MINUTES";
|
|
59
|
-
/**
|
|
60
|
-
* The connecting status will show a series of custom messages.
|
|
61
|
-
*/
|
|
62
|
-
ConnectInfoType[ConnectInfoType["MESSAGE"] = 4] = "MESSAGE";
|
|
63
|
-
/**
|
|
64
|
-
* Starting a chat will result in a connecting error {@link ErrorType.CONNECTING}.
|
|
65
|
-
*/
|
|
66
|
-
ConnectInfoType[ConnectInfoType["CONNECTING_ERROR"] = 5] = "CONNECTING_ERROR";
|
|
67
|
-
/**
|
|
68
|
-
* Starting a chat will just fail with the service desk throwing an error.
|
|
69
|
-
*/
|
|
70
|
-
ConnectInfoType[ConnectInfoType["THROW_ERROR"] = 6] = "THROW_ERROR";
|
|
71
|
-
})(ConnectInfoType || (ConnectInfoType = {}));
|
|
72
|
-
const HELLO_TEXT = (userName) => `Hi${userName ? ` ${userName}` : ''}, I'm Shepard! I'm a **mock** service desk agent. Type *"help"* to see a list of messages you can mock me with. <script>alert("If you see this, it is a serious bug!");</script>`;
|
|
73
|
-
const TEXT_LONG = 'The biggest problem that teams encounter when dealing with coding standards is the ' +
|
|
74
|
-
'variety of opinions on the subject or the introduction of new team members who are familiar with a' +
|
|
75
|
-
" different standard. The first point I would make to address this is that I don't believe that what" +
|
|
76
|
-
' exactly is in your coding standard is nearly as important as having a standard and using it consistently.' +
|
|
77
|
-
" It doesn't matter if you want braces to be on the following line or the same line as long as whatever you" +
|
|
78
|
-
' do is consistent.\n\nBut those who don\'t agree to a specific point are likely to feel that it\'s "wrong"' +
|
|
79
|
-
' and not just "different." Over my career I have worked on a lot of different projects with a wide range' +
|
|
80
|
-
' of coding standards and in my experience, it takes relatively little time to adopt a new standard once' +
|
|
81
|
-
' you\'ve set aside your resistance to it. You may feel that putting braces on the same line is "wrong"' +
|
|
82
|
-
' but I bet that if you try it, in just a few days you will begin to feel that the new style is "right"' +
|
|
83
|
-
' and it\'s now your old style that\'s "wrong".\n\nAs an example, I spent 20 years of my life believing that' +
|
|
84
|
-
' you were supposed to end a sentence with two spaces instead of one. Then one day I started to notice in ' +
|
|
85
|
-
'javadoc comments that other members of my team used just one. I decided to go look up the best practices for ' +
|
|
86
|
-
"this and concluded that the two spaces were outdated and it's now generally accepted to use just one. I made a " +
|
|
87
|
-
'few weak attempts to change but I just found it hard to switch a habit that I had had for so long. One day I ' +
|
|
88
|
-
'finally decided to practice what I preach and made a serious attempt to relegate that extra space to history ' +
|
|
89
|
-
'and sure enough, within a couple of days I no longer had any difficulty typing one space instead of two and in ' +
|
|
90
|
-
'not much time after that, I found myself occasionally noticing the two spaces in old code of mine and found that ' +
|
|
91
|
-
'it did indeed look odd now...\n\n' +
|
|
92
|
-
'[More](https://medium.com/@damon.lundin/on-coding-standards-4420e3fa281f)\n\n<script>alert("If you see this, it is a serious bug!")</script>';
|
|
93
|
-
const PROFILE_URL_PREFIX = 'https://web-chat.assistant.test.watson.cloud.ibm.com';
|
|
94
|
-
const MOCK_AGENT_PROFILE_SHEPARD = {
|
|
95
|
-
id: 'CommanderShepard-id',
|
|
96
|
-
nickname: 'Shepard',
|
|
97
|
-
profile_picture_url: `${PROFILE_URL_PREFIX}/assets/example_avatar_1.png`,
|
|
98
|
-
};
|
|
99
|
-
const MOCK_AGENT_PROFILE_GARRUS = {
|
|
100
|
-
id: 'GarrusVakarian-id',
|
|
101
|
-
nickname: 'Garrus',
|
|
102
|
-
profile_picture_url: `${PROFILE_URL_PREFIX}/assets/example_avatar_2.png`,
|
|
103
|
-
};
|
|
104
|
-
const MOCK_AGENT_PROFILE_LEGION = {
|
|
105
|
-
id: 'Legion-id',
|
|
106
|
-
nickname: 'Legion',
|
|
107
|
-
profile_picture_url: `${PROFILE_URL_PREFIX}/assets/example_avatar_missing.png`,
|
|
108
|
-
};
|
|
109
|
-
const MOCK_AGENT_PROFILE_EMPTY = {
|
|
110
|
-
id: null,
|
|
111
|
-
nickname: null,
|
|
112
|
-
};
|
|
113
|
-
// The agent we're currently talking to.
|
|
114
|
-
class MockServiceDesk {
|
|
115
|
-
constructor(parameters) {
|
|
116
|
-
/**
|
|
117
|
-
* The current internal state for the mock service desk. This object is exported by this module and these values may
|
|
118
|
-
* be controlled by external code.
|
|
119
|
-
*/
|
|
120
|
-
this.mockState = {
|
|
121
|
-
connectDelayFactor: 1,
|
|
122
|
-
connectInfoType: ConnectInfoType.LINE,
|
|
123
|
-
agentAvailabilityDelay: 0,
|
|
124
|
-
agentAvailability: true,
|
|
125
|
-
showStateChanges: false,
|
|
126
|
-
currentAgent: MOCK_AGENT_PROFILE_SHEPARD,
|
|
127
|
-
};
|
|
128
|
-
console.log('Creating MockServiceDesk');
|
|
129
|
-
this.factoryParameters = parameters;
|
|
130
|
-
this.chatInstance = parameters.instance;
|
|
131
|
-
this.callback = parameters.callback;
|
|
132
|
-
this.callback.updateCapabilities({
|
|
133
|
-
allowFileUploads: true,
|
|
134
|
-
allowedFileUploadTypes: 'image/*,.txt',
|
|
135
|
-
allowMultipleFileUploads: true,
|
|
136
|
-
});
|
|
137
|
-
}
|
|
138
|
-
getName() {
|
|
139
|
-
return 'wac mock service desk';
|
|
140
|
-
}
|
|
141
|
-
updateState(state) {
|
|
142
|
-
this.state = state;
|
|
143
|
-
if (this.hasStarted && this.mockState.showStateChanges) {
|
|
144
|
-
runSteps(this, STATE_CHANGED(state));
|
|
145
|
-
}
|
|
146
|
-
}
|
|
147
|
-
startChat(connectMessage, startChatOptions) {
|
|
148
|
-
console.log(`MockServiceDesk [startChat]: connectMessage`, connectMessage);
|
|
149
|
-
console.log(`MockServiceDesk [startChat]: startChatOptions`, startChatOptions);
|
|
150
|
-
this.preStartChatPayload = startChatOptions.preStartChatPayload || {};
|
|
151
|
-
if (this.mockState.connectInfoType === ConnectInfoType.CONNECTING_ERROR) {
|
|
152
|
-
return runSteps(this, START_CHAT_CONNECT_ERROR(this.mockState));
|
|
153
|
-
}
|
|
154
|
-
if (this.mockState.connectInfoType === ConnectInfoType.THROW_ERROR) {
|
|
155
|
-
throw new Error('The mock service desk threw an error during startChat!');
|
|
156
|
-
}
|
|
157
|
-
if (this.mockState.connectDelayFactor === 0) {
|
|
158
|
-
return runSteps(this, START_CHAT_IMMEDIATELY(this.preStartChatPayload.userName));
|
|
159
|
-
}
|
|
160
|
-
if (this.mockState.connectInfoType === ConnectInfoType.NONE) {
|
|
161
|
-
return runSteps(this, START_CHAT_NO_INFO(this.preStartChatPayload.userName, this.mockState));
|
|
162
|
-
}
|
|
163
|
-
this.hasStarted = true;
|
|
164
|
-
return runSteps(this, START_CHAT(this.preStartChatPayload.userName, this.mockState));
|
|
165
|
-
}
|
|
166
|
-
endChat(info) {
|
|
167
|
-
console.log(`MockServiceDesk [endChat]`, info);
|
|
168
|
-
let surveyResponse;
|
|
169
|
-
if (info.preEndChatPayload?.wasAgentHelpful === true) {
|
|
170
|
-
surveyResponse = 'We understand that you found the agent helpful. He will be given a cookie!';
|
|
171
|
-
}
|
|
172
|
-
else if (info.preEndChatPayload?.wasAgentHelpful === false) {
|
|
173
|
-
surveyResponse = 'We are sorry that the agent was not helpful. He will be reassigned to Siberia.';
|
|
174
|
-
}
|
|
175
|
-
if (surveyResponse) {
|
|
176
|
-
const text = `Thank you for responding to our survey. ${surveyResponse}`;
|
|
177
|
-
this.sendMessageToUser(createMessageResponseForText(text), this.mockState.currentAgent.id);
|
|
178
|
-
}
|
|
179
|
-
return Promise.resolve();
|
|
180
|
-
}
|
|
181
|
-
userTyping(isTyping) {
|
|
182
|
-
console.log(`MockServiceDesk [userTyping]: isTyping=${isTyping}`);
|
|
183
|
-
return Promise.resolve();
|
|
184
|
-
}
|
|
185
|
-
sendMessageToAgent(message, _messageID, additionalData) {
|
|
186
|
-
console.log(`MockServiceDesk [sendMessageToAgent]`, message, additionalData);
|
|
187
|
-
const { text } = message.input;
|
|
188
|
-
// Send a message back whenever we get a message from the user.
|
|
189
|
-
let steps;
|
|
190
|
-
if (!text) ;
|
|
191
|
-
else {
|
|
192
|
-
const textLower = text.toLowerCase();
|
|
193
|
-
if (textLower.includes('help')) {
|
|
194
|
-
steps = MESSAGE_TO_AGENT_HELP();
|
|
195
|
-
}
|
|
196
|
-
else if (textLower.includes('blank')) {
|
|
197
|
-
steps = null;
|
|
198
|
-
}
|
|
199
|
-
else if (textLower.includes('joke')) {
|
|
200
|
-
steps = MESSAGE_TO_AGENT_JOKE();
|
|
201
|
-
}
|
|
202
|
-
else if (textLower.includes('someone else')) {
|
|
203
|
-
if (this.mockState.currentAgent === MOCK_AGENT_PROFILE_SHEPARD ||
|
|
204
|
-
this.mockState.currentAgent === MOCK_AGENT_PROFILE_EMPTY) {
|
|
205
|
-
steps = TRANSFER_TO_GARRUS();
|
|
206
|
-
}
|
|
207
|
-
else if (this.mockState.currentAgent === MOCK_AGENT_PROFILE_GARRUS) {
|
|
208
|
-
steps = TRANSFER_TO_LEGION();
|
|
209
|
-
}
|
|
210
|
-
else {
|
|
211
|
-
steps = TRANSFER_TO_EMPTY();
|
|
212
|
-
}
|
|
213
|
-
}
|
|
214
|
-
else if (textLower.includes('text long')) {
|
|
215
|
-
steps = MESSAGE_TO_AGENT_TEXT(TEXT_LONG);
|
|
216
|
-
}
|
|
217
|
-
else if (textLower.includes('text medium')) {
|
|
218
|
-
steps = MESSAGE_TO_AGENT_TEXT("Thanks for being so interesting! I'm sure we're going to have a *wonderful* conversation. Let's get started...");
|
|
219
|
-
}
|
|
220
|
-
else if (textLower.includes('markdown')) {
|
|
221
|
-
steps = MESSAGE_TO_AGENT_TEXT(MARKDOWN);
|
|
222
|
-
}
|
|
223
|
-
else if (textLower.includes('multiple')) {
|
|
224
|
-
steps = MESSAGE_TO_AGENT_MULTIPLE();
|
|
225
|
-
}
|
|
226
|
-
else if (textLower.includes('hide')) {
|
|
227
|
-
steps = MESSAGE_TO_AGENT_TEXT('Session history will hide this message!');
|
|
228
|
-
}
|
|
229
|
-
else if (textLower.includes('secret')) {
|
|
230
|
-
steps = MESSAGE_TO_AGENT_TEXT("I'm afraid I don't know any secrets!");
|
|
231
|
-
}
|
|
232
|
-
else if (textLower.includes('version')) {
|
|
233
|
-
steps = MESSAGE_TO_AGENT_TEXT(`Web chat version: ${this.factoryParameters.instance.getWidgetVersion()}`);
|
|
234
|
-
}
|
|
235
|
-
else if (textLower.includes('intl')) {
|
|
236
|
-
const message = this.factoryParameters.instance.getIntl().formatMessage({ id: 'input_placeholder' });
|
|
237
|
-
steps = MESSAGE_TO_AGENT_TEXT(`Intl string (input_placeholder): *${message}*`);
|
|
238
|
-
}
|
|
239
|
-
else if (textLower.includes('leave')) {
|
|
240
|
-
steps = MESSAGE_TO_AGENT_LEAVE_CHAT();
|
|
241
|
-
}
|
|
242
|
-
else if (textLower.includes('text')) {
|
|
243
|
-
steps = MESSAGE_TO_AGENT_TEXT("TypeScript is awesome! I don't know how anyone can live without it. Seriously?!");
|
|
244
|
-
}
|
|
245
|
-
else if (textLower.includes('upload')) {
|
|
246
|
-
steps = MESSAGE_TO_AGENT_TEXT('Alright, you can upload some files. But only .png files please.', 0, false);
|
|
247
|
-
}
|
|
248
|
-
else if (textLower.includes('message throw')) {
|
|
249
|
-
steps = MESSAGE_THROW();
|
|
250
|
-
}
|
|
251
|
-
else if (textLower.includes('image')) {
|
|
252
|
-
steps = MESSAGE_IMAGE();
|
|
253
|
-
}
|
|
254
|
-
else if (textLower.includes('files')) {
|
|
255
|
-
steps = MESSAGE_FILES();
|
|
256
|
-
}
|
|
257
|
-
else if (textLower.includes('video')) {
|
|
258
|
-
steps = MESSAGE_VIDEO();
|
|
259
|
-
}
|
|
260
|
-
else if (textLower.includes('custom')) {
|
|
261
|
-
steps = MESSAGE_CUSTOM();
|
|
262
|
-
}
|
|
263
|
-
else if (textLower.includes('hang')) {
|
|
264
|
-
steps = HANG_MESSAGE();
|
|
265
|
-
}
|
|
266
|
-
else {
|
|
267
|
-
steps = MESSAGE_TO_AGENT_TEXT('If you say so. Type *"help"* for a list of other things you can say.');
|
|
268
|
-
}
|
|
269
|
-
}
|
|
270
|
-
// Handle any file uploads we may have.
|
|
271
|
-
if (additionalData.filesToUpload) {
|
|
272
|
-
additionalData.filesToUpload.forEach(file => {
|
|
273
|
-
// Use a setTimeout to simulate a random amount of time it takes to upload a file.
|
|
274
|
-
setTimeout(() => {
|
|
275
|
-
let errorMessage;
|
|
276
|
-
if (!file.file.name.endsWith('.png')) {
|
|
277
|
-
errorMessage = 'Only .png files may be uploaded.';
|
|
278
|
-
}
|
|
279
|
-
this.callback.setFileUploadStatus(file.id, Boolean(errorMessage), errorMessage);
|
|
280
|
-
}, Math.random() * 5000 + 1);
|
|
281
|
-
});
|
|
282
|
-
}
|
|
283
|
-
return runSteps(this, steps);
|
|
284
|
-
}
|
|
285
|
-
filesSelectedForUpload(uploads) {
|
|
286
|
-
console.log(`MockServiceDesk [filesSelectedForUpload]`, uploads);
|
|
287
|
-
uploads.forEach(file => {
|
|
288
|
-
if (file.file.name.toLowerCase().startsWith('a')) {
|
|
289
|
-
this.callback.setFileUploadStatus(file.id, true, 'You may not upload files that start with the letter "A"! Duh.');
|
|
290
|
-
}
|
|
291
|
-
});
|
|
292
|
-
}
|
|
293
|
-
userReadMessages() {
|
|
294
|
-
console.log(`MockServiceDesk [userReadMessages]`);
|
|
295
|
-
return Promise.resolve();
|
|
296
|
-
}
|
|
297
|
-
sendMessageToUser(message, agentID) {
|
|
298
|
-
// As soon as the agent sends a message, make sure to clear the "isTyping" event for the agent.
|
|
299
|
-
this.callback.agentTyping(false);
|
|
300
|
-
this.callback.sendMessageToUser(message, agentID);
|
|
301
|
-
}
|
|
302
|
-
async areAnyAgentsOnline() {
|
|
303
|
-
if (this.mockState.agentAvailabilityDelay) {
|
|
304
|
-
await sleep(this.mockState.agentAvailabilityDelay * 1000);
|
|
305
|
-
}
|
|
306
|
-
return this.mockState.agentAvailability;
|
|
307
|
-
}
|
|
308
|
-
async screenShareStop() {
|
|
309
|
-
this.callback.sendMessageToUser('Alright, you have stopped sharing your screen.', this.mockState.currentAgent.id);
|
|
310
|
-
}
|
|
311
|
-
async reconnect() {
|
|
312
|
-
await sleep(2000);
|
|
313
|
-
this.hasStarted = true;
|
|
314
|
-
return true;
|
|
315
|
-
}
|
|
316
|
-
}
|
|
317
|
-
/**
|
|
318
|
-
* This function will run a series of steps to simulate some interaction between the agent and a user.
|
|
319
|
-
*/
|
|
320
|
-
function runSteps(instance, steps) {
|
|
321
|
-
if (steps) {
|
|
322
|
-
let totalTime = 0;
|
|
323
|
-
steps.forEach(step => {
|
|
324
|
-
totalTime += step.delay || 0;
|
|
325
|
-
setTimeout(() => {
|
|
326
|
-
step.callback(instance);
|
|
327
|
-
}, totalTime);
|
|
328
|
-
});
|
|
329
|
-
const lastStep = steps[steps.length - 1];
|
|
330
|
-
// If the last step has some extra work to do in a Promise, then return that Promise. Otherwise, return a no-op.
|
|
331
|
-
return lastStep.returnPromise || Promise.resolve();
|
|
332
|
-
}
|
|
333
|
-
return Promise.resolve();
|
|
334
|
-
}
|
|
335
|
-
// Immediately start a chat with no delays.
|
|
336
|
-
function START_CHAT_IMMEDIATELY(userName) {
|
|
337
|
-
return [
|
|
338
|
-
{
|
|
339
|
-
delay: 0,
|
|
340
|
-
callback: (instance) => {
|
|
341
|
-
instance.mockState.currentAgent = MOCK_AGENT_PROFILE_SHEPARD;
|
|
342
|
-
instance.callback.agentJoined(MOCK_AGENT_PROFILE_SHEPARD);
|
|
343
|
-
instance.sendMessageToUser(HELLO_TEXT(userName), instance.mockState.currentAgent.id);
|
|
344
|
-
},
|
|
345
|
-
},
|
|
346
|
-
];
|
|
347
|
-
}
|
|
348
|
-
function START_CHAT_NO_INFO(userName, mockState) {
|
|
349
|
-
return [
|
|
350
|
-
{
|
|
351
|
-
delay: 1000 * mockState.connectDelayFactor,
|
|
352
|
-
callback: (instance) => {
|
|
353
|
-
mockState.currentAgent = MOCK_AGENT_PROFILE_SHEPARD;
|
|
354
|
-
instance.callback.agentJoined(MOCK_AGENT_PROFILE_SHEPARD);
|
|
355
|
-
},
|
|
356
|
-
},
|
|
357
|
-
{
|
|
358
|
-
delay: 1000,
|
|
359
|
-
callback: (instance) => {
|
|
360
|
-
instance.callback.agentTyping(true);
|
|
361
|
-
},
|
|
362
|
-
},
|
|
363
|
-
{
|
|
364
|
-
delay: 1000,
|
|
365
|
-
callback: (instance) => {
|
|
366
|
-
instance.sendMessageToUser(HELLO_TEXT(userName), MOCK_AGENT_PROFILE_SHEPARD.id);
|
|
367
|
-
},
|
|
368
|
-
},
|
|
369
|
-
];
|
|
370
|
-
}
|
|
371
|
-
function START_CHAT_CONNECT_ERROR(mockState) {
|
|
372
|
-
return [
|
|
373
|
-
{
|
|
374
|
-
delay: 1000 * mockState.connectDelayFactor,
|
|
375
|
-
callback: (instance) => {
|
|
376
|
-
mockState.currentAgent = MOCK_AGENT_PROFILE_SHEPARD;
|
|
377
|
-
instance.callback.setErrorStatus({
|
|
378
|
-
type: ErrorType.CONNECTING,
|
|
379
|
-
logInfo: 'Error!',
|
|
380
|
-
messageToUser: 'Apparently all our agents are taking naps',
|
|
381
|
-
});
|
|
382
|
-
},
|
|
383
|
-
},
|
|
384
|
-
];
|
|
385
|
-
}
|
|
386
|
-
// Starts a chat with a standard sequence of events with low delays on them.
|
|
387
|
-
function START_CHAT(userName, mockState) {
|
|
388
|
-
let availability;
|
|
389
|
-
switch (mockState?.connectInfoType) {
|
|
390
|
-
case ConnectInfoType.MESSAGE: {
|
|
391
|
-
availability = [
|
|
392
|
-
{ message: 'Agent getting on a *plane*...' },
|
|
393
|
-
{ message: 'Agent getting on a *train*...' },
|
|
394
|
-
{ message: 'Agent getting into a *car*...' },
|
|
395
|
-
];
|
|
396
|
-
break;
|
|
397
|
-
}
|
|
398
|
-
case ConnectInfoType.MINUTES: {
|
|
399
|
-
availability = [{ estimated_wait_time: 30 }, { estimated_wait_time: 2 }, { estimated_wait_time: 1 }];
|
|
400
|
-
break;
|
|
401
|
-
}
|
|
402
|
-
default: {
|
|
403
|
-
availability = [{ position_in_queue: 30 }, { position_in_queue: 2 }, { position_in_queue: 1 }];
|
|
404
|
-
break;
|
|
405
|
-
}
|
|
406
|
-
}
|
|
407
|
-
return [
|
|
408
|
-
{
|
|
409
|
-
delay: 1000,
|
|
410
|
-
callback: (instance) => {
|
|
411
|
-
instance.callback.updateAgentAvailability(availability[0]);
|
|
412
|
-
},
|
|
413
|
-
},
|
|
414
|
-
{
|
|
415
|
-
delay: 500 * mockState.connectDelayFactor,
|
|
416
|
-
callback: (instance) => {
|
|
417
|
-
instance.callback.updateAgentAvailability(availability[1]);
|
|
418
|
-
},
|
|
419
|
-
},
|
|
420
|
-
{
|
|
421
|
-
delay: 1000 * mockState.connectDelayFactor,
|
|
422
|
-
callback: (instance) => {
|
|
423
|
-
instance.callback.updateAgentAvailability(availability[2]);
|
|
424
|
-
},
|
|
425
|
-
},
|
|
426
|
-
{
|
|
427
|
-
delay: 1000,
|
|
428
|
-
callback: (instance) => {
|
|
429
|
-
mockState.currentAgent = MOCK_AGENT_PROFILE_SHEPARD;
|
|
430
|
-
instance.callback.agentJoined(MOCK_AGENT_PROFILE_SHEPARD);
|
|
431
|
-
},
|
|
432
|
-
},
|
|
433
|
-
{
|
|
434
|
-
delay: 1000,
|
|
435
|
-
callback: (instance) => {
|
|
436
|
-
instance.callback.agentTyping(true);
|
|
437
|
-
},
|
|
438
|
-
},
|
|
439
|
-
{
|
|
440
|
-
delay: 1000,
|
|
441
|
-
callback: (instance) => {
|
|
442
|
-
instance.sendMessageToUser(HELLO_TEXT(userName), mockState.currentAgent.id);
|
|
443
|
-
},
|
|
444
|
-
},
|
|
445
|
-
];
|
|
446
|
-
}
|
|
447
|
-
// Help messages
|
|
448
|
-
const HELP_TEXT = `You can send me the messages below to get a specific response from me.\n\n
|
|
449
|
-
**text**: I will say something pithy.
|
|
450
|
-
**text medium**: I will send you a few lines of text.
|
|
451
|
-
**text long**: I will bore you with a treatise on coding standards.
|
|
452
|
-
**joke**: I will tell you a joke with after a longer pause with multiple pauses in between messages.
|
|
453
|
-
**someone else**: I will transfer you to someone not as nice as I am.
|
|
454
|
-
**multiple**: I will output a response with multiple items in it.
|
|
455
|
-
**version**: I will output the version of web chat being used.
|
|
456
|
-
**intl**: I will output the current value for a translatable string.
|
|
457
|
-
**message throw**: This will throw an error while sending this message.
|
|
458
|
-
**hang**: The service desk will never respond to this message.
|
|
459
|
-
**leave**: I will leave the chat without ending it.
|
|
460
|
-
**hide**: I will send a message that should get hidden from session history.
|
|
461
|
-
**hide this message**: The user message should be hidden from session history.
|
|
462
|
-
**secret**: I will send you a message with the word "secret" in it.
|
|
463
|
-
**image**: I will insert an image response.
|
|
464
|
-
**files**: I will insert some file responses.
|
|
465
|
-
**video**: I will insert a video response.
|
|
466
|
-
**custom**: I will insert a custom response.
|
|
467
|
-
**markdown**: I will insert some markdown.`;
|
|
468
|
-
function MESSAGE_TO_AGENT_HELP() {
|
|
469
|
-
return [
|
|
470
|
-
{
|
|
471
|
-
delay: 0,
|
|
472
|
-
callback: (instance) => {
|
|
473
|
-
instance.sendMessageToUser('***These messages must be sent to an agent and not to the bot.***', instance.mockState.currentAgent.id);
|
|
474
|
-
instance.sendMessageToUser(HELP_TEXT, instance.mockState.currentAgent.id);
|
|
475
|
-
},
|
|
476
|
-
},
|
|
477
|
-
];
|
|
478
|
-
}
|
|
479
|
-
// A message to the agent to respond with some simple text.
|
|
480
|
-
function MESSAGE_TO_AGENT_TEXT(text, delay = 1000, showTyping = true) {
|
|
481
|
-
const steps = [];
|
|
482
|
-
if (showTyping) {
|
|
483
|
-
steps.push({
|
|
484
|
-
delay,
|
|
485
|
-
callback: (instance) => {
|
|
486
|
-
instance.callback.agentReadMessages();
|
|
487
|
-
instance.callback.agentTyping(true);
|
|
488
|
-
},
|
|
489
|
-
});
|
|
490
|
-
}
|
|
491
|
-
steps.push({
|
|
492
|
-
delay,
|
|
493
|
-
callback: (instance) => {
|
|
494
|
-
instance.sendMessageToUser(text, instance.mockState.currentAgent.id);
|
|
495
|
-
},
|
|
496
|
-
});
|
|
497
|
-
return steps;
|
|
498
|
-
}
|
|
499
|
-
// A response to talk to someone else.
|
|
500
|
-
function TRANSFER_TO_GARRUS() {
|
|
501
|
-
return [
|
|
502
|
-
{
|
|
503
|
-
delay: 1000,
|
|
504
|
-
callback: (instance) => {
|
|
505
|
-
instance.callback.agentReadMessages();
|
|
506
|
-
instance.callback.agentTyping(true);
|
|
507
|
-
},
|
|
508
|
-
},
|
|
509
|
-
{
|
|
510
|
-
delay: 1000,
|
|
511
|
-
callback: (instance) => {
|
|
512
|
-
instance.sendMessageToUser('Noooooo! I thought we were getting along so well!', instance.mockState.currentAgent.id);
|
|
513
|
-
},
|
|
514
|
-
},
|
|
515
|
-
{
|
|
516
|
-
delay: 500,
|
|
517
|
-
callback: (instance) => {
|
|
518
|
-
instance.callback.agentReadMessages();
|
|
519
|
-
instance.callback.agentTyping(true);
|
|
520
|
-
},
|
|
521
|
-
},
|
|
522
|
-
{
|
|
523
|
-
delay: 500,
|
|
524
|
-
callback: (instance) => {
|
|
525
|
-
instance.sendMessageToUser("Okay, I'll find **someone else** you can talk to.", instance.mockState.currentAgent.id);
|
|
526
|
-
},
|
|
527
|
-
},
|
|
528
|
-
{
|
|
529
|
-
delay: 1000,
|
|
530
|
-
callback: (instance) => {
|
|
531
|
-
instance.callback.beginTransferToAnotherAgent();
|
|
532
|
-
},
|
|
533
|
-
},
|
|
534
|
-
{
|
|
535
|
-
delay: 1000,
|
|
536
|
-
callback: (instance) => {
|
|
537
|
-
instance.mockState.currentAgent = MOCK_AGENT_PROFILE_GARRUS;
|
|
538
|
-
instance.callback.agentJoined(MOCK_AGENT_PROFILE_GARRUS);
|
|
539
|
-
},
|
|
540
|
-
},
|
|
541
|
-
{
|
|
542
|
-
delay: 1000,
|
|
543
|
-
callback: (instance) => {
|
|
544
|
-
instance.callback.agentReadMessages();
|
|
545
|
-
instance.callback.agentTyping(true);
|
|
546
|
-
},
|
|
547
|
-
},
|
|
548
|
-
{
|
|
549
|
-
delay: 500,
|
|
550
|
-
callback: (instance) => {
|
|
551
|
-
instance.sendMessageToUser("Hi! I'm **Garrus** and I'm nicer than **Shepard**!", instance.mockState.currentAgent.id);
|
|
552
|
-
},
|
|
553
|
-
},
|
|
554
|
-
];
|
|
555
|
-
}
|
|
556
|
-
// A response to talk to a third agent.
|
|
557
|
-
function TRANSFER_TO_LEGION() {
|
|
558
|
-
return [
|
|
559
|
-
{
|
|
560
|
-
delay: 0,
|
|
561
|
-
callback: (instance) => {
|
|
562
|
-
instance.sendMessageToUser("You'll regret this.", instance.mockState.currentAgent.id);
|
|
563
|
-
},
|
|
564
|
-
},
|
|
565
|
-
{
|
|
566
|
-
delay: 0,
|
|
567
|
-
callback: (instance) => {
|
|
568
|
-
instance.callback.agentReadMessages();
|
|
569
|
-
instance.callback.agentTyping(true);
|
|
570
|
-
},
|
|
571
|
-
},
|
|
572
|
-
{
|
|
573
|
-
delay: 1000,
|
|
574
|
-
callback: (instance) => {
|
|
575
|
-
instance.mockState.currentAgent = MOCK_AGENT_PROFILE_LEGION;
|
|
576
|
-
instance.callback.beginTransferToAnotherAgent(MOCK_AGENT_PROFILE_LEGION);
|
|
577
|
-
instance.callback.agentJoined(MOCK_AGENT_PROFILE_LEGION);
|
|
578
|
-
},
|
|
579
|
-
},
|
|
580
|
-
{
|
|
581
|
-
delay: 0,
|
|
582
|
-
callback: (instance) => {
|
|
583
|
-
instance.sendMessageToUser('Shepard-Commander.', instance.mockState.currentAgent.id);
|
|
584
|
-
},
|
|
585
|
-
},
|
|
586
|
-
];
|
|
587
|
-
}
|
|
588
|
-
// A response to trigger the agent leaving the chat.
|
|
589
|
-
function MESSAGE_TO_AGENT_LEAVE_CHAT() {
|
|
590
|
-
return [
|
|
591
|
-
{
|
|
592
|
-
delay: 0,
|
|
593
|
-
callback: (instance) => {
|
|
594
|
-
instance.sendMessageToUser('I am leaving now!', instance.mockState.currentAgent.id);
|
|
595
|
-
instance.callback.agentLeftChat();
|
|
596
|
-
},
|
|
597
|
-
},
|
|
598
|
-
];
|
|
599
|
-
}
|
|
600
|
-
// A response to talk to an agent with no name.
|
|
601
|
-
function TRANSFER_TO_EMPTY() {
|
|
602
|
-
return [
|
|
603
|
-
{
|
|
604
|
-
delay: 0,
|
|
605
|
-
callback: (instance) => {
|
|
606
|
-
instance.sendMessageToUser('Transferring you to a no-name.', instance.mockState.currentAgent.id);
|
|
607
|
-
instance.mockState.currentAgent = MOCK_AGENT_PROFILE_EMPTY;
|
|
608
|
-
instance.callback.agentJoined(MOCK_AGENT_PROFILE_EMPTY);
|
|
609
|
-
instance.sendMessageToUser('Hi.', instance.mockState.currentAgent.id);
|
|
610
|
-
},
|
|
611
|
-
},
|
|
612
|
-
];
|
|
613
|
-
}
|
|
614
|
-
// A message from the user that fails.
|
|
615
|
-
function MESSAGE_THROW() {
|
|
616
|
-
return [
|
|
617
|
-
{
|
|
618
|
-
delay: 0,
|
|
619
|
-
callback: () => { },
|
|
620
|
-
returnPromise: Promise.reject(),
|
|
621
|
-
},
|
|
622
|
-
];
|
|
623
|
-
}
|
|
624
|
-
function MESSAGE_IMAGE() {
|
|
625
|
-
return [
|
|
626
|
-
{
|
|
627
|
-
delay: 0,
|
|
628
|
-
callback: (instance) => {
|
|
629
|
-
const message = {
|
|
630
|
-
id: null,
|
|
631
|
-
output: {
|
|
632
|
-
generic: [
|
|
633
|
-
assertType({
|
|
634
|
-
response_type: MessageResponseTypes.IMAGE,
|
|
635
|
-
source: 'https://web-chat.global.assistant.test.watson.appdomain.cloud/assets/cat-1950632_1280.jpg',
|
|
636
|
-
title: 'Grump cat',
|
|
637
|
-
}),
|
|
638
|
-
],
|
|
639
|
-
},
|
|
640
|
-
};
|
|
641
|
-
instance.sendMessageToUser(message, instance.mockState.currentAgent.id);
|
|
642
|
-
},
|
|
643
|
-
},
|
|
644
|
-
];
|
|
645
|
-
}
|
|
646
|
-
function MESSAGE_FILES() {
|
|
647
|
-
return [
|
|
648
|
-
{
|
|
649
|
-
delay: 0,
|
|
650
|
-
callback: (instance) => {
|
|
651
|
-
const message = {
|
|
652
|
-
id: null,
|
|
653
|
-
output: {
|
|
654
|
-
generic: [
|
|
655
|
-
assertType({
|
|
656
|
-
response_type: InternalMessageResponseType.BUTTON,
|
|
657
|
-
kind: ButtonItemKind.LINK,
|
|
658
|
-
button_type: ButtonItemType.URL,
|
|
659
|
-
url: 'https://web-chat.global.assistant.test.watson.appdomain.cloud/assets/cat-1950632_1280.jpg',
|
|
660
|
-
label: 'Grump Cat.png',
|
|
661
|
-
target: '_blank',
|
|
662
|
-
}),
|
|
663
|
-
assertType({
|
|
664
|
-
response_type: InternalMessageResponseType.BUTTON,
|
|
665
|
-
kind: ButtonItemKind.LINK,
|
|
666
|
-
button_type: ButtonItemType.URL,
|
|
667
|
-
url: 'https://web-chat.global.assistant.test.watson.appdomain.cloud/assets/maine-coon-694730_1280.jpg',
|
|
668
|
-
target: '_blank',
|
|
669
|
-
}),
|
|
670
|
-
],
|
|
671
|
-
},
|
|
672
|
-
};
|
|
673
|
-
instance.sendMessageToUser(message, instance.mockState.currentAgent.id);
|
|
674
|
-
},
|
|
675
|
-
},
|
|
676
|
-
];
|
|
677
|
-
}
|
|
678
|
-
function MESSAGE_VIDEO() {
|
|
679
|
-
return [
|
|
680
|
-
{
|
|
681
|
-
delay: 0,
|
|
682
|
-
callback: (instance) => {
|
|
683
|
-
const message = {
|
|
684
|
-
id: null,
|
|
685
|
-
output: {
|
|
686
|
-
generic: [
|
|
687
|
-
assertType({
|
|
688
|
-
response_type: MessageResponseTypes.VIDEO,
|
|
689
|
-
title: 'The video title',
|
|
690
|
-
source: 'https://web-chat.global.assistant.test.watson.appdomain.cloud/assets/lake%20(720p).mp4',
|
|
691
|
-
alt_text: 'The video alternate text',
|
|
692
|
-
description: 'The video description',
|
|
693
|
-
}),
|
|
694
|
-
],
|
|
695
|
-
},
|
|
696
|
-
};
|
|
697
|
-
instance.sendMessageToUser(message, instance.mockState.currentAgent.id);
|
|
698
|
-
},
|
|
699
|
-
},
|
|
700
|
-
];
|
|
701
|
-
}
|
|
702
|
-
// A custom response.
|
|
703
|
-
function MESSAGE_CUSTOM() {
|
|
704
|
-
return [
|
|
705
|
-
{
|
|
706
|
-
delay: 0,
|
|
707
|
-
callback: (instance) => {
|
|
708
|
-
const message = {
|
|
709
|
-
id: null,
|
|
710
|
-
output: {
|
|
711
|
-
generic: [
|
|
712
|
-
assertType({
|
|
713
|
-
response_type: MessageResponseTypes.TEXT,
|
|
714
|
-
text: 'Below is a custom response but you may not see it if no handler has been created.',
|
|
715
|
-
}),
|
|
716
|
-
assertType({
|
|
717
|
-
response_type: MessageResponseTypes.USER_DEFINED,
|
|
718
|
-
user_defined: { user_defined_type: 'agent_custom' },
|
|
719
|
-
}),
|
|
720
|
-
],
|
|
721
|
-
},
|
|
722
|
-
};
|
|
723
|
-
instance.sendMessageToUser(message, instance.mockState.currentAgent.id);
|
|
724
|
-
},
|
|
725
|
-
},
|
|
726
|
-
];
|
|
727
|
-
}
|
|
728
|
-
function MESSAGE_TO_AGENT_MULTIPLE() {
|
|
729
|
-
return [
|
|
730
|
-
{
|
|
731
|
-
delay: 0,
|
|
732
|
-
callback: (instance) => {
|
|
733
|
-
const message = {
|
|
734
|
-
id: null,
|
|
735
|
-
output: {
|
|
736
|
-
generic: [
|
|
737
|
-
assertType({
|
|
738
|
-
response_type: MessageResponseTypes.TEXT,
|
|
739
|
-
text: 'This is a text item in this response.',
|
|
740
|
-
}),
|
|
741
|
-
assertType({
|
|
742
|
-
response_type: MessageResponseTypes.TEXT,
|
|
743
|
-
text: 'This is a second text item.',
|
|
744
|
-
}),
|
|
745
|
-
assertType({
|
|
746
|
-
response_type: MessageResponseTypes.IMAGE,
|
|
747
|
-
source: 'https://web-chat.global.assistant.test.watson.appdomain.cloud/assets/cat-1950632_1280.jpg',
|
|
748
|
-
}),
|
|
749
|
-
],
|
|
750
|
-
},
|
|
751
|
-
};
|
|
752
|
-
instance.sendMessageToUser(message, instance.mockState.currentAgent.id);
|
|
753
|
-
},
|
|
754
|
-
},
|
|
755
|
-
];
|
|
756
|
-
}
|
|
757
|
-
// A message from the user that hangs.
|
|
758
|
-
function HANG_MESSAGE() {
|
|
759
|
-
return [
|
|
760
|
-
{
|
|
761
|
-
delay: 0,
|
|
762
|
-
callback: () => { },
|
|
763
|
-
returnPromise: new Promise(() => { }),
|
|
764
|
-
},
|
|
765
|
-
];
|
|
766
|
-
}
|
|
767
|
-
// A response to a user asking for a joke.
|
|
768
|
-
function MESSAGE_TO_AGENT_JOKE() {
|
|
769
|
-
return [
|
|
770
|
-
{
|
|
771
|
-
delay: 1000,
|
|
772
|
-
callback: (instance) => {
|
|
773
|
-
instance.callback.agentReadMessages();
|
|
774
|
-
instance.callback.agentTyping(true);
|
|
775
|
-
},
|
|
776
|
-
},
|
|
777
|
-
{
|
|
778
|
-
delay: 5000,
|
|
779
|
-
callback: (instance) => {
|
|
780
|
-
instance.sendMessageToUser("One atom says to another atom: I think I've lost an electron.", instance.mockState.currentAgent.id);
|
|
781
|
-
},
|
|
782
|
-
},
|
|
783
|
-
{
|
|
784
|
-
delay: 2000,
|
|
785
|
-
callback: (instance) => {
|
|
786
|
-
instance.sendMessageToUser('The second atom says: are you sure?', instance.mockState.currentAgent.id);
|
|
787
|
-
},
|
|
788
|
-
},
|
|
789
|
-
{
|
|
790
|
-
delay: 2000,
|
|
791
|
-
callback: (instance) => {
|
|
792
|
-
instance.sendMessageToUser("The first atom says: I'm positive.", instance.mockState.currentAgent.id);
|
|
793
|
-
},
|
|
794
|
-
},
|
|
795
|
-
];
|
|
796
|
-
}
|
|
797
|
-
// A message from the user that fails.
|
|
798
|
-
function STATE_CHANGED(state) {
|
|
799
|
-
return [
|
|
800
|
-
{
|
|
801
|
-
delay: 0,
|
|
802
|
-
callback: (instance) => {
|
|
803
|
-
instance.sendMessageToUser(`The web chat state has changed: ${JSON.stringify(state)}`, instance.mockState.currentAgent.id);
|
|
804
|
-
},
|
|
805
|
-
},
|
|
806
|
-
];
|
|
807
|
-
}
|
|
808
|
-
const FENCE_BLOCK = `
|
|
809
|
-
\`\`\`
|
|
810
|
-
const example = {
|
|
811
|
-
value: true,
|
|
812
|
-
};
|
|
813
|
-
\`\`\`
|
|
814
|
-
`;
|
|
815
|
-
// Note, blockquote is not supported. Our HTML sanitization turns the ">" into ">" which prevents the markdown
|
|
816
|
-
// library from turning it into a blockquote.
|
|
817
|
-
const MARKDOWN = `
|
|
818
|
-
This is **bold**, ***bold and italics***, **bold *italics inside***, *italics **bold inside***, and ~~strikethrough~~.
|
|
819
|
-
|
|
820
|
-
# H1
|
|
821
|
-
H1 Text
|
|
822
|
-
## H2
|
|
823
|
-
H2 Text
|
|
824
|
-
|
|
825
|
-
1. Ordered List 1
|
|
826
|
-
2. Ordered List 2
|
|
827
|
-
|
|
828
|
-
- Unordered List 1
|
|
829
|
-
- Unordered List 2
|
|
830
|
-
|
|
831
|
-
\`Inline code\`
|
|
832
|
-
|
|
833
|
-
${FENCE_BLOCK}
|
|
834
|
-
|
|
835
|
-
| Header 1 | Header 2 |
|
|
836
|
-
| ----------- | ----------- |
|
|
837
|
-
| Text 1 | Text 2 |
|
|
838
|
-
| Text 3 | Text 4 |
|
|
839
|
-
|
|
840
|
-
---
|
|
841
|
-
|
|
842
|
-
[IBM's HomePage 1 (new tab)](https://ibm.com)
|
|
843
|
-
|
|
844
|
-
[IBM's HomePage 1 (same tab)](https://ibm.com){{target=_self}}
|
|
845
|
-
|
|
846
|
-
ibm.com (autolink, new tab)
|
|
847
|
-
|
|
848
|
-

|
|
849
|
-
`;
|
|
850
|
-
|
|
851
|
-
export { ConnectInfoType, MARKDOWN, MESSAGE_CUSTOM, MESSAGE_FILES, MESSAGE_IMAGE, MESSAGE_TO_AGENT_MULTIPLE, MESSAGE_TO_AGENT_TEXT, MESSAGE_VIDEO, MOCK_AGENT_PROFILE_EMPTY, MOCK_AGENT_PROFILE_GARRUS, MOCK_AGENT_PROFILE_LEGION, MOCK_AGENT_PROFILE_SHEPARD, MockServiceDesk, TEXT_LONG, runSteps };
|
|
1
|
+
import{j as e,ak as t,L as a,a0 as s,a2 as n}from"./messageUtils.js";import{n as o,a4 as i,p as l}from"./aiChatEntry2.js";import"@lit/react";import"react";import"lit";import"lit/decorators.js";import"react-dom";var r;!function(e){e[e.NONE=1]="NONE",e[e.LINE=2]="LINE",e[e.MINUTES=3]="MINUTES",e[e.MESSAGE=4]="MESSAGE",e[e.CONNECTING_ERROR=5]="CONNECTING_ERROR",e[e.THROW_ERROR=6]="THROW_ERROR"}(r||(r={}));const c=e=>`Hi${e?` ${e}`:""}, I'm Shepard! I'm a **mock** service desk agent. Type *"help"* to see a list of messages you can mock me with. <script>alert("If you see this, it is a serious bug!");<\/script>`,d='The biggest problem that teams encounter when dealing with coding standards is the variety of opinions on the subject or the introduction of new team members who are familiar with a different standard. The first point I would make to address this is that I don\'t believe that what exactly is in your coding standard is nearly as important as having a standard and using it consistently. It doesn\'t matter if you want braces to be on the following line or the same line as long as whatever you do is consistent.\n\nBut those who don\'t agree to a specific point are likely to feel that it\'s "wrong" and not just "different." Over my career I have worked on a lot of different projects with a wide range of coding standards and in my experience, it takes relatively little time to adopt a new standard once you\'ve set aside your resistance to it. You may feel that putting braces on the same line is "wrong" but I bet that if you try it, in just a few days you will begin to feel that the new style is "right" and it\'s now your old style that\'s "wrong".\n\nAs an example, I spent 20 years of my life believing that you were supposed to end a sentence with two spaces instead of one. Then one day I started to notice in javadoc comments that other members of my team used just one. I decided to go look up the best practices for this and concluded that the two spaces were outdated and it\'s now generally accepted to use just one. I made a few weak attempts to change but I just found it hard to switch a habit that I had had for so long. One day I finally decided to practice what I preach and made a serious attempt to relegate that extra space to history and sure enough, within a couple of days I no longer had any difficulty typing one space instead of two and in not much time after that, I found myself occasionally noticing the two spaces in old code of mine and found that it did indeed look odd now...\n\n[More](https://medium.com/@damon.lundin/on-coding-standards-4420e3fa281f)\n\n<script>alert("If you see this, it is a serious bug!")<\/script>',u="https://web-chat.assistant.test.watson.cloud.ibm.com",g={id:"CommanderShepard-id",nickname:"Shepard",profile_picture_url:`${u}/assets/example_avatar_1.png`},h={id:"GarrusVakarian-id",nickname:"Garrus",profile_picture_url:`${u}/assets/example_avatar_2.png`},m={id:"Legion-id",nickname:"Legion",profile_picture_url:`${u}/assets/example_avatar_missing.png`},p={id:null,nickname:null};class y{constructor(e){this.mockState={connectDelayFactor:1,connectInfoType:r.LINE,agentAvailabilityDelay:0,agentAvailability:!0,showStateChanges:!1,currentAgent:g},console.log("Creating MockServiceDesk"),this.factoryParameters=e,this.chatInstance=e.instance,this.callback=e.callback,this.callback.updateCapabilities({allowFileUploads:!0,allowedFileUploadTypes:"image/*,.txt",allowMultipleFileUploads:!0})}getName(){return"wac mock service desk"}updateState(e){this.state=e,this.hasStarted&&this.mockState.showStateChanges&&k(this,function(e){return[{delay:0,callback:t=>{t.sendMessageToUser(`The web chat state has changed: ${JSON.stringify(e)}`,t.mockState.currentAgent.id)}}]}(e))}startChat(e,a){if(console.log("MockServiceDesk [startChat]: connectMessage",e),console.log("MockServiceDesk [startChat]: startChatOptions",a),this.preStartChatPayload=a.preStartChatPayload||{},this.mockState.connectInfoType===r.CONNECTING_ERROR)return k(this,[{delay:1e3*(s=this.mockState).connectDelayFactor,callback:e=>{s.currentAgent=g,e.callback.setErrorStatus({type:t.CONNECTING,logInfo:"Error!",messageToUser:"Apparently all our agents are taking naps"})}}]);var s,n;if(this.mockState.connectInfoType===r.THROW_ERROR)throw new Error("The mock service desk threw an error during startChat!");return 0===this.mockState.connectDelayFactor?k(this,(n=this.preStartChatPayload.userName,[{delay:0,callback:e=>{e.mockState.currentAgent=g,e.callback.agentJoined(g),e.sendMessageToUser(c(n),e.mockState.currentAgent.id)}}])):this.mockState.connectInfoType===r.NONE?k(this,function(e,t){return[{delay:1e3*t.connectDelayFactor,callback:e=>{t.currentAgent=g,e.callback.agentJoined(g)}},{delay:1e3,callback:e=>{e.callback.agentTyping(!0)}},{delay:1e3,callback:t=>{t.sendMessageToUser(c(e),g.id)}}]}(this.preStartChatPayload.userName,this.mockState)):(this.hasStarted=!0,k(this,function(e,t){let a;switch(t?.connectInfoType){case r.MESSAGE:a=[{message:"Agent getting on a *plane*..."},{message:"Agent getting on a *train*..."},{message:"Agent getting into a *car*..."}];break;case r.MINUTES:a=[{estimated_wait_time:30},{estimated_wait_time:2},{estimated_wait_time:1}];break;default:a=[{position_in_queue:30},{position_in_queue:2},{position_in_queue:1}]}return[{delay:1e3,callback:e=>{e.callback.updateAgentAvailability(a[0])}},{delay:500*t.connectDelayFactor,callback:e=>{e.callback.updateAgentAvailability(a[1])}},{delay:1e3*t.connectDelayFactor,callback:e=>{e.callback.updateAgentAvailability(a[2])}},{delay:1e3,callback:e=>{t.currentAgent=g,e.callback.agentJoined(g)}},{delay:1e3,callback:e=>{e.callback.agentTyping(!0)}},{delay:1e3,callback:a=>{a.sendMessageToUser(c(e),t.currentAgent.id)}}]}(this.preStartChatPayload.userName,this.mockState)))}endChat(t){let a;if(console.log("MockServiceDesk [endChat]",t),!0===t.preEndChatPayload?.wasAgentHelpful?a="We understand that you found the agent helpful. He will be given a cookie!":!1===t.preEndChatPayload?.wasAgentHelpful&&(a="We are sorry that the agent was not helpful. He will be reassigned to Siberia."),a){const t=`Thank you for responding to our survey. ${a}`;this.sendMessageToUser(e(t),this.mockState.currentAgent.id)}return Promise.resolve()}userTyping(e){return console.log(`MockServiceDesk [userTyping]: isTyping=${e}`),Promise.resolve()}sendMessageToAgent(e,t,a){console.log("MockServiceDesk [sendMessageToAgent]",e,a);const{text:s}=e.input;let n;if(s){const e=s.toLowerCase();if(e.includes("help"))n=[{delay:0,callback:e=>{e.sendMessageToUser("***These messages must be sent to an agent and not to the bot.***",e.mockState.currentAgent.id),e.sendMessageToUser(b,e.mockState.currentAgent.id)}}];else if(e.includes("blank"))n=null;else if(e.includes("joke"))n=[{delay:1e3,callback:e=>{e.callback.agentReadMessages(),e.callback.agentTyping(!0)}},{delay:5e3,callback:e=>{e.sendMessageToUser("One atom says to another atom: I think I've lost an electron.",e.mockState.currentAgent.id)}},{delay:2e3,callback:e=>{e.sendMessageToUser("The second atom says: are you sure?",e.mockState.currentAgent.id)}},{delay:2e3,callback:e=>{e.sendMessageToUser("The first atom says: I'm positive.",e.mockState.currentAgent.id)}}];else if(e.includes("someone else"))n=this.mockState.currentAgent===g||this.mockState.currentAgent===p?[{delay:1e3,callback:e=>{e.callback.agentReadMessages(),e.callback.agentTyping(!0)}},{delay:1e3,callback:e=>{e.sendMessageToUser("Noooooo! I thought we were getting along so well!",e.mockState.currentAgent.id)}},{delay:500,callback:e=>{e.callback.agentReadMessages(),e.callback.agentTyping(!0)}},{delay:500,callback:e=>{e.sendMessageToUser("Okay, I'll find **someone else** you can talk to.",e.mockState.currentAgent.id)}},{delay:1e3,callback:e=>{e.callback.beginTransferToAnotherAgent()}},{delay:1e3,callback:e=>{e.mockState.currentAgent=h,e.callback.agentJoined(h)}},{delay:1e3,callback:e=>{e.callback.agentReadMessages(),e.callback.agentTyping(!0)}},{delay:500,callback:e=>{e.sendMessageToUser("Hi! I'm **Garrus** and I'm nicer than **Shepard**!",e.mockState.currentAgent.id)}}]:this.mockState.currentAgent===h?[{delay:0,callback:e=>{e.sendMessageToUser("You'll regret this.",e.mockState.currentAgent.id)}},{delay:0,callback:e=>{e.callback.agentReadMessages(),e.callback.agentTyping(!0)}},{delay:1e3,callback:e=>{e.mockState.currentAgent=m,e.callback.beginTransferToAnotherAgent(m),e.callback.agentJoined(m)}},{delay:0,callback:e=>{e.sendMessageToUser("Shepard-Commander.",e.mockState.currentAgent.id)}}]:[{delay:0,callback:e=>{e.sendMessageToUser("Transferring you to a no-name.",e.mockState.currentAgent.id),e.mockState.currentAgent=p,e.callback.agentJoined(p),e.sendMessageToUser("Hi.",e.mockState.currentAgent.id)}}];else if(e.includes("text long"))n=f(d);else if(e.includes("text medium"))n=f("Thanks for being so interesting! I'm sure we're going to have a *wonderful* conversation. Let's get started...");else if(e.includes("markdown"))n=f(v);else if(e.includes("multiple"))n=A();else if(e.includes("hide"))n=f("Session history will hide this message!");else if(e.includes("secret"))n=f("I'm afraid I don't know any secrets!");else if(e.includes("version"))n=f(`Web chat version: ${this.factoryParameters.instance.getWidgetVersion()}`);else if(e.includes("intl")){n=f(`Intl string (input_placeholder): *${this.factoryParameters.instance.getIntl().formatMessage({id:"input_placeholder"})}*`)}else n=e.includes("leave")?[{delay:0,callback:e=>{e.sendMessageToUser("I am leaving now!",e.mockState.currentAgent.id),e.callback.agentLeftChat()}}]:e.includes("text")?f("TypeScript is awesome! I don't know how anyone can live without it. Seriously?!"):e.includes("upload")?f("Alright, you can upload some files. But only .png files please.",0,!1):e.includes("message throw")?[{delay:0,callback:()=>{},returnPromise:Promise.reject()}]:e.includes("image")?w():e.includes("files")?T():e.includes("video")?S():e.includes("custom")?I():e.includes("hang")?[{delay:0,callback:()=>{},returnPromise:new Promise((()=>{}))}]:f('If you say so. Type *"help"* for a list of other things you can say.')}else;return a.filesToUpload&&a.filesToUpload.forEach((e=>{setTimeout((()=>{let t;e.file.name.endsWith(".png")||(t="Only .png files may be uploaded."),this.callback.setFileUploadStatus(e.id,Boolean(t),t)}),5e3*Math.random()+1)})),k(this,n)}filesSelectedForUpload(e){console.log("MockServiceDesk [filesSelectedForUpload]",e),e.forEach((e=>{e.file.name.toLowerCase().startsWith("a")&&this.callback.setFileUploadStatus(e.id,!0,'You may not upload files that start with the letter "A"! Duh.')}))}userReadMessages(){return console.log("MockServiceDesk [userReadMessages]"),Promise.resolve()}sendMessageToUser(e,t){this.callback.agentTyping(!1),this.callback.sendMessageToUser(e,t)}async areAnyAgentsOnline(){return this.mockState.agentAvailabilityDelay&&await o(1e3*this.mockState.agentAvailabilityDelay),this.mockState.agentAvailability}async screenShareStop(){this.callback.sendMessageToUser("Alright, you have stopped sharing your screen.",this.mockState.currentAgent.id)}async reconnect(){return await o(2e3),this.hasStarted=!0,!0}}function k(e,t){if(t){let a=0;t.forEach((t=>{a+=t.delay||0,setTimeout((()=>{t.callback(e)}),a)}));return t[t.length-1].returnPromise||Promise.resolve()}return Promise.resolve()}const b='You can send me the messages below to get a specific response from me.\n\n\n**text**: I will say something pithy.\n**text medium**: I will send you a few lines of text.\n**text long**: I will bore you with a treatise on coding standards.\n**joke**: I will tell you a joke with after a longer pause with multiple pauses in between messages.\n**someone else**: I will transfer you to someone not as nice as I am.\n**multiple**: I will output a response with multiple items in it.\n**version**: I will output the version of web chat being used.\n**intl**: I will output the current value for a translatable string.\n**message throw**: This will throw an error while sending this message.\n**hang**: The service desk will never respond to this message.\n**leave**: I will leave the chat without ending it.\n**hide**: I will send a message that should get hidden from session history.\n**hide this message**: The user message should be hidden from session history.\n**secret**: I will send you a message with the word "secret" in it.\n**image**: I will insert an image response.\n**files**: I will insert some file responses.\n**video**: I will insert a video response.\n**custom**: I will insert a custom response.\n**markdown**: I will insert some markdown.';function f(e,t=1e3,a=!0){const s=[];return a&&s.push({delay:t,callback:e=>{e.callback.agentReadMessages(),e.callback.agentTyping(!0)}}),s.push({delay:t,callback:t=>{t.sendMessageToUser(e,t.mockState.currentAgent.id)}}),s}function w(){return[{delay:0,callback:e=>{const t={id:null,output:{generic:[i({response_type:l.IMAGE,source:"https://web-chat.global.assistant.test.watson.appdomain.cloud/assets/cat-1950632_1280.jpg",title:"Grump cat"})]}};e.sendMessageToUser(t,e.mockState.currentAgent.id)}}]}function T(){return[{delay:0,callback:e=>{const t={id:null,output:{generic:[i({response_type:a.BUTTON,kind:s.LINK,button_type:n.URL,url:"https://web-chat.global.assistant.test.watson.appdomain.cloud/assets/cat-1950632_1280.jpg",label:"Grump Cat.png",target:"_blank"}),i({response_type:a.BUTTON,kind:s.LINK,button_type:n.URL,url:"https://web-chat.global.assistant.test.watson.appdomain.cloud/assets/maine-coon-694730_1280.jpg",target:"_blank"})]}};e.sendMessageToUser(t,e.mockState.currentAgent.id)}}]}function S(){return[{delay:0,callback:e=>{const t={id:null,output:{generic:[i({response_type:l.VIDEO,title:"The video title",source:"https://web-chat.global.assistant.test.watson.appdomain.cloud/assets/lake%20(720p).mp4",alt_text:"The video alternate text",description:"The video description"})]}};e.sendMessageToUser(t,e.mockState.currentAgent.id)}}]}function I(){return[{delay:0,callback:e=>{const t={id:null,output:{generic:[i({response_type:l.TEXT,text:"Below is a custom response but you may not see it if no handler has been created."}),i({response_type:l.USER_DEFINED,user_defined:{user_defined_type:"agent_custom"}})]}};e.sendMessageToUser(t,e.mockState.currentAgent.id)}}]}function A(){return[{delay:0,callback:e=>{const t={id:null,output:{generic:[i({response_type:l.TEXT,text:"This is a text item in this response."}),i({response_type:l.TEXT,text:"This is a second text item."}),i({response_type:l.IMAGE,source:"https://web-chat.global.assistant.test.watson.appdomain.cloud/assets/cat-1950632_1280.jpg"})]}};e.sendMessageToUser(t,e.mockState.currentAgent.id)}}]}const v="\nThis is **bold**, ***bold and italics***, **bold *italics inside***, *italics **bold inside***, and ~~strikethrough~~.\n\n# H1\nH1 Text\n## H2\nH2 Text\n\n1. Ordered List 1 \n2. Ordered List 2 \n\n- Unordered List 1 \n- Unordered List 2\n\n`Inline code`\n\n\n```\nconst example = {\n value: true,\n};\n```\n\n\n| Header 1 | Header 2 |\n| ----------- | ----------- |\n| Text 1 | Text 2 |\n| Text 3 | Text 4 |\n\n---\n\n[IBM's HomePage 1 (new tab)](https://ibm.com)\n\n[IBM's HomePage 1 (same tab)](https://ibm.com){{target=_self}}\n\nibm.com (autolink, new tab)\n\n\n";export{r as ConnectInfoType,v as MARKDOWN,I as MESSAGE_CUSTOM,T as MESSAGE_FILES,w as MESSAGE_IMAGE,A as MESSAGE_TO_AGENT_MULTIPLE,f as MESSAGE_TO_AGENT_TEXT,S as MESSAGE_VIDEO,p as MOCK_AGENT_PROFILE_EMPTY,h as MOCK_AGENT_PROFILE_GARRUS,m as MOCK_AGENT_PROFILE_LEGION,g as MOCK_AGENT_PROFILE_SHEPARD,y as MockServiceDesk,d as TEXT_LONG,k as runSteps};
|