@sprucelabs/spruce-conversation-plugin 45.2.9 → 46.0.0

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.
Files changed (123) hide show
  1. package/build/__tests__/behavioral/CheckingHealth.test.d.ts +10 -0
  2. package/build/__tests__/behavioral/CheckingHealth.test.js +87 -0
  3. package/build/__tests__/behavioral/KillingASkill.test.d.ts +4 -0
  4. package/build/__tests__/behavioral/KillingASkill.test.js +27 -0
  5. package/build/__tests__/behavioral/RegisteringConversationsOnBoot.test.d.ts +11 -0
  6. package/build/__tests__/behavioral/RegisteringConversationsOnBoot.test.js +106 -0
  7. package/build/__tests__/behavioral/RespondingToMessages.test.d.ts +13 -0
  8. package/build/__tests__/behavioral/RespondingToMessages.test.js +139 -0
  9. package/build/__tests__/behavioral/TestingAConversation.test.d.ts +10 -0
  10. package/build/__tests__/behavioral/TestingAConversation.test.js +70 -0
  11. package/build/__tests__/implementation/ConversationCoordinator.test.d.ts +15 -0
  12. package/build/__tests__/implementation/ConversationCoordinator.test.js +142 -0
  13. package/build/__tests__/implementation/MessageGraphicsInterface/EmailField.test.d.ts +7 -0
  14. package/build/__tests__/implementation/MessageGraphicsInterface/EmailField.test.js +71 -0
  15. package/build/__tests__/implementation/MessageGraphicsInterface/MessageGraphicsInterface.test.d.ts +4 -0
  16. package/build/__tests__/implementation/MessageGraphicsInterface/MessageGraphicsInterface.test.js +42 -0
  17. package/build/__tests__/implementation/MessageGraphicsInterface/SelectField.test.d.ts +7 -0
  18. package/build/__tests__/implementation/MessageGraphicsInterface/SelectField.test.js +71 -0
  19. package/build/__tests__/implementation/MessageGraphicsInterface/TextField.test.d.ts +6 -0
  20. package/build/__tests__/implementation/MessageGraphicsInterface/TextField.test.js +46 -0
  21. package/build/__tests__/implementation/ScriptTester.test.d.ts +18 -0
  22. package/build/__tests__/implementation/ScriptTester.test.js +459 -0
  23. package/build/__tests__/implementation/SuggesterUtil.test.d.ts +7 -0
  24. package/build/__tests__/implementation/SuggesterUtil.test.js +63 -0
  25. package/build/__tests__/implementation/TopicLoader.test.d.ts +8 -0
  26. package/build/__tests__/implementation/TopicLoader.test.js +66 -0
  27. package/build/__tests__/implementation/TopicScriptPlayer.test.d.ts +21 -0
  28. package/build/__tests__/implementation/TopicScriptPlayer.test.js +413 -0
  29. package/build/__tests__/implementation/TopicSuggester.test.d.ts +8 -0
  30. package/build/__tests__/implementation/TopicSuggester.test.js +131 -0
  31. package/build/__tests__/testDirsAndFiles/bad-empty/conversations/bookAppointment.topic.d.ts +0 -0
  32. package/build/__tests__/testDirsAndFiles/bad-empty/conversations/bookAppointment.topic.js +1 -0
  33. package/build/__tests__/testDirsAndFiles/bad-missing-params/conversations/bookAppointment.topic.d.ts +2 -0
  34. package/build/__tests__/testDirsAndFiles/bad-missing-params/conversations/bookAppointment.topic.js +4 -0
  35. package/build/__tests__/testDirsAndFiles/bad-skill/build/.spruce/events/listeners.d.ts +2 -0
  36. package/build/__tests__/testDirsAndFiles/bad-skill/build/.spruce/events/listeners.js +3 -0
  37. package/build/__tests__/testDirsAndFiles/bad-skill/build/conversations/bookAppointment.topic.d.ts +2 -0
  38. package/build/__tests__/testDirsAndFiles/bad-skill/build/conversations/bookAppointment.topic.js +4 -0
  39. package/build/__tests__/testDirsAndFiles/empty-skill/build/.spruce/events/listeners.d.ts +2 -0
  40. package/build/__tests__/testDirsAndFiles/empty-skill/build/.spruce/events/listeners.js +3 -0
  41. package/build/__tests__/testDirsAndFiles/good/conversations/bookAppointment.topic.d.ts +3 -0
  42. package/build/__tests__/testDirsAndFiles/good/conversations/bookAppointment.topic.js +8 -0
  43. package/build/__tests__/testDirsAndFiles/good/conversations/cancelAppointment.topic.d.ts +3 -0
  44. package/build/__tests__/testDirsAndFiles/good/conversations/cancelAppointment.topic.js +8 -0
  45. package/build/__tests__/testDirsAndFiles/skill/build/.spruce/events/listeners.d.ts +2 -0
  46. package/build/__tests__/testDirsAndFiles/skill/build/.spruce/events/listeners.js +3 -0
  47. package/build/__tests__/testDirsAndFiles/skill/build/conversations/bookAppointment.topic.d.ts +3 -0
  48. package/build/__tests__/testDirsAndFiles/skill/build/conversations/bookAppointment.topic.js +8 -0
  49. package/build/__tests__/testDirsAndFiles/skill/build/conversations/cancelAppointment.topic.d.ts +3 -0
  50. package/build/__tests__/testDirsAndFiles/skill/build/conversations/cancelAppointment.topic.js +8 -0
  51. package/build/__tests__/testDirsAndFiles/skill/build/conversations/favoriteColor.topic.d.ts +3 -0
  52. package/build/__tests__/testDirsAndFiles/skill/build/conversations/favoriteColor.topic.js +18 -0
  53. package/build/__tests__/testDirsAndFiles/skill/build/conversations/favoriteColorTopicChanger.topic.d.ts +3 -0
  54. package/build/__tests__/testDirsAndFiles/skill/build/conversations/favoriteColorTopicChanger.topic.js +18 -0
  55. package/build/__tests__/testDirsAndFiles/skill/build/conversations/mixedStringsAndCallbacks.topic.d.ts +3 -0
  56. package/build/__tests__/testDirsAndFiles/skill/build/conversations/mixedStringsAndCallbacks.topic.js +29 -0
  57. package/build/__tests__/testDirsAndFiles/skill-assertions/build/.spruce/events/listeners.d.ts +2 -0
  58. package/build/__tests__/testDirsAndFiles/skill-assertions/build/.spruce/events/listeners.js +3 -0
  59. package/build/__tests__/testDirsAndFiles/skill-assertions/build/conversations/assertsScriptCallbackOptions.topic.d.ts +3 -0
  60. package/build/__tests__/testDirsAndFiles/skill-assertions/build/conversations/assertsScriptCallbackOptions.topic.js +22 -0
  61. package/build/__tests__/testDirsAndFiles/skill-assertions/build/conversations/assertsScriptOnlyCalledOnce.topic.d.ts +3 -0
  62. package/build/__tests__/testDirsAndFiles/skill-assertions/build/conversations/assertsScriptOnlyCalledOnce.topic.js +14 -0
  63. package/build/__tests__/testDirsAndFiles/skill-with-script-that-throws/build/.spruce/events/listeners.d.ts +2 -0
  64. package/build/__tests__/testDirsAndFiles/skill-with-script-that-throws/build/.spruce/events/listeners.js +3 -0
  65. package/build/__tests__/testDirsAndFiles/skill-with-script-that-throws/build/conversations/cancelAppointment.topic.d.ts +3 -0
  66. package/build/__tests__/testDirsAndFiles/skill-with-script-that-throws/build/conversations/cancelAppointment.topic.js +12 -0
  67. package/build/esm/__tests__/behavioral/CheckingHealth.test.d.ts +10 -0
  68. package/build/esm/__tests__/behavioral/CheckingHealth.test.js +104 -0
  69. package/build/esm/__tests__/behavioral/KillingASkill.test.d.ts +4 -0
  70. package/build/esm/__tests__/behavioral/KillingASkill.test.js +32 -0
  71. package/build/esm/__tests__/behavioral/RegisteringConversationsOnBoot.test.d.ts +11 -0
  72. package/build/esm/__tests__/behavioral/RegisteringConversationsOnBoot.test.js +126 -0
  73. package/build/esm/__tests__/behavioral/RespondingToMessages.test.d.ts +13 -0
  74. package/build/esm/__tests__/behavioral/RespondingToMessages.test.js +156 -0
  75. package/build/esm/__tests__/behavioral/TestingAConversation.test.d.ts +10 -0
  76. package/build/esm/__tests__/behavioral/TestingAConversation.test.js +93 -0
  77. package/build/esm/__tests__/implementation/ConversationCoordinator.test.d.ts +15 -0
  78. package/build/esm/__tests__/implementation/ConversationCoordinator.test.js +168 -0
  79. package/build/esm/__tests__/implementation/MessageGraphicsInterface/EmailField.test.d.ts +7 -0
  80. package/build/esm/__tests__/implementation/MessageGraphicsInterface/EmailField.test.js +82 -0
  81. package/build/esm/__tests__/implementation/MessageGraphicsInterface/MessageGraphicsInterface.test.d.ts +4 -0
  82. package/build/esm/__tests__/implementation/MessageGraphicsInterface/MessageGraphicsInterface.test.js +47 -0
  83. package/build/esm/__tests__/implementation/MessageGraphicsInterface/SelectField.test.d.ts +7 -0
  84. package/build/esm/__tests__/implementation/MessageGraphicsInterface/SelectField.test.js +80 -0
  85. package/build/esm/__tests__/implementation/MessageGraphicsInterface/TextField.test.d.ts +6 -0
  86. package/build/esm/__tests__/implementation/MessageGraphicsInterface/TextField.test.js +55 -0
  87. package/build/esm/__tests__/implementation/ScriptTester.test.d.ts +18 -0
  88. package/build/esm/__tests__/implementation/ScriptTester.test.js +465 -0
  89. package/build/esm/__tests__/implementation/SuggesterUtil.test.d.ts +7 -0
  90. package/build/esm/__tests__/implementation/SuggesterUtil.test.js +74 -0
  91. package/build/esm/__tests__/implementation/TopicLoader.test.d.ts +8 -0
  92. package/build/esm/__tests__/implementation/TopicLoader.test.js +79 -0
  93. package/build/esm/__tests__/implementation/TopicScriptPlayer.test.d.ts +21 -0
  94. package/build/esm/__tests__/implementation/TopicScriptPlayer.test.js +452 -0
  95. package/build/esm/__tests__/implementation/TopicSuggester.test.d.ts +8 -0
  96. package/build/esm/__tests__/implementation/TopicSuggester.test.js +124 -0
  97. package/build/esm/__tests__/testDirsAndFiles/bad-empty/conversations/bookAppointment.topic.d.ts +0 -0
  98. package/build/esm/__tests__/testDirsAndFiles/bad-empty/conversations/bookAppointment.topic.js +1 -0
  99. package/build/esm/__tests__/testDirsAndFiles/bad-missing-params/conversations/bookAppointment.topic.d.ts +2 -0
  100. package/build/esm/__tests__/testDirsAndFiles/bad-missing-params/conversations/bookAppointment.topic.js +2 -0
  101. package/build/esm/__tests__/testDirsAndFiles/bad-skill/build/conversations/bookAppointment.topic.d.ts +2 -0
  102. package/build/esm/__tests__/testDirsAndFiles/bad-skill/build/conversations/bookAppointment.topic.js +2 -0
  103. package/build/esm/__tests__/testDirsAndFiles/good/conversations/bookAppointment.topic.d.ts +3 -0
  104. package/build/esm/__tests__/testDirsAndFiles/good/conversations/bookAppointment.topic.js +6 -0
  105. package/build/esm/__tests__/testDirsAndFiles/good/conversations/cancelAppointment.topic.d.ts +3 -0
  106. package/build/esm/__tests__/testDirsAndFiles/good/conversations/cancelAppointment.topic.js +6 -0
  107. package/build/esm/__tests__/testDirsAndFiles/skill/build/conversations/bookAppointment.topic.d.ts +3 -0
  108. package/build/esm/__tests__/testDirsAndFiles/skill/build/conversations/bookAppointment.topic.js +6 -0
  109. package/build/esm/__tests__/testDirsAndFiles/skill/build/conversations/cancelAppointment.topic.d.ts +3 -0
  110. package/build/esm/__tests__/testDirsAndFiles/skill/build/conversations/cancelAppointment.topic.js +6 -0
  111. package/build/esm/__tests__/testDirsAndFiles/skill/build/conversations/favoriteColor.topic.d.ts +3 -0
  112. package/build/esm/__tests__/testDirsAndFiles/skill/build/conversations/favoriteColor.topic.js +25 -0
  113. package/build/esm/__tests__/testDirsAndFiles/skill/build/conversations/favoriteColorTopicChanger.topic.d.ts +3 -0
  114. package/build/esm/__tests__/testDirsAndFiles/skill/build/conversations/favoriteColorTopicChanger.topic.js +25 -0
  115. package/build/esm/__tests__/testDirsAndFiles/skill/build/conversations/mixedStringsAndCallbacks.topic.d.ts +3 -0
  116. package/build/esm/__tests__/testDirsAndFiles/skill/build/conversations/mixedStringsAndCallbacks.topic.js +36 -0
  117. package/build/esm/__tests__/testDirsAndFiles/skill-assertions/build/conversations/assertsScriptCallbackOptions.topic.d.ts +3 -0
  118. package/build/esm/__tests__/testDirsAndFiles/skill-assertions/build/conversations/assertsScriptCallbackOptions.topic.js +29 -0
  119. package/build/esm/__tests__/testDirsAndFiles/skill-assertions/build/conversations/assertsScriptOnlyCalledOnce.topic.d.ts +3 -0
  120. package/build/esm/__tests__/testDirsAndFiles/skill-assertions/build/conversations/assertsScriptOnlyCalledOnce.topic.js +21 -0
  121. package/build/esm/__tests__/testDirsAndFiles/skill-with-script-that-throws/build/conversations/cancelAppointment.topic.d.ts +3 -0
  122. package/build/esm/__tests__/testDirsAndFiles/skill-with-script-that-throws/build/conversations/cancelAppointment.topic.js +10 -0
  123. package/package.json +6 -6
@@ -0,0 +1,413 @@
1
+ "use strict";
2
+ var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
3
+ var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
4
+ if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
5
+ else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
6
+ return c > 3 && r && Object.defineProperty(target, key, r), r;
7
+ };
8
+ var __importDefault = (this && this.__importDefault) || function (mod) {
9
+ return (mod && mod.__esModule) ? mod : { "default": mod };
10
+ };
11
+ Object.defineProperty(exports, "__esModule", { value: true });
12
+ const test_1 = require("@sprucelabs/test");
13
+ const test_utils_1 = require("@sprucelabs/test-utils");
14
+ const AbstractConversationTest_1 = __importDefault(require("../../tests/AbstractConversationTest"));
15
+ const TopicScriptPlayer_1 = require("../../topics/TopicScriptPlayer");
16
+ class TopicScriptPlayerTest extends AbstractConversationTest_1.default {
17
+ static async throwsWhenRequiredOptionsNotSent() {
18
+ //@ts-ignore
19
+ const err = test_1.assert.doesThrow(() => new TopicScriptPlayer_1.TopicScriptPlayer());
20
+ test_utils_1.errorAssert.assertError(err, 'MISSING_PARAMETERS', {
21
+ parameters: ['script', 'sendMessageHandler', 'target.personId'],
22
+ });
23
+ }
24
+ static async respondsToMessageWithOnlyLineInScript() {
25
+ const messages = [];
26
+ const player = this.Player({
27
+ script: ['It all started on a cold, dark night.'],
28
+ target: { personId: '12345' },
29
+ sendMessageHandler: async (message) => {
30
+ messages.push(message);
31
+ },
32
+ });
33
+ await this.sendMessage(player, {
34
+ body: 'how are you today?',
35
+ });
36
+ test_1.assert.isLength(messages, 1);
37
+ test_1.assert.isEqual(messages[0].body, 'It all started on a cold, dark night.');
38
+ test_1.assert.isEqualDeep(messages[0].target.personId, '12345');
39
+ }
40
+ static async respondsToMessagesWithAllLinesInScript() {
41
+ const messages = [];
42
+ const player = this.Player({
43
+ script: [
44
+ 'It all started on a cold, dark night.',
45
+ 'Before the sun went down',
46
+ ],
47
+ sendMessageHandler: async (message) => {
48
+ messages.push(message);
49
+ },
50
+ });
51
+ await this.sendMessage(player, {
52
+ body: 'how are you today?',
53
+ });
54
+ test_1.assert.isLength(messages, 2);
55
+ test_1.assert.isEqual(messages[0].body, 'It all started on a cold, dark night.');
56
+ test_1.assert.isEqual(messages[1].body, 'Before the sun went down');
57
+ }
58
+ static async multipleTextLinesWaitsForDelay() {
59
+ const messages = [];
60
+ const player = this.Player({
61
+ lineDelay: 50,
62
+ script: [
63
+ 'It all started on a cold, dark night.',
64
+ 'Before the sun went down',
65
+ ],
66
+ sendMessageHandler: async (message) => {
67
+ messages.push(message);
68
+ },
69
+ });
70
+ void this.sendMessage(player, {
71
+ body: 'how are you today?',
72
+ });
73
+ test_1.assert.isLength(messages, 1);
74
+ await this.wait(100);
75
+ test_1.assert.isLength(messages, 2);
76
+ test_1.assert.isEqual(messages[0].body, 'It all started on a cold, dark night.');
77
+ test_1.assert.isEqual(messages[1].body, 'Before the sun went down');
78
+ }
79
+ static async restartsScriptNextMessage() {
80
+ const messages = [];
81
+ const player = this.Player({
82
+ script: [
83
+ 'It all started on a cold, dark night.',
84
+ 'Before the sun went down',
85
+ ],
86
+ sendMessageHandler: async (message) => {
87
+ messages.push(message);
88
+ },
89
+ });
90
+ await this.sendMessage(player, {
91
+ body: 'how are you today?',
92
+ });
93
+ await this.sendMessage(player, {
94
+ body: 'how are you today?',
95
+ });
96
+ test_1.assert.isLength(messages, 4);
97
+ }
98
+ static async respondsWithRandomLine() {
99
+ const messages = [];
100
+ const player = this.Player({
101
+ script: [['one', 'two', 'three']],
102
+ sendMessageHandler: async (message) => {
103
+ messages.push(message);
104
+ },
105
+ });
106
+ const remaining = { one: 1, two: 1, three: 1 };
107
+ do {
108
+ await this.sendMessage(player, {
109
+ body: 'how are you today?',
110
+ });
111
+ if (messages.length === 0) {
112
+ test_1.assert.fail("Didn't send any message.");
113
+ }
114
+ //@ts-ignore
115
+ delete remaining[messages.pop().body];
116
+ } while (Object.keys(remaining).length > 0);
117
+ }
118
+ static async renderLineSendsMessage() {
119
+ const messages = [];
120
+ const player = this.Player({
121
+ script: [
122
+ async (options) => {
123
+ options.ui.renderLine('What is up?');
124
+ },
125
+ ],
126
+ sendMessageHandler: async (message) => {
127
+ messages.push(message);
128
+ },
129
+ });
130
+ await this.sendMessage(player, {
131
+ body: 'What the?',
132
+ });
133
+ test_1.assert.isLength(messages, 1);
134
+ test_1.assert.isEqual(messages[0].body, 'What is up?');
135
+ //@ts-ignore
136
+ test_1.assert.isFalsy(messages[0].target.isCore);
137
+ }
138
+ static async scriptCanAskToConfirm(confirmBody, expectedConfirmResults) {
139
+ let confirmStarted = false;
140
+ let confirmResponse;
141
+ let confirmFinished = false;
142
+ const messages = [];
143
+ const player = this.Player({
144
+ sendMessageHandler: async (message) => {
145
+ messages.push(message);
146
+ },
147
+ script: [
148
+ 'It all started on a cold, dark night.',
149
+ 'Before the sun went down',
150
+ async (options) => {
151
+ confirmStarted = true;
152
+ const confirm = await options.ui.confirm('Are you sure?');
153
+ confirmResponse = confirm;
154
+ confirmFinished = true;
155
+ },
156
+ ],
157
+ });
158
+ void this.sendMessage(player, {
159
+ body: 'tell me a story!',
160
+ });
161
+ await this.wait(100);
162
+ test_1.assert.isTrue(confirmStarted);
163
+ test_1.assert.isUndefined(confirmResponse);
164
+ test_1.assert.isFalse(confirmFinished);
165
+ await this.sendMessage(player, {
166
+ body: confirmBody,
167
+ });
168
+ await this.wait(100);
169
+ test_1.assert.isTrue(confirmStarted);
170
+ test_1.assert.isEqual(confirmResponse, expectedConfirmResults);
171
+ test_1.assert.isTrue(confirmFinished);
172
+ test_1.assert.doesInclude(messages, { body: 'Are you sure?' });
173
+ }
174
+ static async scriptCanRespondWithTransition() {
175
+ const player = this.Player({
176
+ script: [
177
+ async () => {
178
+ return { transitionConversationTo: 'greeting' };
179
+ },
180
+ ],
181
+ });
182
+ const results = await this.sendMessage(player, {
183
+ body: 'tell me a story!',
184
+ });
185
+ test_1.assert.isTruthy(results);
186
+ test_1.assert.isTruthy(results.transitionConversationTo);
187
+ test_1.assert.isEqual(results.transitionConversationTo, 'greeting');
188
+ }
189
+ static async scriptCanRespondWithTransitionAInLaterLines() {
190
+ const player = this.Player({
191
+ script: [
192
+ 'Hey there!',
193
+ async () => { },
194
+ async () => {
195
+ return { transitionConversationTo: 'greeting' };
196
+ },
197
+ ],
198
+ });
199
+ const results = await this.sendMessage(player, {
200
+ body: 'tell me a story!',
201
+ });
202
+ test_1.assert.isTruthy(results);
203
+ test_1.assert.isTruthy(results.transitionConversationTo);
204
+ test_1.assert.isEqual(results.transitionConversationTo, 'greeting');
205
+ }
206
+ static async scriptCanRespondWithTransitionAInLaterLinesAfterAskingForInput() {
207
+ const player = this.Player({
208
+ script: [
209
+ 'Hey there!',
210
+ async (options) => {
211
+ await options.ui.prompt({ type: 'text', isRequired: true });
212
+ },
213
+ async () => {
214
+ return { transitionConversationTo: 'greeting' };
215
+ },
216
+ ],
217
+ });
218
+ await this.sendMessage(player, {
219
+ body: 'tell me a story!',
220
+ });
221
+ const results = await this.sendMessage(player, {
222
+ body: 'Yes!',
223
+ });
224
+ test_1.assert.isTruthy(results);
225
+ test_1.assert.isTruthy(results.transitionConversationTo);
226
+ test_1.assert.isEqual(results.transitionConversationTo, 'greeting');
227
+ }
228
+ static async randomOnOptions() {
229
+ const messages = [];
230
+ const remaining = { one: true, two: true, three: true };
231
+ const possibilities = ['one', 'two', 'three'];
232
+ const player = this.Player({
233
+ sendMessageHandler: async (message) => {
234
+ messages.push(message.body);
235
+ },
236
+ script: [
237
+ async (options) => {
238
+ test_1.assert.isFunction(options.rand);
239
+ const answer = options.rand(possibilities);
240
+ //@ts-ignore
241
+ delete remaining[answer];
242
+ },
243
+ ],
244
+ });
245
+ do {
246
+ await this.sendMessage(player, {
247
+ body: 'tell me a story!',
248
+ });
249
+ } while (Object.keys(remaining).length > 0);
250
+ }
251
+ static async randomOptionsRandomOnNotString() {
252
+ const possibilities = [true, false];
253
+ let answer;
254
+ const player = this.Player({
255
+ script: [
256
+ async (options) => {
257
+ test_1.assert.isFunction(options.rand);
258
+ answer = options.rand(possibilities);
259
+ },
260
+ ],
261
+ });
262
+ await this.sendMessage(player, {
263
+ body: 'go',
264
+ });
265
+ test_1.assert.isTrue(possibilities.includes(answer));
266
+ }
267
+ static async retainsStateBetweenScriptLines() {
268
+ const player = this.Player({
269
+ script: [
270
+ async (options) => {
271
+ options.state.goTeam = true;
272
+ },
273
+ async (options) => {
274
+ test_1.assert.isTrue(options.state.goTeam);
275
+ },
276
+ ],
277
+ });
278
+ await this.sendMessage(player, {
279
+ body: 'tell me a story!',
280
+ });
281
+ }
282
+ static async retainsStateBetweenMessages() {
283
+ let stateCount = 0;
284
+ const player = this.Player({
285
+ script: [
286
+ async (options) => {
287
+ if (!options.state.count) {
288
+ options.state.count = 1;
289
+ }
290
+ else {
291
+ options.state.count++;
292
+ }
293
+ },
294
+ async (options) => {
295
+ options.state.count++;
296
+ stateCount = options.state.count;
297
+ },
298
+ ],
299
+ });
300
+ await this.sendMessage(player, {
301
+ body: 'tell me a story!',
302
+ });
303
+ test_1.assert.isEqual(stateCount, 2);
304
+ await this.sendMessage(player, { body: 'again, again!' });
305
+ test_1.assert.isEqual(stateCount, 4);
306
+ }
307
+ static async alwaysEndsWithRedirectToDiscovery() {
308
+ let stateCount = 0;
309
+ const player = this.Player({
310
+ script: [
311
+ async (options) => {
312
+ if (!options.state.count) {
313
+ options.state.count = 1;
314
+ }
315
+ else {
316
+ options.state.count++;
317
+ }
318
+ },
319
+ async (options) => {
320
+ options.state.count++;
321
+ stateCount = options.state.count;
322
+ },
323
+ ],
324
+ });
325
+ let results = await this.sendMessage(player, {
326
+ body: 'tell me a story!',
327
+ });
328
+ test_1.assert.isEqual(results === null || results === void 0 ? void 0 : results.transitionConversationTo, 'discovery');
329
+ test_1.assert.isEqual(stateCount, 2);
330
+ results = await this.sendMessage(player, { body: 'again, again!' });
331
+ test_1.assert.isEqual(results === null || results === void 0 ? void 0 : results.transitionConversationTo, 'discovery');
332
+ test_1.assert.isEqual(stateCount, 4);
333
+ }
334
+ static Player(options) {
335
+ var _a, _b;
336
+ return new TopicScriptPlayer_1.TopicScriptPlayer({
337
+ target: (_a = options.target) !== null && _a !== void 0 ? _a : { personId: '12345' },
338
+ script: options.script,
339
+ lineDelay: 0,
340
+ sendMessageHandler: (_b = options.sendMessageHandler) !== null && _b !== void 0 ? _b : async function () { },
341
+ });
342
+ }
343
+ static async sendMessage(player, message) {
344
+ return player.handleMessage(this.buildMessage({ source: { personId: '1234' }, ...message }));
345
+ }
346
+ }
347
+ __decorate([
348
+ (0, test_1.test)()
349
+ ], TopicScriptPlayerTest, "throwsWhenRequiredOptionsNotSent", null);
350
+ __decorate([
351
+ (0, test_1.test)()
352
+ ], TopicScriptPlayerTest, "respondsToMessageWithOnlyLineInScript", null);
353
+ __decorate([
354
+ (0, test_1.test)()
355
+ ], TopicScriptPlayerTest, "respondsToMessagesWithAllLinesInScript", null);
356
+ __decorate([
357
+ (0, test_1.test)()
358
+ ], TopicScriptPlayerTest, "multipleTextLinesWaitsForDelay", null);
359
+ __decorate([
360
+ (0, test_1.test)()
361
+ ], TopicScriptPlayerTest, "restartsScriptNextMessage", null);
362
+ __decorate([
363
+ (0, test_1.test)()
364
+ ], TopicScriptPlayerTest, "respondsWithRandomLine", null);
365
+ __decorate([
366
+ (0, test_1.test)()
367
+ ], TopicScriptPlayerTest, "renderLineSendsMessage", null);
368
+ __decorate([
369
+ (0, test_1.test)('Passes confirm when sent "Y"', 'Y', true),
370
+ (0, test_1.test)('Passes confirm when sent "y"', 'y', true),
371
+ (0, test_1.test)('Passes confirm when sent "yes"', 'yes', true),
372
+ (0, test_1.test)('Passes confirm when sent "yup"', 'yup', true),
373
+ (0, test_1.test)('Passes confirm when sent "yes please"', 'yes please', true),
374
+ (0, test_1.test)('Passes confirm when sent "yeah"', 'yeah', true),
375
+ (0, test_1.test)('Passes confirm when sent "yeah!!!"', 'yeah!!!', true),
376
+ (0, test_1.test)('Passes confirm when sent "oh heck ya"', 'oh heck ya', true),
377
+ (0, test_1.test)('Passes confirm when sent "oh heck yeah"', 'oh heck yeah', true),
378
+ (0, test_1.test)('Passes confirm when sent "👍"', '👍', true),
379
+ (0, test_1.test)('Fails confirm when sent "negative"', 'negative', false),
380
+ (0, test_1.test)('Fails confirm when sent "nope"', 'nope', false),
381
+ (0, test_1.test)('Fails confirm when sent "nope!!"', 'nope!!', false),
382
+ (0, test_1.test)('Fails confirm when sent "no"', 'no', false),
383
+ (0, test_1.test)('Fails confirm when sent "no thanks"', 'no thanks', false),
384
+ (0, test_1.test)('Fails confirm when sent "no thank you"', 'no thank you', false),
385
+ (0, test_1.test)('Fails confirm when sent "nah"', 'nah', false),
386
+ (0, test_1.test)('Fails confirm when sent "No thanks!!!"', 'No thanks!!!', false),
387
+ (0, test_1.test)('Fails confirm when sent "👎"', '👎', true)
388
+ ], TopicScriptPlayerTest, "scriptCanAskToConfirm", null);
389
+ __decorate([
390
+ (0, test_1.test)()
391
+ ], TopicScriptPlayerTest, "scriptCanRespondWithTransition", null);
392
+ __decorate([
393
+ (0, test_1.test)()
394
+ ], TopicScriptPlayerTest, "scriptCanRespondWithTransitionAInLaterLines", null);
395
+ __decorate([
396
+ (0, test_1.test)()
397
+ ], TopicScriptPlayerTest, "scriptCanRespondWithTransitionAInLaterLinesAfterAskingForInput", null);
398
+ __decorate([
399
+ (0, test_1.test)()
400
+ ], TopicScriptPlayerTest, "randomOnOptions", null);
401
+ __decorate([
402
+ (0, test_1.test)()
403
+ ], TopicScriptPlayerTest, "randomOptionsRandomOnNotString", null);
404
+ __decorate([
405
+ (0, test_1.test)()
406
+ ], TopicScriptPlayerTest, "retainsStateBetweenScriptLines", null);
407
+ __decorate([
408
+ (0, test_1.test)()
409
+ ], TopicScriptPlayerTest, "retainsStateBetweenMessages", null);
410
+ __decorate([
411
+ (0, test_1.test)()
412
+ ], TopicScriptPlayerTest, "alwaysEndsWithRedirectToDiscovery", null);
413
+ exports.default = TopicScriptPlayerTest;
@@ -0,0 +1,8 @@
1
+ import AbstractSpruceTest from '@sprucelabs/test';
2
+ export default class TopicSuggesterTest extends AbstractSpruceTest {
3
+ protected static canCreateTopicSuggester(): Promise<void>;
4
+ protected static canReturnOnlyTopic(): Promise<void>;
5
+ protected static makeSureTopicsAreReturnedInOrderOfConfidence(): Promise<void>;
6
+ protected static matchTests(phrase: string, expectedSuggestionKey: string): Promise<void>;
7
+ private static Suggester;
8
+ }
@@ -0,0 +1,131 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
17
+ });
18
+ var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
19
+ var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
20
+ if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
21
+ else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
22
+ return c > 3 && r && Object.defineProperty(target, key, r), r;
23
+ };
24
+ var __importStar = (this && this.__importStar) || function (mod) {
25
+ if (mod && mod.__esModule) return mod;
26
+ var result = {};
27
+ if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
28
+ __setModuleDefault(result, mod);
29
+ return result;
30
+ };
31
+ Object.defineProperty(exports, "__esModule", { value: true });
32
+ const test_1 = __importStar(require("@sprucelabs/test"));
33
+ const TopicSuggester_1 = require("../../topics/TopicSuggester");
34
+ class TopicSuggesterTest extends test_1.default {
35
+ static async canCreateTopicSuggester() {
36
+ const topicSuggester = await TopicSuggester_1.TopicSuggester.Suggester({ topics: [] });
37
+ test_1.assert.isTruthy(topicSuggester);
38
+ }
39
+ static async canReturnOnlyTopic() {
40
+ const topics = [
41
+ {
42
+ key: 'bookAppointment',
43
+ label: 'Book an appointment',
44
+ utterances: ['book an appointment'],
45
+ },
46
+ ];
47
+ const messageBody = 'book';
48
+ const suggestions = await this.Suggester(topics, messageBody);
49
+ test_1.assert.doesInclude(suggestions[0], {
50
+ key: 'bookAppointment',
51
+ label: 'Book an appointment',
52
+ });
53
+ test_1.assert.isAbove(suggestions[0].confidence, 0);
54
+ }
55
+ static async makeSureTopicsAreReturnedInOrderOfConfidence() {
56
+ const suggestions = await this.Suggester([
57
+ {
58
+ key: 'scheduleShft',
59
+ label: 'Shift',
60
+ utterances: ['shift', 'block my time', 'break', 'hours', 'schedule'],
61
+ },
62
+ {
63
+ key: 'bookAppointment',
64
+ label: 'Book',
65
+ utterances: [
66
+ 'book appointment',
67
+ 'schedule an appointment',
68
+ 'book',
69
+ 'schedule',
70
+ ],
71
+ },
72
+ ], "I'd like to schedule a haircut");
73
+ test_1.assert.isLength(suggestions, 2);
74
+ test_1.assert.isEqualDeep(suggestions[0].key, 'bookAppointment');
75
+ }
76
+ static async matchTests(phrase, expectedSuggestionKey) {
77
+ const suggestions = await this.Suggester([
78
+ {
79
+ key: 'contactUs',
80
+ label: 'Contact',
81
+ utterances: [
82
+ 'tell me more',
83
+ 'experience',
84
+ 'experience management',
85
+ 'tell me about experience',
86
+ 'I want to know more',
87
+ ],
88
+ },
89
+ {
90
+ key: 'jokes',
91
+ label: 'Jokes',
92
+ utterances: [
93
+ 'be funny',
94
+ 'tell me a joke',
95
+ 'tell me something funny',
96
+ 'laugh',
97
+ 'funny',
98
+ 'make me laugh',
99
+ 'robot jokes',
100
+ ],
101
+ },
102
+ ], phrase);
103
+ test_1.assert.isLength(suggestions, 2);
104
+ test_1.assert.isEqualDeep(suggestions[0].key, expectedSuggestionKey);
105
+ test_1.assert.isAbove(suggestions[0].confidence, 0.8);
106
+ }
107
+ static async Suggester(topics, messageBody) {
108
+ const topicSuggester = await TopicSuggester_1.TopicSuggester.Suggester({
109
+ topics,
110
+ });
111
+ const suggestions = await topicSuggester.suggest(messageBody);
112
+ return suggestions;
113
+ }
114
+ }
115
+ __decorate([
116
+ (0, test_1.test)()
117
+ ], TopicSuggesterTest, "canCreateTopicSuggester", null);
118
+ __decorate([
119
+ (0, test_1.test)()
120
+ ], TopicSuggesterTest, "canReturnOnlyTopic", null);
121
+ __decorate([
122
+ (0, test_1.test)()
123
+ ], TopicSuggesterTest, "makeSureTopicsAreReturnedInOrderOfConfidence", null);
124
+ __decorate([
125
+ (0, test_1.test)('matches regardless "Experience "', 'Experience ', 'contactUs'),
126
+ (0, test_1.test)('matches regardless "Tell me about experience"', 'Tell me about experience ', 'contactUs'),
127
+ (0, test_1.test)('matches "Tell me something funny"', 'Tell me something funny', 'jokes'),
128
+ (0, test_1.test)('matches "Joke me"', 'Joke me', 'jokes'),
129
+ (0, test_1.test)('matches "Joke me"', 'Joke me', 'jokes')
130
+ ], TopicSuggesterTest, "matchTests", null);
131
+ exports.default = TopicSuggesterTest;
@@ -0,0 +1,2 @@
1
+ declare const topic: {};
2
+ export default topic;
@@ -0,0 +1,4 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const topic = {};
4
+ exports.default = topic;
@@ -0,0 +1,2 @@
1
+ declare const _default: never[];
2
+ export default _default;
@@ -0,0 +1,3 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.default = [];
@@ -0,0 +1,2 @@
1
+ declare const topic: {};
2
+ export default topic;
@@ -0,0 +1,4 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const topic = {};
4
+ exports.default = topic;
@@ -0,0 +1,2 @@
1
+ declare const _default: never[];
2
+ export default _default;
@@ -0,0 +1,3 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.default = [];
@@ -0,0 +1,3 @@
1
+ import { TopicDefinition } from '../../../../types/conversation.types';
2
+ declare const topicDefinition: TopicDefinition;
3
+ export default topicDefinition;
@@ -0,0 +1,8 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const topicDefinition = {
4
+ label: 'book appointment',
5
+ utterances: ['book appointment', 'Can i book my appointment?', 'book'],
6
+ script: ['Sweet, lets book!', 'Lemme find your appointment!'],
7
+ };
8
+ exports.default = topicDefinition;
@@ -0,0 +1,3 @@
1
+ import { TopicDefinition } from '../../../../types/conversation.types';
2
+ declare const topicDefinition: TopicDefinition;
3
+ export default topicDefinition;
@@ -0,0 +1,8 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const topicDefinition = {
4
+ label: 'Cancel appointment',
5
+ utterances: ['Cancel appointment', 'Can i cancel my appointment?', 'cancel'],
6
+ script: ['how are you?', 'Lemme find your appointment!'],
7
+ };
8
+ exports.default = topicDefinition;
@@ -0,0 +1,2 @@
1
+ declare const _default: never[];
2
+ export default _default;
@@ -0,0 +1,3 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.default = [];
@@ -0,0 +1,3 @@
1
+ import { TopicDefinition } from '../../../../../types/conversation.types';
2
+ declare const topicDefinition: TopicDefinition;
3
+ export default topicDefinition;
@@ -0,0 +1,8 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const topicDefinition = {
4
+ label: 'book appointment',
5
+ utterances: ['book appointment', 'Can i book my appointment?', 'book'],
6
+ script: ['Sweet, lets book!', 'Lemme find your appointment!'],
7
+ };
8
+ exports.default = topicDefinition;
@@ -0,0 +1,3 @@
1
+ import { TopicDefinition } from '../../../../../types/conversation.types';
2
+ declare const topicDefinition: TopicDefinition;
3
+ export default topicDefinition;
@@ -0,0 +1,8 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const topicDefinition = {
4
+ label: 'Cancel appointment',
5
+ utterances: ['Cancel appointment', 'Can i cancel my appointment?', 'cancel'],
6
+ script: ['how are you?', 'Lemme find your appointment!'],
7
+ };
8
+ exports.default = topicDefinition;
@@ -0,0 +1,3 @@
1
+ import { TopicDefinition } from '../../../../../types/conversation.types';
2
+ declare const topicDefinition: TopicDefinition;
3
+ export default topicDefinition;