@cognigy/rest-api-client 0.11.0 → 0.12.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 (189) hide show
  1. package/.snyk +1 -1
  2. package/build/GenericUploadFn.js +1 -1
  3. package/build/RestAPIClient.js +14 -0
  4. package/build/apigroups/AdministrationAPIGroup_2_0.js +25 -3
  5. package/build/apigroups/AnalyticsAPIGroup_2_0.js +12 -0
  6. package/build/apigroups/InsightsAPIGroup_2_0.js +53 -0
  7. package/build/apigroups/ResourcesAPIGroup_2_0.js +23 -2
  8. package/build/apigroups/index.js +5 -1
  9. package/build/authentication/BasicAuthentication/BasicAuthentication.js +8 -1
  10. package/build/authentication/OAuth2/ILoginByClientCredentialsParameters.js +3 -0
  11. package/build/authentication/OAuth2/IOAuth2ClientCredentialsGrantAccessTokenRequest.js +11 -0
  12. package/build/authentication/OAuth2/OAuth2Authentication.js +41 -15
  13. package/build/shared/charts/createNodeDescriptor.js +1 -1
  14. package/build/shared/charts/descriptors/apps/index.js +8 -0
  15. package/build/shared/charts/descriptors/apps/initAppSession.js +33 -0
  16. package/build/shared/charts/descriptors/apps/setAppState.js +46 -0
  17. package/build/shared/charts/descriptors/connectionNodes/smtp/emailNotification.js +6 -4
  18. package/build/shared/charts/descriptors/connectionNodes/smtp/sendEmail.js +2 -2
  19. package/build/shared/charts/descriptors/end.js +1 -0
  20. package/build/shared/charts/descriptors/index.js +86 -67
  21. package/build/shared/charts/descriptors/logic/goTo.js +1 -0
  22. package/build/shared/charts/descriptors/logic/if/else.js +2 -0
  23. package/build/shared/charts/descriptors/logic/if/if.js +2 -1
  24. package/build/shared/charts/descriptors/logic/if/then.js +2 -0
  25. package/build/shared/charts/descriptors/logic/index.js +5 -3
  26. package/build/shared/charts/descriptors/logic/interval/elseInterval.js +1 -0
  27. package/build/shared/charts/descriptors/logic/interval/onInterval.js +1 -0
  28. package/build/shared/charts/descriptors/logic/once/afterwards.js +1 -0
  29. package/build/shared/charts/descriptors/logic/once/onFirstExecution.js +1 -0
  30. package/build/shared/charts/descriptors/logic/setTranslation.js +88 -0
  31. package/build/shared/charts/descriptors/logic/switch/case.js +2 -0
  32. package/build/shared/charts/descriptors/logic/switch/default.js +2 -0
  33. package/build/shared/charts/descriptors/logic/switch/switch.js +52 -4
  34. package/build/shared/charts/descriptors/logic/switchLocale.js +30 -2
  35. package/build/shared/charts/descriptors/logic/think.js +7 -3
  36. package/build/shared/charts/descriptors/logic/thinkV2.js +104 -0
  37. package/build/shared/charts/descriptors/logic/wait.js +2 -9
  38. package/build/shared/charts/descriptors/message/checkChannelChange/checkChannelChange.js +1 -0
  39. package/build/shared/charts/descriptors/message/checkChannelChange/onNo.js +3 -1
  40. package/build/shared/charts/descriptors/message/checkChannelChange/onYes.js +3 -1
  41. package/build/shared/charts/descriptors/message/checkChannelChange/unchanged.js +3 -1
  42. package/build/shared/charts/descriptors/message/question/onAnswer.js +3 -1
  43. package/build/shared/charts/descriptors/message/question/onQuestion.js +3 -1
  44. package/build/shared/charts/descriptors/message/question/question.js +474 -56
  45. package/build/shared/charts/descriptors/message/question/utils/datepickerUtils.js +1 -0
  46. package/build/shared/charts/descriptors/message/question/utils/evaluateQuestionAnswer.js +9 -3
  47. package/build/shared/charts/descriptors/message/question/utils/generateAnswerShortForm.js +37 -0
  48. package/build/shared/charts/descriptors/message/question/utils/getQuestionText.js +36 -0
  49. package/build/shared/charts/descriptors/message/question/utils/resetNodeState.js +12 -0
  50. package/build/shared/charts/descriptors/message/question/utils/storeQuestionAnswer.js +30 -0
  51. package/build/shared/charts/descriptors/message/question/utils/validateQuestionAnswer.js +22 -0
  52. package/build/shared/charts/descriptors/microsoft/getToken.js +34 -0
  53. package/build/shared/charts/descriptors/microsoft/index.js +22 -0
  54. package/build/shared/charts/descriptors/microsoft/invalidateToken.js +29 -0
  55. package/build/shared/charts/descriptors/microsoft/tokenStatus/index.js +51 -0
  56. package/build/shared/charts/descriptors/microsoft/tokenStatus/tokenGranted.js +24 -0
  57. package/build/shared/charts/descriptors/microsoft/tokenStatus/tokenNotGranted.js +24 -0
  58. package/build/shared/charts/descriptors/microsoft/utils/design.js +5 -0
  59. package/build/shared/charts/descriptors/nlu/executeCognigyNLU.js +5 -0
  60. package/build/shared/charts/descriptors/nlu/extractAnswer.js +115 -0
  61. package/build/shared/charts/descriptors/nlu/fuzzySearch.js +270 -0
  62. package/build/shared/charts/descriptors/nlu/index.js +7 -1
  63. package/build/shared/charts/descriptors/nlu/matchPattern.js +104 -0
  64. package/build/shared/charts/descriptors/nlu/utils/patternMatcher.js +197 -0
  65. package/build/shared/charts/descriptors/profile/index.js +5 -1
  66. package/build/shared/charts/descriptors/profile/overwriteAnalytics.js +54 -2
  67. package/build/shared/charts/descriptors/profile/requestRating.js +57 -0
  68. package/build/shared/charts/descriptors/profile/setRating.js +39 -0
  69. package/build/shared/charts/descriptors/service/handover.js +29 -2
  70. package/build/shared/charts/descriptors/service/handoverV2.js +129 -0
  71. package/build/shared/charts/descriptors/service/httpRequest.js +26 -7
  72. package/build/shared/charts/descriptors/service/index.js +3 -1
  73. package/build/shared/charts/descriptors/service/triggerFunction/onScheduled.js +2 -0
  74. package/build/shared/charts/descriptors/service/triggerFunction/onSchedulingError.js +2 -0
  75. package/build/shared/charts/descriptors/start.js +1 -0
  76. package/build/shared/charts/descriptors/voicegateway/nodes/callRecording.js +36 -16
  77. package/build/shared/charts/descriptors/voicegateway/nodes/handover.js +2 -2
  78. package/build/shared/charts/descriptors/voicegateway/nodes/playURL.js +9 -0
  79. package/build/shared/charts/descriptors/voicegateway/nodes/sendMessage.js +1 -1
  80. package/build/shared/charts/descriptors/voicegateway/utils/paramUtils.js +9 -1
  81. package/build/shared/charts/descriptors/voicegateway2/index.js +21 -0
  82. package/build/shared/charts/descriptors/voicegateway2/nodes/dtmf.js +56 -0
  83. package/build/shared/charts/descriptors/voicegateway2/nodes/hangup.js +48 -0
  84. package/build/shared/charts/descriptors/voicegateway2/nodes/play.js +199 -0
  85. package/build/shared/charts/descriptors/voicegateway2/nodes/refer.js +44 -0
  86. package/build/shared/charts/descriptors/voicegateway2/nodes/setSessionConfig.js +584 -0
  87. package/build/shared/charts/descriptors/voicegateway2/utils/design.js +5 -0
  88. package/build/shared/charts/descriptors/voicegateway2/utils/strip-nulls.js +19 -0
  89. package/build/shared/constants.js +9 -1
  90. package/build/shared/errors/baseError.js +34 -1
  91. package/build/shared/helper/rest/array.js +19 -0
  92. package/build/shared/helper/rest/boolean.js +5 -1
  93. package/build/shared/helper/rest/index.js +4 -1
  94. package/build/shared/interfaces/IEndpointTranslationSettings.js +32 -0
  95. package/build/shared/interfaces/IHandoverRequestStatus.js +3 -0
  96. package/build/shared/interfaces/{restAPI/administration/user/v2.0/IDeleteUserMeRest_2_0.js → IHttpRequest.js} +1 -1
  97. package/build/shared/interfaces/IOrganisation.js +1 -1
  98. package/build/shared/interfaces/TEntrypointType.js +2 -0
  99. package/build/shared/interfaces/amqpInterface.js +3 -0
  100. package/build/shared/interfaces/analytics/IAnalyticsFlowHistoryData.js +3 -0
  101. package/build/shared/interfaces/analytics/IAnalyticsSourceData.js +196 -45
  102. package/build/shared/interfaces/analytics/IStepEvent.js +2 -1
  103. package/build/shared/interfaces/analytics/TAnalyticsMode.js +10 -0
  104. package/build/shared/interfaces/analytics/TAnalyticsType.js +5 -0
  105. package/build/shared/interfaces/debugEvents/IErrorEventPayload.js +3 -0
  106. package/build/shared/interfaces/debugEvents/TDebugEndpointEvent.js +1 -0
  107. package/build/shared/interfaces/debugEvents/TDebugEventType.js +2 -1
  108. package/build/shared/interfaces/debugEvents/TSessionStateEmitParams.js +3 -0
  109. package/build/shared/interfaces/handover.js +81 -3
  110. package/build/shared/interfaces/license.js +34 -0
  111. package/build/shared/interfaces/license.js.map +1 -0
  112. package/build/shared/interfaces/messageAPI/ai.js +15 -1
  113. package/build/shared/interfaces/messageAPI/endpoints.js +273 -9
  114. package/build/shared/interfaces/resources/IAuditEvent.js +15 -2
  115. package/build/shared/interfaces/resources/IChartNode.js +56 -10
  116. package/build/shared/interfaces/resources/IEndpoint.js +5 -2
  117. package/build/shared/interfaces/resources/IFlow.js +1 -1
  118. package/build/shared/interfaces/resources/ILexicon.js +8 -2
  119. package/build/shared/interfaces/resources/INLUConnector.js +15 -2
  120. package/build/shared/interfaces/resources/INodeDescriptorSet.js +164 -52
  121. package/build/shared/interfaces/resources/IOptionsResolverFunction.js +18 -0
  122. package/build/shared/interfaces/resources/IPlaybookRun.js +61 -0
  123. package/build/shared/interfaces/resources/IProject.js +7 -1
  124. package/build/shared/interfaces/resources/ISlotFiller.js +38 -21
  125. package/build/shared/interfaces/resources/ISnapshot.js +1 -1
  126. package/build/shared/interfaces/resources/ITrackAnalyticsStepsArguments.js +3 -0
  127. package/build/shared/interfaces/resources/TNLUConnectorType.js +2 -1
  128. package/build/shared/interfaces/resources/TResourceType.js +1 -0
  129. package/build/shared/interfaces/resources/TRestChannelType.js +5 -0
  130. package/build/shared/interfaces/resources/TSocketChannelType.js +5 -1
  131. package/build/shared/interfaces/resources/chart/IChartExecutable.js +3 -2
  132. package/build/shared/interfaces/resources/chart/IChartExecutableNode.js +1 -0
  133. package/build/shared/interfaces/resources/intent/IIntent.js +4 -2
  134. package/build/shared/interfaces/resources/intent/IIntentTrainGroup.js +3 -1
  135. package/build/shared/interfaces/resources/intent/ISentence.js +32 -8
  136. package/build/shared/interfaces/resources/settings/IAgentSettings.js +40 -2
  137. package/build/shared/interfaces/resources/settings/IFlowSettings.js +1 -1
  138. package/build/shared/interfaces/restAPI/administration/liveAgent/v2.0/IReadLiveAgentAccountRest_2_0.js +3 -0
  139. package/build/shared/interfaces/restAPI/administration/liveAgent/v2.0/IReadProjectInboxRest_2_0.js +3 -0
  140. package/build/shared/interfaces/restAPI/administration/liveAgent/v2.0/ISetupCognigyLiveAgentInboxRest_2_0.js +3 -0
  141. package/build/shared/interfaces/restAPI/administration/liveAgent/v2.0/ISetupCognigyLiveAgentRest_2_0.js +3 -0
  142. package/build/shared/interfaces/restAPI/administration/liveAgent/v2.0/index.js +3 -0
  143. package/build/shared/interfaces/restAPI/analytics/IDeleteAnalyticsRecordsRest_2_0.js +3 -0
  144. package/build/shared/interfaces/restAPI/analytics/IUpdateAnalyticsRecordProperties_2_0.js +3 -0
  145. package/build/shared/interfaces/restAPI/analytics/IUpdateAnalyticsRecordsRest_2_0.js +3 -0
  146. package/build/shared/interfaces/restAPI/insights/IAnalyticsQueryFilter_2_0.js +3 -0
  147. package/build/shared/interfaces/restAPI/insights/TAnalyticsQueryFilterOperator_2_0.js +3 -0
  148. package/build/shared/interfaces/restAPI/insights/messages/IGenerateMessagesRest_2_0.js +5 -0
  149. package/build/shared/interfaces/restAPI/insights/messages/ILoadMessagesReportByQueryHashResponse_2_0.js +3 -0
  150. package/build/shared/interfaces/restAPI/insights/messages/ILoadMessagesReportByQueryHashRestData_2_0.js +3 -0
  151. package/build/shared/interfaces/restAPI/insights/messages/ITopNMessages_2_0.js +3 -0
  152. package/build/shared/interfaces/restAPI/insights/reports/IGenerateReportResponse_2_0.js +3 -0
  153. package/build/shared/interfaces/restAPI/insights/reports/IGenerateReportRest_2_0.js +41 -0
  154. package/build/shared/interfaces/restAPI/insights/reports/ILoadReportByQueryHashResponse_2_0.js +3 -0
  155. package/build/shared/interfaces/restAPI/insights/reports/ILoadReportByQueryHashRest_2_0.js +3 -0
  156. package/build/shared/interfaces/restAPI/insights/steps/IGenerateStepReportRest_2_0.js +3 -0
  157. package/build/shared/interfaces/restAPI/insights/steps/IIndexStepsRest_2_0.js +3 -0
  158. package/build/shared/interfaces/restAPI/insights/steps/ILoadStepReportByQueryHashResponse_2_0.js +3 -0
  159. package/build/shared/interfaces/restAPI/insights/steps/ILoadStepReportByQueryHashRestData_2_0.js +3 -0
  160. package/build/shared/interfaces/restAPI/insights/steps/IStepIndexItem_2_0.js +3 -0
  161. package/build/shared/interfaces/restAPI/insights/steps/IStepReport_2_0.js +3 -0
  162. package/build/shared/interfaces/restAPI/insights/steps/IStep_2_0.js +3 -0
  163. package/build/shared/interfaces/restAPI/insights/transcripts/IGenerateTranscriptsRest_2_0.js +3 -0
  164. package/build/shared/interfaces/restAPI/insights/transcripts/ILoadTranscriptsReportByQueryHashResponse_2_0.js +3 -0
  165. package/build/shared/interfaces/restAPI/insights/transcripts/ILoadTranscriptsReportByQueryHashRestData_2_0.js +3 -0
  166. package/build/shared/interfaces/restAPI/insights/transcripts/IStepPath_2_0.js +3 -0
  167. package/build/shared/interfaces/restAPI/resources/chart/v2.0/ISearchChartNodesRest_2_0.js +3 -0
  168. package/build/shared/interfaces/restAPI/resources/extension/v2.0/IUpdateExtensionPackageRest_2_0.js +4 -0
  169. package/build/shared/interfaces/restAPI/resources/flow/v2.0/ICreateFlowFromChildrenRest_2_0.js +4 -0
  170. package/build/shared/interfaces/restAPI/resources/flow/v2.0/intent/ITrainYesNoIntentsRest_2_0.js +3 -0
  171. package/build/shared/interfaces/restAPI/resources/lexicon/v2.0/IComposeLexiconDownloadLinkRest_2_0.js +3 -0
  172. package/build/shared/interfaces/restAPI/resources/nluconnector/v2.0/TNLUConnectorType_2_0.js +3 -1
  173. package/build/shared/interfaces/restAPI/resources/nodedescriptorsets/v2.0/IOptionsResolverRest_2_0.js +3 -0
  174. package/build/shared/interfaces/restAPI/resources/playbook/v2.0/IDeletePlaybookRunRest_2_0.js +3 -0
  175. package/build/shared/interfaces/restAPI/resources/playbook/v2.0/IIndexPlaybookRunsRest_2_0.js +3 -0
  176. package/build/shared/interfaces/restAPI/resources/playbook/v2.0/IPlaybookRunIndexItem_2_0.js +3 -0
  177. package/build/shared/interfaces/restAPI/resources/playbook/v2.0/IPlaybookRun_2_0.js +7 -0
  178. package/build/shared/interfaces/restAPI/resources/playbook/v2.0/IReadPlaybookRunRest_2_0.js +3 -0
  179. package/build/shared/interfaces/restAPI/resources/playbook/v2.0/ISchedulePlaybookRunRest_2_0.js +3 -0
  180. package/build/shared/interfaces/security/IACL.js +1 -1
  181. package/build/shared/interfaces/security/IPermission.js +6 -0
  182. package/build/shared/interfaces/security/IRole.js +8 -2
  183. package/build/shared/interfaces/sessionstate/ISessionState.js +3 -0
  184. package/build/shared/interfaces/sessionstate/index.js +3 -0
  185. package/build/shared/interfaces/trainer/ITrainerRecord.js +4 -0
  186. package/build/shared/interfaces/translation.js +11 -0
  187. package/package.json +5 -5
  188. package/types/index.d.ts +3905 -1178
  189. package/build/shared/charts/descriptors/logic/checkFrustration.js +0 -82
@@ -0,0 +1,270 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.FUZZY_SEARCH = void 0;
4
+ const createNodeDescriptor_1 = require("../../createNodeDescriptor");
5
+ const objectSizeValidator_1 = require("../../../helper/objectSizeValidator");
6
+ const getFuzzySearchMaxObjectSizeInBytes = () => {
7
+ return parseInt(process.env.FUZZYSEARCH_MAX_OBJECT_SIZE) || 524288;
8
+ };
9
+ exports.FUZZY_SEARCH = createNodeDescriptor_1.createNodeDescriptor({
10
+ type: "fuzzySearch",
11
+ defaultLabel: "Fuzzy Search",
12
+ summary: "Performs a fuzzy search on a given collection of source data",
13
+ preview: {
14
+ key: "searchPattern",
15
+ type: "text"
16
+ },
17
+ tags: ["nlu", "fuzzy", "search"],
18
+ fields: [
19
+ {
20
+ key: "searchPattern",
21
+ label: "Search Pattern",
22
+ description: "The pattern to search for",
23
+ type: "cognigyText",
24
+ params: {
25
+ required: true
26
+ }
27
+ },
28
+ {
29
+ key: "items",
30
+ label: "Source Data",
31
+ description: "An array of type string or object to search through..",
32
+ type: "json",
33
+ params: {
34
+ required: true
35
+ },
36
+ defaultValue: `[
37
+ "apple",
38
+ "orange",
39
+ "banana",
40
+ "pear"
41
+ ]`
42
+ },
43
+ {
44
+ key: "isCaseSensitive",
45
+ label: "Is Case Sensitive",
46
+ defaultValue: false,
47
+ type: "toggle",
48
+ description: "Indicates whether comparisons should be case sensitive"
49
+ },
50
+ {
51
+ key: "includeScore",
52
+ label: "Include Score",
53
+ defaultValue: true,
54
+ type: "toggle",
55
+ description: "Whether the score should be included in the result set. A score of 1 indicates a perfect match, while a score of 0 indicates a complete mismatch"
56
+ },
57
+ {
58
+ key: "includeMatches",
59
+ label: "Include Matches",
60
+ defaultValue: false,
61
+ type: "toggle",
62
+ description: "Whether the matches should be included in the result set. When true, each record in the result set will include the indices of the matched characters."
63
+ },
64
+ {
65
+ key: "minMatchCharLength",
66
+ label: "Minimum Characters",
67
+ defaultValue: 1,
68
+ type: "number",
69
+ description: "Only the matches whose length exceeds this value will be returned.",
70
+ params: {
71
+ min: 1,
72
+ max: 100
73
+ }
74
+ },
75
+ {
76
+ key: "shouldSort",
77
+ label: "Should Sort",
78
+ defaultValue: true,
79
+ type: "toggle",
80
+ description: "Whether to sort the result list, by score."
81
+ },
82
+ {
83
+ key: "findAllMatches",
84
+ label: "Find All Matches",
85
+ defaultValue: true,
86
+ type: "toggle",
87
+ description: "When activated, the matching function will continue to the end of a search pattern even if a perfect match has already been located in the string."
88
+ },
89
+ {
90
+ key: "location",
91
+ label: "Location",
92
+ defaultValue: 0,
93
+ type: "number",
94
+ description: "Determines approximately where in the text is the pattern expected to be found.",
95
+ params: {
96
+ min: 0,
97
+ max: 100
98
+ }
99
+ },
100
+ {
101
+ key: "threshold",
102
+ label: "Threshold",
103
+ defaultValue: 0.1,
104
+ type: "slider",
105
+ description: "At what point does the match algorithm give up. A threshold of 1.0 requires a perfect match (of both letters and location), a threshold of 0.0 would match anything.",
106
+ params: {
107
+ min: 0,
108
+ max: 1,
109
+ step: 0.1
110
+ }
111
+ },
112
+ {
113
+ key: "distance",
114
+ label: "Distance",
115
+ defaultValue: 100,
116
+ type: "number",
117
+ description: "Determines how close the match must be to the fuzzy location (specified by location).",
118
+ params: {
119
+ min: 0,
120
+ max: 1000
121
+ }
122
+ },
123
+ {
124
+ key: "ignoreLocation",
125
+ label: "Ignore Location",
126
+ defaultValue: true,
127
+ type: "toggle",
128
+ description: "When activated, search will ignore location and distance, so it won't matter where in the string the pattern appears."
129
+ },
130
+ {
131
+ key: "storeLocation",
132
+ type: "select",
133
+ label: "Where to store the result",
134
+ params: {
135
+ options: [
136
+ {
137
+ label: "Input",
138
+ value: "input"
139
+ },
140
+ {
141
+ label: "Context",
142
+ value: "context"
143
+ }
144
+ ],
145
+ required: true
146
+ },
147
+ defaultValue: "input"
148
+ },
149
+ {
150
+ key: "inputKey",
151
+ type: "cognigyText",
152
+ label: "Input Key to store Result",
153
+ defaultValue: "search",
154
+ condition: {
155
+ key: "storeLocation",
156
+ value: "input"
157
+ }
158
+ },
159
+ {
160
+ key: "contextKey",
161
+ type: "cognigyText",
162
+ label: "Context Key to store Result",
163
+ defaultValue: "search",
164
+ condition: {
165
+ key: "storeLocation",
166
+ value: "context"
167
+ }
168
+ }
169
+ ],
170
+ sections: [
171
+ {
172
+ key: "storageOption",
173
+ label: "Storage Option",
174
+ defaultCollapsed: true,
175
+ fields: [
176
+ "storeLocation",
177
+ "inputKey",
178
+ "contextKey"
179
+ ]
180
+ },
181
+ {
182
+ key: "basicOptions",
183
+ label: "Basic Options",
184
+ defaultCollapsed: true,
185
+ fields: [
186
+ "isCaseSensitive",
187
+ "includeScore",
188
+ "includeMatches",
189
+ "minMatchCharLength",
190
+ "shouldSort",
191
+ "findAllMatches",
192
+ ]
193
+ },
194
+ {
195
+ key: "fuzzyOptions",
196
+ label: "Fuzzy Matching Options",
197
+ defaultCollapsed: true,
198
+ fields: [
199
+ "location",
200
+ "threshold",
201
+ "distance",
202
+ "ignoreLocation",
203
+ ]
204
+ }
205
+ ],
206
+ form: [
207
+ { type: "field", key: "searchPattern" },
208
+ { type: "field", key: "items" },
209
+ { type: "section", key: "basicOptions" },
210
+ { type: "section", key: "fuzzyOptions" },
211
+ { type: "section", key: "storageOption" }
212
+ ],
213
+ function: async ({ cognigy, config }) => {
214
+ const { api } = cognigy;
215
+ const { searchPattern, items, distance, findAllMatches, ignoreLocation, includeMatches, includeScore, isCaseSensitive, location, minMatchCharLength, shouldSort, threshold, storeLocation, inputKey, contextKey } = config;
216
+ if (!searchPattern)
217
+ throw new Error("No search pattern provided.");
218
+ if (!items)
219
+ throw new Error("No source data provided.");
220
+ try {
221
+ // reverse threshold as fuse requires it inverse (0 = perfect match, 1 = matches everything)
222
+ const newThreshold = 1 - threshold;
223
+ const options = {
224
+ distance,
225
+ findAllMatches,
226
+ ignoreLocation,
227
+ includeMatches,
228
+ includeScore,
229
+ isCaseSensitive,
230
+ location,
231
+ minMatchCharLength,
232
+ shouldSort,
233
+ threshold: newThreshold,
234
+ };
235
+ const validObjectSize = objectSizeValidator_1.validateObjectSize(items, getFuzzySearchMaxObjectSizeInBytes());
236
+ let result = null;
237
+ if (validObjectSize.valid) {
238
+ result = api.fuseSearch(items, options, searchPattern);
239
+ // reverse scores from fuse's 0 = perfect match to Cognigy's 1 = perfect match.
240
+ if (includeScore && result && Array.isArray(result) && result.length > 0) {
241
+ result.forEach((item) => {
242
+ if (item.score || item.score === 0) {
243
+ item.score = 1 - item.score;
244
+ }
245
+ });
246
+ }
247
+ }
248
+ else {
249
+ result = {
250
+ "error": `Source data file size limit (${getFuzzySearchMaxObjectSizeInBytes()} bytes) exceeded`
251
+ };
252
+ }
253
+ if (storeLocation === "context") {
254
+ api.addToContext(contextKey, result, "simple");
255
+ }
256
+ else {
257
+ api.addToInput(inputKey, result);
258
+ }
259
+ }
260
+ catch (error) {
261
+ if (storeLocation === "context") {
262
+ api.addToContext(contextKey, error, "simple");
263
+ }
264
+ else {
265
+ api.addToInput(inputKey, error);
266
+ }
267
+ }
268
+ }
269
+ });
270
+ //# sourceMappingURL=fuzzySearch.js.map
@@ -1,10 +1,16 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.REGEX_SLOT_FILLER = exports.EXECUTE_COGNIGY_NLU = exports.ADD_LEXICON_KEYPHRASE = void 0;
3
+ exports.FUZZY_SEARCH = exports.MATCH_PATTERN = exports.REGEX_SLOT_FILLER = exports.EXTRACT_ANSWER = exports.EXECUTE_COGNIGY_NLU = exports.ADD_LEXICON_KEYPHRASE = void 0;
4
4
  var addLexiconKeyphrase_1 = require("./addLexiconKeyphrase");
5
5
  Object.defineProperty(exports, "ADD_LEXICON_KEYPHRASE", { enumerable: true, get: function () { return addLexiconKeyphrase_1.ADD_LEXICON_KEYPHRASE; } });
6
6
  var executeCognigyNLU_1 = require("./executeCognigyNLU");
7
7
  Object.defineProperty(exports, "EXECUTE_COGNIGY_NLU", { enumerable: true, get: function () { return executeCognigyNLU_1.EXECUTE_COGNIGY_NLU; } });
8
+ var extractAnswer_1 = require("./extractAnswer");
9
+ Object.defineProperty(exports, "EXTRACT_ANSWER", { enumerable: true, get: function () { return extractAnswer_1.EXTRACT_ANSWER; } });
8
10
  var regexSlotFiller_1 = require("./regexSlotFiller");
9
11
  Object.defineProperty(exports, "REGEX_SLOT_FILLER", { enumerable: true, get: function () { return regexSlotFiller_1.REGEX_SLOT_FILLER; } });
12
+ var matchPattern_1 = require("./matchPattern");
13
+ Object.defineProperty(exports, "MATCH_PATTERN", { enumerable: true, get: function () { return matchPattern_1.MATCH_PATTERN; } });
14
+ var fuzzySearch_1 = require("./fuzzySearch");
15
+ Object.defineProperty(exports, "FUZZY_SEARCH", { enumerable: true, get: function () { return fuzzySearch_1.FUZZY_SEARCH; } });
10
16
  //# sourceMappingURL=index.js.map
@@ -0,0 +1,104 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.MATCH_PATTERN = void 0;
4
+ const createNodeDescriptor_1 = require("../../createNodeDescriptor");
5
+ const patternMatcher_1 = require("./utils/patternMatcher");
6
+ exports.MATCH_PATTERN = createNodeDescriptor_1.createNodeDescriptor({
7
+ type: "matchPattern",
8
+ defaultLabel: "Match Pattern",
9
+ preview: {
10
+ key: "patternGroupName",
11
+ type: "text"
12
+ },
13
+ summary: "Rule-based pattern matching for compound slot groups",
14
+ tags: ["nlu", "pattern", "patterns"],
15
+ fields: [
16
+ {
17
+ key: "patterns",
18
+ label: "Patterns",
19
+ type: "textArray",
20
+ description: "The patterns to match, e.g. 'from @city>origin to @city>destination'. Maximum: 20.",
21
+ defaultValue: ["@NUMBER>val1 or @NUMBER>val2"]
22
+ },
23
+ {
24
+ key: "patternGroupName",
25
+ label: "Pattern Group Name",
26
+ description: "Name for the slot compound group to be found under input.matchedPatterns.groupname",
27
+ type: "cognigyText",
28
+ defaultValue: "patternGroupName",
29
+ params: {
30
+ required: true
31
+ },
32
+ },
33
+ {
34
+ key: "alternateInput",
35
+ label: "Alternate Input",
36
+ description: "The input text to use instead of the current input text",
37
+ type: "cognigyText",
38
+ },
39
+ {
40
+ key: "detailedCompoundSlots",
41
+ label: "Detailed Match Results",
42
+ description: "Whether to store detailed results for the matched patterns or not",
43
+ type: "toggle",
44
+ defaultValue: false
45
+ },
46
+ {
47
+ key: "createNewSlots",
48
+ label: "Create New Slots",
49
+ description: "Whether to create new slots from tags or not",
50
+ type: "toggle",
51
+ defaultValue: false
52
+ },
53
+ {
54
+ key: "tagExistingSlots",
55
+ label: "Tag Existing Slots",
56
+ description: "Whether to tag existing slots or not",
57
+ type: "toggle",
58
+ defaultValue: true
59
+ }
60
+ ],
61
+ sections: [
62
+ {
63
+ key: "advanced",
64
+ label: "Advanced",
65
+ defaultCollapsed: true,
66
+ fields: [
67
+ "createNewSlots",
68
+ "tagExistingSlots",
69
+ "detailedCompoundSlots",
70
+ "alternateInput"
71
+ ]
72
+ }
73
+ ],
74
+ form: [
75
+ { type: "field", key: "patterns" },
76
+ { type: "field", key: "patternGroupName" },
77
+ { type: "section", key: "advanced" }
78
+ ],
79
+ function: async ({ cognigy, config }) => {
80
+ let { input, api } = cognigy;
81
+ const { patterns, patternGroupName, alternateInput, detailedCompoundSlots, createNewSlots, tagExistingSlots } = config;
82
+ if (!patterns || !Array.isArray(patterns) || patterns.length === 0) {
83
+ throw new Error("No patterns to match specified");
84
+ }
85
+ if (patterns.length > 20) {
86
+ throw new Error("Maximum of 20 patterns allowed");
87
+ }
88
+ // When using an alternative input, input.slots is empty - we need to call the cognigy nlu again to get the slots
89
+ let nluResult = {};
90
+ if (alternateInput) {
91
+ nluResult = await api.executeCognigyNLU(alternateInput, {}, input.inputId, {});
92
+ }
93
+ patternMatcher_1.patternMatcher({
94
+ input,
95
+ patterns,
96
+ patternGroupName,
97
+ detailedCompoundSlots,
98
+ tagExistingSlots,
99
+ createNewSlots,
100
+ nluResult
101
+ });
102
+ }
103
+ });
104
+ //# sourceMappingURL=matchPattern.js.map
@@ -0,0 +1,197 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.patternMatcher = void 0;
4
+ /**
5
+ * Finds compound slots using pattern inside the user input
6
+ * @param input Cognigy Input Object
7
+ * @param patterns The patterns to check for
8
+ * @param patternGroupName Name for the compound group
9
+ * @param detailedCompoundSlots Store detailed results for compound slots
10
+ * @param tagExistingSlots Tag existing slots
11
+ * @param createNewSlots Create new slots from tags
12
+ * @param nluResult result from cognigy NLU since there was an alternative input
13
+ */
14
+ const patternMatcher = (params) => {
15
+ const { input, patternGroupName, detailedCompoundSlots, tagExistingSlots, createNewSlots, nluResult } = params;
16
+ let { patterns } = params;
17
+ // prune patterns if more than 20
18
+ if (patterns.length > 20) {
19
+ patterns = patterns.slice(0, 20);
20
+ }
21
+ // firstly sort array to start with the longest patterns, as those will win
22
+ patterns.sort((a, b) => {
23
+ return b.length - a.length;
24
+ });
25
+ // we use let because we strip out found phrases later
26
+ let inputText = nluResult.text || input.text; // ci.processText
27
+ let inputSlots = nluResult.slots || input.slots;
28
+ const regexPatterns = [];
29
+ // go through patterns and create regex versions of each that is not empty string
30
+ patterns.forEach((pattern) => {
31
+ if (pattern) {
32
+ // set parsedPattern to pattern in case there are no slots
33
+ let parsedPattern = pattern;
34
+ // match all mentioned slots in the pattern
35
+ const foundSlots = pattern.match(/\@[\w>]+/g);
36
+ const tags = [];
37
+ const slots = [];
38
+ // if there are slots, process them
39
+ if (Array.isArray(foundSlots) && foundSlots.length > 0) {
40
+ foundSlots.forEach((slot) => {
41
+ // splits tags from slots
42
+ const split = slot.split(">");
43
+ const slotName = split[0].replace("@", "");
44
+ slots.push(slotName);
45
+ // if there is a tag (SLOT>TAG), remember it
46
+ if (split.length === 2)
47
+ tags.push(split[1]);
48
+ else
49
+ tags.push("");
50
+ const slotValues = [];
51
+ if (inputSlots[slotName]) {
52
+ switch (slotName) {
53
+ case "DATE":
54
+ inputSlots.DATE.forEach((s) => {
55
+ // just add the number
56
+ if (s.start)
57
+ slotValues.push(s["text"]);
58
+ });
59
+ break;
60
+ case "TEMPERATURE":
61
+ inputSlots.TEMPERATURE.forEach((s) => {
62
+ // just add the number
63
+ slotValues.push(s.value);
64
+ });
65
+ break;
66
+ case "AGE":
67
+ inputSlots.AGE.forEach((s) => {
68
+ // just add the number
69
+ slotValues.push(s.value);
70
+ });
71
+ break;
72
+ case "PERCENTAGE":
73
+ inputSlots.PERCENTAGE.forEach((s) => {
74
+ // just add the number
75
+ slotValues.push(s + "%");
76
+ slotValues.push(s + " percent");
77
+ });
78
+ break;
79
+ case "NUMBER":
80
+ inputSlots.NUMBER.forEach((s) => {
81
+ // just add the number
82
+ slotValues.push(s);
83
+ });
84
+ break;
85
+ default:
86
+ inputSlots[slotName].forEach((s) => {
87
+ // it's important to use the synonym, as this is the text that was actually found
88
+ slotValues.push(s.synonym);
89
+ });
90
+ }
91
+ const slotRegex = slotValues.join("|");
92
+ // replace the slots name with the list of actually found entites for this slot
93
+ parsedPattern = parsedPattern.replace(new RegExp(`${slot}`, "g"), `(${slotRegex})`);
94
+ }
95
+ });
96
+ }
97
+ regexPatterns.push({
98
+ "pattern": pattern,
99
+ "parsedPattern": parsedPattern,
100
+ "tags": tags,
101
+ "slots": slots
102
+ });
103
+ }
104
+ });
105
+ const compoundGroups = [];
106
+ // go through all created patterns and test them
107
+ regexPatterns.forEach((pattern) => {
108
+ let result;
109
+ const regExp = new RegExp(pattern.parsedPattern, "gi");
110
+ const regexMatches = [];
111
+ while (result = regExp.exec(inputText)) {
112
+ regexMatches.push(result);
113
+ }
114
+ regexMatches.forEach((m) => {
115
+ inputText = inputText.replace(m[0], "");
116
+ });
117
+ if (regexMatches.length > 0) {
118
+ // we found a match for this pattern!
119
+ regexMatches.forEach((matches, mi) => {
120
+ // set up a compoundGroup scaffold, just in case we need it
121
+ const matchedPatternGroup = {
122
+ "matchedPhrase": matches[0],
123
+ "components": []
124
+ };
125
+ if (!detailedCompoundSlots)
126
+ delete matchedPatternGroup.components;
127
+ // iterate through matches, starting at the first group result ([0] is the full match)
128
+ for (let i = 1; i < matches.length; i++) {
129
+ let originalSlot = null;
130
+ switch (pattern.slots[i - 1]) {
131
+ case "PERCENTAGE":
132
+ originalSlot = Number(matches[i].replace(new RegExp("[^0-9]", "gi"), ""));
133
+ break;
134
+ case "TEMPERATURE":
135
+ case "AGE":
136
+ case "NUMBER":
137
+ originalSlot = Number(matches[i]);
138
+ break;
139
+ case "DATE":
140
+ // @ts-ignore
141
+ const dateSlot = inputSlots.DATE.find(e => (e["text"] === matches[i]));
142
+ originalSlot = (dateSlot === null || dateSlot === void 0 ? void 0 : dateSlot.start) || (dateSlot === null || dateSlot === void 0 ? void 0 : dateSlot.end);
143
+ break;
144
+ default:
145
+ originalSlot = inputSlots[pattern.slots[i - 1]].find(e => (e.synonym) ? e.synonym.toLowerCase() === matches[i].toLowerCase() : false);
146
+ }
147
+ // create compound groups
148
+ if (detailedCompoundSlots) {
149
+ const components = {
150
+ "slot": pattern.slots[i - 1],
151
+ "value": originalSlot.keyphrase || originalSlot
152
+ };
153
+ if (pattern.tags[i - 1])
154
+ components["tag"] = pattern.tags[i - 1];
155
+ else
156
+ components["tag"] = null;
157
+ matchedPatternGroup.components.push(components);
158
+ }
159
+ else {
160
+ if (pattern.tags[i - 1])
161
+ matchedPatternGroup[pattern.tags[i - 1]] = (originalSlot === null || originalSlot === void 0 ? void 0 : originalSlot.keyphrase) || originalSlot;
162
+ else
163
+ matchedPatternGroup[pattern.slots[i - 1]] = originalSlot || originalSlot.keyphrase;
164
+ }
165
+ if (pattern.tags[i - 1]) {
166
+ if (createNewSlots) {
167
+ if (inputSlots[pattern.tags[i - 1]]) {
168
+ inputSlots[pattern.tags[i - 1]].push(originalSlot);
169
+ }
170
+ else
171
+ inputSlots[pattern.tags[i - 1]] = [originalSlot];
172
+ }
173
+ if (tagExistingSlots) {
174
+ inputSlots[pattern.slots[i - 1]].forEach((s) => {
175
+ var _a, _b;
176
+ if (((_a = s === null || s === void 0 ? void 0 : s.synonym) === null || _a === void 0 ? void 0 : _a.toLowerCase()) === ((_b = matches[i]) === null || _b === void 0 ? void 0 : _b.toLowerCase())) {
177
+ s["tags"] = (Array.isArray(s["tags"])) ? s["tags"].push(pattern.tags[i - 1]) : [pattern.tags[i - 1]];
178
+ }
179
+ });
180
+ }
181
+ }
182
+ }
183
+ compoundGroups.push(matchedPatternGroup);
184
+ });
185
+ }
186
+ });
187
+ if (!input["matchedPatterns"])
188
+ input["matchedPatterns"] = {};
189
+ if (compoundGroups && Array.isArray(compoundGroups) && compoundGroups.length > 0) {
190
+ input["matchedPatterns"][patternGroupName] = compoundGroups;
191
+ }
192
+ if (compoundGroups && compoundGroups.length === 0 && (typeof input["matchedPatterns"] !== 'object' || Object.keys(input["matchedPatterns"]).length === 0))
193
+ delete input["matchedPatterns"];
194
+ return input;
195
+ };
196
+ exports.patternMatcher = patternMatcher;
197
+ //# sourceMappingURL=patternMatcher.js.map
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.OVERWRITE_ANALYTICS = exports.BLIND_MODE = exports.UPDATE_PROFILE = exports.MERGE_PROFILE = exports.DELETE_PROFILE = exports.DEACTIVATE_PROFILE = exports.COMPLETE_GOAL = exports.ACTIVATE_PROFILE = void 0;
3
+ exports.REQUEST_RATING = exports.SET_RATING = exports.OVERWRITE_ANALYTICS = exports.BLIND_MODE = exports.UPDATE_PROFILE = exports.MERGE_PROFILE = exports.DELETE_PROFILE = exports.DEACTIVATE_PROFILE = exports.COMPLETE_GOAL = exports.ACTIVATE_PROFILE = void 0;
4
4
  var activateProfile_1 = require("./activateProfile");
5
5
  Object.defineProperty(exports, "ACTIVATE_PROFILE", { enumerable: true, get: function () { return activateProfile_1.ACTIVATE_PROFILE; } });
6
6
  var completeGoal_1 = require("./completeGoal");
@@ -17,4 +17,8 @@ var blindMode_1 = require("./blindMode");
17
17
  Object.defineProperty(exports, "BLIND_MODE", { enumerable: true, get: function () { return blindMode_1.BLIND_MODE; } });
18
18
  var overwriteAnalytics_1 = require("./overwriteAnalytics");
19
19
  Object.defineProperty(exports, "OVERWRITE_ANALYTICS", { enumerable: true, get: function () { return overwriteAnalytics_1.OVERWRITE_ANALYTICS; } });
20
+ var setRating_1 = require("./setRating");
21
+ Object.defineProperty(exports, "SET_RATING", { enumerable: true, get: function () { return setRating_1.SET_RATING; } });
22
+ var requestRating_1 = require("./requestRating");
23
+ Object.defineProperty(exports, "REQUEST_RATING", { enumerable: true, get: function () { return requestRating_1.REQUEST_RATING; } });
20
24
  //# sourceMappingURL=index.js.map