@microsoft/agents-hosting-dialogs 0.1.49

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 (325) hide show
  1. package/dist/index.js +20 -0
  2. package/dist/src/agentComponent.d.ts +18 -0
  3. package/dist/src/agentComponent.js +55 -0
  4. package/dist/src/agentComponent.js.map +1 -0
  5. package/dist/src/agentStateSet.d.ts +48 -0
  6. package/dist/src/agentStateSet.js +66 -0
  7. package/dist/src/agentStateSet.js.map +1 -0
  8. package/dist/src/choices/choice.d.ts +14 -0
  9. package/dist/src/choices/choice.js +7 -0
  10. package/dist/src/choices/choice.js.map +1 -0
  11. package/dist/src/choices/choiceFactory.d.ts +81 -0
  12. package/dist/src/choices/choiceFactory.js +133 -0
  13. package/dist/src/choices/choiceFactory.js.map +1 -0
  14. package/dist/src/choices/findChoices.d.ts +28 -0
  15. package/dist/src/choices/findChoices.js +46 -0
  16. package/dist/src/choices/findChoices.js.map +1 -0
  17. package/dist/src/choices/findValues.d.ts +36 -0
  18. package/dist/src/choices/findValues.js +129 -0
  19. package/dist/src/choices/findValues.js.map +1 -0
  20. package/dist/src/choices/index.d.ts +11 -0
  21. package/dist/src/choices/index.js +28 -0
  22. package/dist/src/choices/index.js.map +1 -0
  23. package/dist/src/choices/modelResult.d.ts +11 -0
  24. package/dist/src/choices/modelResult.js +3 -0
  25. package/dist/src/choices/modelResult.js.map +1 -0
  26. package/dist/src/choices/recognizeChoices.d.ts +16 -0
  27. package/dist/src/choices/recognizeChoices.js +81 -0
  28. package/dist/src/choices/recognizeChoices.js.map +1 -0
  29. package/dist/src/choices/tokenizer.d.ts +25 -0
  30. package/dist/src/choices/tokenizer.js +73 -0
  31. package/dist/src/choices/tokenizer.js.map +1 -0
  32. package/dist/src/componentDialog.d.ts +178 -0
  33. package/dist/src/componentDialog.js +252 -0
  34. package/dist/src/componentDialog.js.map +1 -0
  35. package/dist/src/componentRegistration.d.ts +22 -0
  36. package/dist/src/componentRegistration.js +32 -0
  37. package/dist/src/componentRegistration.js.map +1 -0
  38. package/dist/src/configurable.d.ts +22 -0
  39. package/dist/src/configurable.js +60 -0
  40. package/dist/src/configurable.js.map +1 -0
  41. package/dist/src/configuration.d.ts +11 -0
  42. package/dist/src/configuration.js +17 -0
  43. package/dist/src/configuration.js.map +1 -0
  44. package/dist/src/converter.d.ts +13 -0
  45. package/dist/src/converter.js +7 -0
  46. package/dist/src/converter.js.map +1 -0
  47. package/dist/src/dialog.d.ts +184 -0
  48. package/dist/src/dialog.js +201 -0
  49. package/dist/src/dialog.js.map +1 -0
  50. package/dist/src/dialogContainer.d.ts +61 -0
  51. package/dist/src/dialogContainer.js +82 -0
  52. package/dist/src/dialogContainer.js.map +1 -0
  53. package/dist/src/dialogContext.d.ts +272 -0
  54. package/dist/src/dialogContext.js +444 -0
  55. package/dist/src/dialogContext.js.map +1 -0
  56. package/dist/src/dialogContextError.d.ts +27 -0
  57. package/dist/src/dialogContextError.js +39 -0
  58. package/dist/src/dialogContextError.js.map +1 -0
  59. package/dist/src/dialogEvent.d.ts +20 -0
  60. package/dist/src/dialogEvent.js +3 -0
  61. package/dist/src/dialogEvent.js.map +1 -0
  62. package/dist/src/dialogEvents.d.ts +15 -0
  63. package/dist/src/dialogEvents.js +20 -0
  64. package/dist/src/dialogEvents.js.map +1 -0
  65. package/dist/src/dialogHelper.d.ts +32 -0
  66. package/dist/src/dialogHelper.js +116 -0
  67. package/dist/src/dialogHelper.js.map +1 -0
  68. package/dist/src/dialogInstance.d.ts +30 -0
  69. package/dist/src/dialogInstance.js +3 -0
  70. package/dist/src/dialogInstance.js.map +1 -0
  71. package/dist/src/dialogManager.d.ts +73 -0
  72. package/dist/src/dialogManager.js +156 -0
  73. package/dist/src/dialogManager.js.map +1 -0
  74. package/dist/src/dialogReason.d.ts +35 -0
  75. package/dist/src/dialogReason.js +40 -0
  76. package/dist/src/dialogReason.js.map +1 -0
  77. package/dist/src/dialogSet.d.ts +85 -0
  78. package/dist/src/dialogSet.js +138 -0
  79. package/dist/src/dialogSet.js.map +1 -0
  80. package/dist/src/dialogTurnResult.d.ts +34 -0
  81. package/dist/src/dialogTurnResult.js +3 -0
  82. package/dist/src/dialogTurnResult.js.map +1 -0
  83. package/dist/src/dialogTurnStateConstants.d.ts +12 -0
  84. package/dist/src/dialogTurnStateConstants.js +17 -0
  85. package/dist/src/dialogTurnStateConstants.js.map +1 -0
  86. package/dist/src/dialogTurnStatus.d.ts +34 -0
  87. package/dist/src/dialogTurnStatus.js +39 -0
  88. package/dist/src/dialogTurnStatus.js.map +1 -0
  89. package/dist/src/dialogsAgentComponent.d.ts +17 -0
  90. package/dist/src/dialogsAgentComponent.js +65 -0
  91. package/dist/src/dialogsAgentComponent.js.map +1 -0
  92. package/dist/src/dialogsComponentRegistration.d.ts +28 -0
  93. package/dist/src/dialogsComponentRegistration.js +45 -0
  94. package/dist/src/dialogsComponentRegistration.js.map +1 -0
  95. package/dist/src/i18n.d.ts +15 -0
  96. package/dist/src/i18n.js +28 -0
  97. package/dist/src/i18n.js.map +1 -0
  98. package/dist/src/index.d.ts +29 -0
  99. package/dist/src/index.js +48 -0
  100. package/dist/src/index.js.map +1 -0
  101. package/dist/src/intentScore.d.ts +11 -0
  102. package/dist/src/intentScore.js +3 -0
  103. package/dist/src/intentScore.js.map +1 -0
  104. package/dist/src/memory/componentMemoryScopes.d.ts +18 -0
  105. package/dist/src/memory/componentMemoryScopes.js +54 -0
  106. package/dist/src/memory/componentMemoryScopes.js.map +1 -0
  107. package/dist/src/memory/componentPathResolvers.d.ts +18 -0
  108. package/dist/src/memory/componentPathResolvers.js +52 -0
  109. package/dist/src/memory/componentPathResolvers.js.map +1 -0
  110. package/dist/src/memory/dialogPath.d.ts +17 -0
  111. package/dist/src/memory/dialogPath.js +30 -0
  112. package/dist/src/memory/dialogPath.js.map +1 -0
  113. package/dist/src/memory/dialogStateManager.d.ts +156 -0
  114. package/dist/src/memory/dialogStateManager.js +598 -0
  115. package/dist/src/memory/dialogStateManager.js.map +1 -0
  116. package/dist/src/memory/index.d.ts +12 -0
  117. package/dist/src/memory/index.js +29 -0
  118. package/dist/src/memory/index.js.map +1 -0
  119. package/dist/src/memory/pathResolvers/aliasPathResolver.d.ts +25 -0
  120. package/dist/src/memory/pathResolvers/aliasPathResolver.js +37 -0
  121. package/dist/src/memory/pathResolvers/aliasPathResolver.js.map +1 -0
  122. package/dist/src/memory/pathResolvers/atAtPathResolver.d.ts +11 -0
  123. package/dist/src/memory/pathResolvers/atAtPathResolver.js +18 -0
  124. package/dist/src/memory/pathResolvers/atAtPathResolver.js.map +1 -0
  125. package/dist/src/memory/pathResolvers/atPathResolver.d.ts +20 -0
  126. package/dist/src/memory/pathResolvers/atPathResolver.js +46 -0
  127. package/dist/src/memory/pathResolvers/atPathResolver.js.map +1 -0
  128. package/dist/src/memory/pathResolvers/dollarPathResolver.d.ts +11 -0
  129. package/dist/src/memory/pathResolvers/dollarPathResolver.js +18 -0
  130. package/dist/src/memory/pathResolvers/dollarPathResolver.js.map +1 -0
  131. package/dist/src/memory/pathResolvers/hashPathResolver.d.ts +11 -0
  132. package/dist/src/memory/pathResolvers/hashPathResolver.js +18 -0
  133. package/dist/src/memory/pathResolvers/hashPathResolver.js.map +1 -0
  134. package/dist/src/memory/pathResolvers/index.d.ts +11 -0
  135. package/dist/src/memory/pathResolvers/index.js +28 -0
  136. package/dist/src/memory/pathResolvers/index.js.map +1 -0
  137. package/dist/src/memory/pathResolvers/pathResolver.d.ts +13 -0
  138. package/dist/src/memory/pathResolvers/pathResolver.js +7 -0
  139. package/dist/src/memory/pathResolvers/pathResolver.js.map +1 -0
  140. package/dist/src/memory/pathResolvers/percentPathResolver.d.ts +11 -0
  141. package/dist/src/memory/pathResolvers/percentPathResolver.js +18 -0
  142. package/dist/src/memory/pathResolvers/percentPathResolver.js.map +1 -0
  143. package/dist/src/memory/scopePath.d.ts +18 -0
  144. package/dist/src/memory/scopePath.js +23 -0
  145. package/dist/src/memory/scopePath.js.map +1 -0
  146. package/dist/src/memory/scopes/agentStateMemoryScope.d.ts +53 -0
  147. package/dist/src/memory/scopes/agentStateMemoryScope.js +82 -0
  148. package/dist/src/memory/scopes/agentStateMemoryScope.js.map +1 -0
  149. package/dist/src/memory/scopes/classMemoryScope.d.ts +29 -0
  150. package/dist/src/memory/scopes/classMemoryScope.js +65 -0
  151. package/dist/src/memory/scopes/classMemoryScope.js.map +1 -0
  152. package/dist/src/memory/scopes/conversationMemoryScope.d.ts +15 -0
  153. package/dist/src/memory/scopes/conversationMemoryScope.js +23 -0
  154. package/dist/src/memory/scopes/conversationMemoryScope.js.map +1 -0
  155. package/dist/src/memory/scopes/dialogClassMemoryScope.d.ts +19 -0
  156. package/dist/src/memory/scopes/dialogClassMemoryScope.js +42 -0
  157. package/dist/src/memory/scopes/dialogClassMemoryScope.js.map +1 -0
  158. package/dist/src/memory/scopes/dialogContextMemoryScope.d.ts +19 -0
  159. package/dist/src/memory/scopes/dialogContextMemoryScope.js +48 -0
  160. package/dist/src/memory/scopes/dialogContextMemoryScope.js.map +1 -0
  161. package/dist/src/memory/scopes/dialogMemoryScope.d.ts +32 -0
  162. package/dist/src/memory/scopes/dialogMemoryScope.js +74 -0
  163. package/dist/src/memory/scopes/dialogMemoryScope.js.map +1 -0
  164. package/dist/src/memory/scopes/index.d.ts +15 -0
  165. package/dist/src/memory/scopes/index.js +32 -0
  166. package/dist/src/memory/scopes/index.js.map +1 -0
  167. package/dist/src/memory/scopes/memoryScope.d.ts +52 -0
  168. package/dist/src/memory/scopes/memoryScope.js +54 -0
  169. package/dist/src/memory/scopes/memoryScope.js.map +1 -0
  170. package/dist/src/memory/scopes/settingsMemoryScope.d.ts +68 -0
  171. package/dist/src/memory/scopes/settingsMemoryScope.js +216 -0
  172. package/dist/src/memory/scopes/settingsMemoryScope.js.map +1 -0
  173. package/dist/src/memory/scopes/thisMemoryScope.d.ts +26 -0
  174. package/dist/src/memory/scopes/thisMemoryScope.js +43 -0
  175. package/dist/src/memory/scopes/thisMemoryScope.js.map +1 -0
  176. package/dist/src/memory/scopes/turnMemoryScope.d.ts +29 -0
  177. package/dist/src/memory/scopes/turnMemoryScope.js +52 -0
  178. package/dist/src/memory/scopes/turnMemoryScope.js.map +1 -0
  179. package/dist/src/memory/scopes/userMemoryScope.d.ts +15 -0
  180. package/dist/src/memory/scopes/userMemoryScope.js +23 -0
  181. package/dist/src/memory/scopes/userMemoryScope.js.map +1 -0
  182. package/dist/src/memory/turnPath.d.ts +21 -0
  183. package/dist/src/memory/turnPath.js +38 -0
  184. package/dist/src/memory/turnPath.js.map +1 -0
  185. package/dist/src/prompts/activityPrompt.d.ts +101 -0
  186. package/dist/src/prompts/activityPrompt.js +166 -0
  187. package/dist/src/prompts/activityPrompt.js.map +1 -0
  188. package/dist/src/prompts/attachmentPrompt.d.ts +37 -0
  189. package/dist/src/prompts/attachmentPrompt.js +55 -0
  190. package/dist/src/prompts/attachmentPrompt.js.map +1 -0
  191. package/dist/src/prompts/choicePrompt.d.ts +83 -0
  192. package/dist/src/prompts/choicePrompt.js +116 -0
  193. package/dist/src/prompts/choicePrompt.js.map +1 -0
  194. package/dist/src/prompts/confirmPrompt.d.ts +82 -0
  195. package/dist/src/prompts/confirmPrompt.js +163 -0
  196. package/dist/src/prompts/confirmPrompt.js.map +1 -0
  197. package/dist/src/prompts/datetimePrompt.d.ts +65 -0
  198. package/dist/src/prompts/datetimePrompt.js +109 -0
  199. package/dist/src/prompts/datetimePrompt.js.map +1 -0
  200. package/dist/src/prompts/index.d.ts +13 -0
  201. package/dist/src/prompts/index.js +30 -0
  202. package/dist/src/prompts/index.js.map +1 -0
  203. package/dist/src/prompts/numberPrompt.d.ts +55 -0
  204. package/dist/src/prompts/numberPrompt.js +134 -0
  205. package/dist/src/prompts/numberPrompt.js.map +1 -0
  206. package/dist/src/prompts/prompt.d.ts +256 -0
  207. package/dist/src/prompts/prompt.js +260 -0
  208. package/dist/src/prompts/prompt.js.map +1 -0
  209. package/dist/src/prompts/promptCultureModels.d.ts +72 -0
  210. package/dist/src/prompts/promptCultureModels.js +123 -0
  211. package/dist/src/prompts/promptCultureModels.js.map +1 -0
  212. package/dist/src/prompts/textPrompt.d.ts +54 -0
  213. package/dist/src/prompts/textPrompt.js +72 -0
  214. package/dist/src/prompts/textPrompt.js.map +1 -0
  215. package/dist/src/recognizer.d.ts +43 -0
  216. package/dist/src/recognizer.js +104 -0
  217. package/dist/src/recognizer.js.map +1 -0
  218. package/dist/src/recognizerResult.d.ts +19 -0
  219. package/dist/src/recognizerResult.js +24 -0
  220. package/dist/src/recognizerResult.js.map +1 -0
  221. package/dist/src/serviceCollection.d.ts +112 -0
  222. package/dist/src/serviceCollection.js +209 -0
  223. package/dist/src/serviceCollection.js.map +1 -0
  224. package/dist/src/stringUtils.d.ts +36 -0
  225. package/dist/src/stringUtils.js +62 -0
  226. package/dist/src/stringUtils.js.map +1 -0
  227. package/dist/src/template.d.ts +18 -0
  228. package/dist/src/template.js +7 -0
  229. package/dist/src/template.js.map +1 -0
  230. package/dist/src/waterfallDialog.d.ts +101 -0
  231. package/dist/src/waterfallDialog.js +179 -0
  232. package/dist/src/waterfallDialog.js.map +1 -0
  233. package/dist/src/waterfallStepContext.d.ts +71 -0
  234. package/dist/src/waterfallStepContext.js +78 -0
  235. package/dist/src/waterfallStepContext.js.map +1 -0
  236. package/package.json +49 -0
  237. package/src/agentComponent.ts +23 -0
  238. package/src/agentStateSet.ts +75 -0
  239. package/src/choices/choice.ts +16 -0
  240. package/src/choices/choiceFactory.ts +189 -0
  241. package/src/choices/findChoices.ts +70 -0
  242. package/src/choices/findValues.ts +179 -0
  243. package/src/choices/index.ts +11 -0
  244. package/src/choices/modelResult.ts +11 -0
  245. package/src/choices/recognizeChoices.ts +94 -0
  246. package/src/choices/tokenizer.ts +93 -0
  247. package/src/componentDialog.ts +306 -0
  248. package/src/componentRegistration.ts +30 -0
  249. package/src/configurable.ts +55 -0
  250. package/src/configuration.ts +22 -0
  251. package/src/converter.ts +15 -0
  252. package/src/dialog.ts +243 -0
  253. package/src/dialogContainer.ts +90 -0
  254. package/src/dialogContext.ts +607 -0
  255. package/src/dialogContextError.ts +50 -0
  256. package/src/dialogEvent.ts +23 -0
  257. package/src/dialogEvents.ts +16 -0
  258. package/src/dialogHelper.ts +154 -0
  259. package/src/dialogInstance.ts +32 -0
  260. package/src/dialogManager.ts +202 -0
  261. package/src/dialogReason.ts +40 -0
  262. package/src/dialogSet.ts +168 -0
  263. package/src/dialogTurnResult.ts +37 -0
  264. package/src/dialogTurnStateConstants.ts +13 -0
  265. package/src/dialogTurnStatus.ts +38 -0
  266. package/src/dialogsAgentComponent.ts +71 -0
  267. package/src/dialogsComponentRegistration.ts +49 -0
  268. package/src/i18n.ts +17 -0
  269. package/src/index.ts +31 -0
  270. package/src/intentScore.ts +11 -0
  271. package/src/memory/componentMemoryScopes.ts +28 -0
  272. package/src/memory/componentPathResolvers.ts +29 -0
  273. package/src/memory/dialogPath.ts +33 -0
  274. package/src/memory/dialogStateManager.ts +661 -0
  275. package/src/memory/index.ts +12 -0
  276. package/src/memory/pathResolvers/aliasPathResolver.ts +44 -0
  277. package/src/memory/pathResolvers/atAtPathResolver.ts +14 -0
  278. package/src/memory/pathResolvers/atPathResolver.ts +45 -0
  279. package/src/memory/pathResolvers/dollarPathResolver.ts +14 -0
  280. package/src/memory/pathResolvers/hashPathResolver.ts +14 -0
  281. package/src/memory/pathResolvers/index.ts +11 -0
  282. package/src/memory/pathResolvers/pathResolver.ts +14 -0
  283. package/src/memory/pathResolvers/percentPathResolver.ts +14 -0
  284. package/src/memory/scopePath.ts +19 -0
  285. package/src/memory/scopes/agentStateMemoryScope.ts +92 -0
  286. package/src/memory/scopes/classMemoryScope.ts +71 -0
  287. package/src/memory/scopes/conversationMemoryScope.ts +19 -0
  288. package/src/memory/scopes/dialogClassMemoryScope.ts +43 -0
  289. package/src/memory/scopes/dialogContextMemoryScope.ts +51 -0
  290. package/src/memory/scopes/dialogMemoryScope.ts +79 -0
  291. package/src/memory/scopes/index.ts +15 -0
  292. package/src/memory/scopes/memoryScope.ts +70 -0
  293. package/src/memory/scopes/settingsMemoryScope.ts +239 -0
  294. package/src/memory/scopes/thisMemoryScope.ts +44 -0
  295. package/src/memory/scopes/turnMemoryScope.ts +54 -0
  296. package/src/memory/scopes/userMemoryScope.ts +19 -0
  297. package/src/memory/turnPath.ts +45 -0
  298. package/src/prompts/activityPrompt.ts +202 -0
  299. package/src/prompts/attachmentPrompt.ts +62 -0
  300. package/src/prompts/choicePrompt.ts +176 -0
  301. package/src/prompts/confirmPrompt.ts +182 -0
  302. package/src/prompts/datetimePrompt.ts +110 -0
  303. package/src/prompts/index.ts +13 -0
  304. package/src/prompts/numberPrompt.ts +117 -0
  305. package/src/prompts/prompt.ts +459 -0
  306. package/src/prompts/promptCultureModels.ts +178 -0
  307. package/src/prompts/textPrompt.ts +82 -0
  308. package/src/recognizer.ts +127 -0
  309. package/src/recognizerResult.ts +37 -0
  310. package/src/serviceCollection.ts +305 -0
  311. package/src/stringUtils.ts +62 -0
  312. package/src/template.ts +20 -0
  313. package/src/waterfallDialog.ts +215 -0
  314. package/src/waterfallStepContext.ts +96 -0
  315. package/vendor/cldr-data/README.md +5 -0
  316. package/vendor/cldr-data/main/de/numbers.json +156 -0
  317. package/vendor/cldr-data/main/en/numbers.json +159 -0
  318. package/vendor/cldr-data/main/es/numbers.json +156 -0
  319. package/vendor/cldr-data/main/fr/numbers.json +157 -0
  320. package/vendor/cldr-data/main/ja/numbers.json +120 -0
  321. package/vendor/cldr-data/main/nl/numbers.json +156 -0
  322. package/vendor/cldr-data/main/pt/numbers.json +156 -0
  323. package/vendor/cldr-data/main/zh/numbers.json +214 -0
  324. package/vendor/cldr-data/supplemental/likelySubtags.json +1844 -0
  325. package/vendor/cldr-data/supplemental/numberingSystems.json +343 -0
@@ -0,0 +1,176 @@
1
+ /**
2
+ * Copyright (c) Microsoft Corporation. All rights reserved.
3
+ * Licensed under the MIT License.
4
+ */
5
+ import { Activity, TurnContext } from '@microsoft/agents-hosting'
6
+ import { ChoiceFactory, ChoiceFactoryOptions, FindChoicesOptions, FoundChoice, recognizeChoices } from '../choices'
7
+ import { ListStyle, Prompt, PromptOptions, PromptRecognizerResult, PromptValidator } from './prompt'
8
+ import { PromptCultureModels } from './promptCultureModels'
9
+
10
+ // Need ChoiceDefaultsProperty so we can set choiceDefaults dynamically with lambda
11
+ interface ChoiceDefaultsChoicePrompt {
12
+ [locale: string]: ChoiceFactoryOptions;
13
+ }
14
+
15
+ /**
16
+ * Prompts a user to select from a list of choices.
17
+ *
18
+ * @remarks
19
+ * By default the prompt will return to the calling dialog a `FoundChoice` object containing the
20
+ * choice that was selected.
21
+ */
22
+ export class ChoicePrompt extends Prompt<FoundChoice> {
23
+ /**
24
+ * A dictionary of Default Choices based on [[PromptCultureModels.getSupportedCultures()]].
25
+ * Can be replaced by user using the constructor that contains choiceDefaults.
26
+ */
27
+ private choiceDefaults: ChoiceDefaultsChoicePrompt
28
+
29
+ /**
30
+ * The prompts default locale that should be recognized.
31
+ */
32
+ defaultLocale: string | undefined
33
+
34
+ /**
35
+ * Style of the "yes" and "no" choices rendered to the user when prompting.
36
+ *
37
+ * @remarks
38
+ * Defaults to `ListStyle.auto`.
39
+ */
40
+ style: ListStyle
41
+
42
+ /**
43
+ * Additional options passed to the `ChoiceFactory` and used to tweak the style of choices
44
+ * rendered to the user.
45
+ */
46
+ choiceOptions: ChoiceFactoryOptions | undefined
47
+
48
+ /**
49
+ * Additional options passed to the underlying `recognizeChoices()` function.
50
+ */
51
+ recognizerOptions: FindChoicesOptions | undefined
52
+
53
+ /**
54
+ * Creates a new `ChoicePrompt` instance.
55
+ *
56
+ * @param dialogId Unique ID of the dialog within its parent `DialogSet`.
57
+ * @param validator (Optional) validator that will be called each time the user responds to the prompt. If the validator replies with a message no additional retry prompt will be sent.
58
+ * @param defaultLocale (Optional) locale to use if `dc.context.activity.locale` not specified. Defaults to a value of `en-us`.
59
+ * @param choiceDefaults (Optional) Overrides the dictionary of Bot Framework SDK-supported _choiceDefaults (for prompt localization).
60
+ * Must be passed in to each ConfirmPrompt that needs the custom choice defaults.
61
+ */
62
+ constructor (
63
+ dialogId: string,
64
+ validator?: PromptValidator<FoundChoice>,
65
+ defaultLocale?: string,
66
+ choiceDefaults?: ChoiceDefaultsChoicePrompt
67
+ ) {
68
+ super(dialogId, validator)
69
+ this.style = ListStyle.auto
70
+ this.defaultLocale = defaultLocale
71
+
72
+ if (choiceDefaults === undefined) {
73
+ const supported: ChoiceDefaultsChoicePrompt = {}
74
+ PromptCultureModels.getSupportedCultures().forEach((culture): void => {
75
+ supported[culture.locale] = {
76
+ inlineSeparator: culture.separator,
77
+ inlineOr: culture.inlineOr,
78
+ inlineOrMore: culture.inlineOrMore,
79
+ includeNumbers: true,
80
+ }
81
+ })
82
+ this.choiceDefaults = supported
83
+ } else {
84
+ this.choiceDefaults = choiceDefaults
85
+ }
86
+ }
87
+
88
+ /**
89
+ * Prompts the user for input.
90
+ *
91
+ * @param context TurnContext, context for the current
92
+ * turn of conversation with the user.
93
+ * @param state Contains state for the current instance of the prompt on the dialog stack.
94
+ * @param options A PromptOptions object constructed
95
+ * from the options initially provided in the call to Prompt.
96
+ * @param isRetry `true` if this is the first time this prompt dialog instance
97
+ * on the stack is prompting the user for input; otherwise, false.
98
+ * @returns A `Promise` representing the asynchronous operation.
99
+ */
100
+ protected async onPrompt (
101
+ context: TurnContext,
102
+ state: any,
103
+ options: PromptOptions,
104
+ isRetry: boolean
105
+ ): Promise<void> {
106
+ // Determine locale
107
+ const locale = this.determineCulture(context.activity)
108
+
109
+ // Format prompt to send
110
+ let prompt: Activity
111
+ const choices =
112
+ (this.style === ListStyle.suggestedAction ? ChoiceFactory.toChoices(options.choices) : options.choices) ||
113
+ []
114
+ const channelId = context.activity.channelId
115
+ const choiceOptions = this.choiceOptions || this.choiceDefaults[locale]
116
+ const choiceStyle: ListStyle = options.style === 0 ? 0 : options.style || this.style
117
+ if (isRetry && options.retryPrompt) {
118
+ prompt = this.appendChoices(options.retryPrompt, channelId, choices, choiceStyle, choiceOptions)
119
+ } else {
120
+ prompt = this.appendChoices(options.prompt, channelId, choices, choiceStyle, choiceOptions)
121
+ }
122
+
123
+ // Send prompt
124
+ await context.sendActivity(prompt)
125
+ }
126
+
127
+ /**
128
+ * Attempts to recognize the user's input.
129
+ *
130
+ * @param context TurnContext context for the current
131
+ * turn of conversation with the user.
132
+ * @param state Contains state for the current instance of the prompt on the dialog stack.
133
+ * @param options A PromptOptions object constructed
134
+ * from the options initially provided in the call to Prompt.
135
+ * @returns A `Promise` representing the asynchronous operation.
136
+ */
137
+ protected async onRecognize (
138
+ context: TurnContext,
139
+ state: any,
140
+ options: PromptOptions
141
+ ): Promise<PromptRecognizerResult<FoundChoice>> {
142
+ const result: PromptRecognizerResult<FoundChoice> = { succeeded: false }
143
+ const activity = context.activity
144
+ const utterance = activity.text
145
+ if (!utterance) {
146
+ return result
147
+ }
148
+ const choices =
149
+ (this.style === ListStyle.suggestedAction ? ChoiceFactory.toChoices(options.choices) : options.choices) ||
150
+ []
151
+ const opt = this.recognizerOptions || {}
152
+ opt.locale = this.determineCulture(activity, opt)
153
+ const results = recognizeChoices(utterance, choices, opt)
154
+ if (Array.isArray(results) && results.length > 0) {
155
+ result.succeeded = true
156
+ result.value = results[0].resolution
157
+ }
158
+
159
+ return result
160
+ }
161
+
162
+ /**
163
+ * @private
164
+ */
165
+ private determineCulture (activity: Activity, opt?: FindChoicesOptions): string {
166
+ const optLocale = opt && opt.locale ? opt.locale : null
167
+ let culture = PromptCultureModels.mapToNearestLanguage(
168
+ activity.locale || optLocale || this.defaultLocale || PromptCultureModels.English.locale
169
+ )
170
+ if (!(culture && this.choiceDefaults[culture])) {
171
+ culture = PromptCultureModels.English.locale
172
+ }
173
+
174
+ return culture
175
+ }
176
+ }
@@ -0,0 +1,182 @@
1
+ /**
2
+ * Copyright (c) Microsoft Corporation. All rights reserved.
3
+ * Licensed under the MIT License.
4
+ */
5
+ import * as Recognizers from '@microsoft/recognizers-text-choice'
6
+ import { Activity, TurnContext } from '@microsoft/agents-hosting'
7
+ import { Choice, ChoiceFactoryOptions, recognizeChoices } from '../choices'
8
+ import { ListStyle, Prompt, PromptOptions, PromptRecognizerResult, PromptValidator } from './prompt'
9
+ import { PromptCultureModels } from './promptCultureModels'
10
+
11
+ // Need ChoiceDefaultsProperty so we can set choiceDefaults dynamically with lambda
12
+ interface ChoiceDefaultsConfirmPrompt {
13
+ [locale: string]: { choices: (string | Choice)[]; options: ChoiceFactoryOptions };
14
+ }
15
+
16
+ /**
17
+ * Prompts a user to confirm something with a "yes" or "no" response.
18
+ *
19
+ * @remarks
20
+ * By default the prompt will return to the calling dialog a `boolean` representing the users
21
+ * selection.
22
+ */
23
+ export class ConfirmPrompt extends Prompt<boolean> {
24
+ /**
25
+ * A dictionary of Default Choices based on [[PromptCultureModels.getSupportedCultures()]].
26
+ * Can be replaced by user using the constructor that contains choiceDefaults.
27
+ * This is initially set in the constructor.
28
+ */
29
+ private choiceDefaults: ChoiceDefaultsConfirmPrompt
30
+ /**
31
+ * The prompts default locale that should be recognized.
32
+ */
33
+ defaultLocale: string | undefined
34
+
35
+ /**
36
+ * Style of the "yes" and "no" choices rendered to the user when prompting.
37
+ *
38
+ * @remarks
39
+ * Defaults to `ListStyle.auto`.
40
+ */
41
+ style: ListStyle
42
+
43
+ /**
44
+ * Additional options passed to the `ChoiceFactory` and used to tweak the style of choices
45
+ * rendered to the user.
46
+ */
47
+ choiceOptions: ChoiceFactoryOptions | undefined
48
+
49
+ /**
50
+ * Custom list of choices to send for the prompt.
51
+ */
52
+ confirmChoices: (string | Choice)[] | undefined
53
+
54
+ /**
55
+ * Creates a new ConfirmPrompt instance.
56
+ *
57
+ * @param dialogId Unique ID of the dialog within its parent `DialogSet` or `ComponentDialog`.
58
+ * @param validator (Optional) validator that will be called each time the user responds to the prompt.
59
+ * @param defaultLocale (Optional) locale to use if `TurnContext.activity.locale` is not specified. Defaults to a value of `en-us`.
60
+ * @param choiceDefaults (Optional) Overrides the dictionary of Default Choices on [[PromptCultureModels.getSupportedCultures()]].
61
+ */
62
+ constructor (
63
+ dialogId: string,
64
+ validator?: PromptValidator<boolean>,
65
+ defaultLocale?: string,
66
+ choiceDefaults?: ChoiceDefaultsConfirmPrompt
67
+ ) {
68
+ super(dialogId, validator)
69
+ this.style = ListStyle.auto
70
+ this.defaultLocale = defaultLocale
71
+
72
+ if (choiceDefaults === undefined) {
73
+ const supported: ChoiceDefaultsConfirmPrompt = {}
74
+ PromptCultureModels.getSupportedCultures().forEach((culture): void => {
75
+ supported[culture.locale] = {
76
+ choices: [culture.yesInLanguage, culture.noInLanguage],
77
+ options: {
78
+ inlineSeparator: culture.separator,
79
+ inlineOr: culture.inlineOr,
80
+ inlineOrMore: culture.inlineOrMore,
81
+ includeNumbers: true,
82
+ },
83
+ }
84
+ })
85
+ this.choiceDefaults = supported
86
+ } else {
87
+ this.choiceDefaults = choiceDefaults
88
+ }
89
+ }
90
+
91
+ /**
92
+ * Prompts the user for input.
93
+ *
94
+ * @param context TurnContext, context for the current
95
+ * turn of conversation with the user.
96
+ * @param state Contains state for the current instance of the prompt on the dialog stack.
97
+ * @param options A PromptOptions object constructed
98
+ * from the options initially provided in the call to Prompt.
99
+ * @param isRetry `true` if this is the first time this prompt dialog instance
100
+ * on the stack is prompting the user for input; otherwise, false.
101
+ * @returns A `Promise` representing the asynchronous operation.
102
+ */
103
+ protected async onPrompt (
104
+ context: TurnContext,
105
+ state: any,
106
+ options: PromptOptions,
107
+ isRetry: boolean
108
+ ): Promise<void> {
109
+ // Format prompt to send
110
+ let prompt: Activity
111
+ const channelId = context.activity.channelId
112
+ const culture = this.determineCulture(context.activity)
113
+ const choiceOptions = this.choiceOptions || this.choiceDefaults[culture].options
114
+ const choices = this.confirmChoices || this.choiceDefaults[culture].choices
115
+ if (isRetry && options.retryPrompt) {
116
+ prompt = this.appendChoices(options.retryPrompt, channelId, choices, this.style, choiceOptions)
117
+ } else {
118
+ prompt = this.appendChoices(options.prompt, channelId, choices, this.style, choiceOptions)
119
+ }
120
+
121
+ // Send prompt
122
+ await context.sendActivity(prompt)
123
+ }
124
+
125
+ /**
126
+ * Attempts to recognize the user's input.
127
+ *
128
+ * @param context TurnContext, context for the current
129
+ * turn of conversation with the user.
130
+ * @param _state Contains state for the current instance of the prompt on the dialog stack.
131
+ * @param _options A PromptOptions object constructed
132
+ * from the options initially provided in the call to Prompt.
133
+ * @returns A `Promise` representing the asynchronous operation.
134
+ */
135
+ protected async onRecognize (
136
+ context: TurnContext,
137
+ _state,
138
+ _options: PromptOptions
139
+ ): Promise<PromptRecognizerResult<boolean>> {
140
+ const result: PromptRecognizerResult<boolean> = { succeeded: false }
141
+ const activity = context.activity
142
+ const utterance = activity.text
143
+ if (!utterance) {
144
+ return result
145
+ }
146
+ const culture = this.determineCulture(context.activity)
147
+ const results = Recognizers.recognizeBoolean(utterance, _options.recognizeLanguage ?? culture)
148
+ if (results.length > 0 && results[0].resolution) {
149
+ result.succeeded = true
150
+ result.value = results[0].resolution.value
151
+ } else {
152
+ // If the prompt text was sent to the user with numbers, the prompt should recognize number choices.
153
+ const choiceOptions = this.choiceOptions || this.choiceDefaults[culture].options
154
+
155
+ if (typeof choiceOptions.includeNumbers !== 'boolean' || choiceOptions.includeNumbers) {
156
+ const confirmChoices = this.confirmChoices || this.choiceDefaults[culture].choices
157
+ const choices = [confirmChoices[0], confirmChoices[1]]
158
+ const secondOrMoreAttemptResults = recognizeChoices(utterance, choices)
159
+ if (secondOrMoreAttemptResults.length > 0) {
160
+ result.succeeded = true
161
+ result.value = secondOrMoreAttemptResults[0].resolution.index === 0
162
+ }
163
+ }
164
+ }
165
+
166
+ return result
167
+ }
168
+
169
+ /**
170
+ * @private
171
+ */
172
+ private determineCulture (activity: Activity): string {
173
+ let culture = PromptCultureModels.mapToNearestLanguage(
174
+ activity.locale || this.defaultLocale || PromptCultureModels.English.locale
175
+ )
176
+ if (!(culture && this.choiceDefaults[culture])) {
177
+ culture = PromptCultureModels.English.locale
178
+ }
179
+
180
+ return culture
181
+ }
182
+ }
@@ -0,0 +1,110 @@
1
+ /**
2
+ * Copyright (c) Microsoft Corporation. All rights reserved.
3
+ * Licensed under the MIT License.
4
+ */
5
+ import * as Recognizers from '@microsoft/recognizers-text-date-time'
6
+ import { Activity, InputHints, TurnContext } from '@microsoft/agents-hosting'
7
+ import { Prompt, PromptOptions, PromptRecognizerResult, PromptValidator } from './prompt'
8
+
9
+ /**
10
+ * Result returned by the `DateTimePrompt`.
11
+ */
12
+ export interface DateTimeResolution {
13
+ /**
14
+ * TIMEX expression representing ambiguity of the recognized time.
15
+ */
16
+ timex: string;
17
+
18
+ /**
19
+ * Type of time recognized. Possible values are 'date', 'time', 'datetime', 'daterange',
20
+ * 'timerange', 'datetimerange', 'duration', or 'set'.
21
+ */
22
+ type: string;
23
+
24
+ /**
25
+ * Value of the specified [type](#type) that's a reasonable approximation given the ambiguity
26
+ * of the [timex](#timex).
27
+ */
28
+ value: string;
29
+ }
30
+
31
+ /**
32
+ * Prompts a user to enter a datetime expression.
33
+ *
34
+ * @remarks
35
+ * By default the prompt will return to the calling dialog a `DateTimeResolution[]`.
36
+ */
37
+ export class DateTimePrompt extends Prompt<DateTimeResolution[]> {
38
+ /**
39
+ * The prompts default locale that should be recognized.
40
+ */
41
+ defaultLocale: string | undefined
42
+
43
+ /**
44
+ * Creates a new DateTimePrompt instance.
45
+ *
46
+ * @param dialogId Unique ID of the dialog within its parent `DialogSet` or `ComponentDialog`.
47
+ * @param validator (Optional) validator that will be called each time the user responds to the prompt.
48
+ * @param defaultLocale (Optional) locale to use if `TurnContext.activity.locale` is not specified. Defaults to a value of `en-us`.
49
+ */
50
+ constructor (dialogId: string, validator?: PromptValidator<DateTimeResolution[]>, defaultLocale?: string) {
51
+ super(dialogId, validator)
52
+ this.defaultLocale = defaultLocale
53
+ }
54
+
55
+ /**
56
+ * Prompts the user for input.
57
+ *
58
+ * @param context TurnContext, context for the current
59
+ * turn of conversation with the user.
60
+ * @param state Contains state for the current instance of the prompt on the dialog stack.
61
+ * @param options A PromptOptions object constructed
62
+ * from the options initially provided in the call to Prompt.
63
+ * @param isRetry `true` if this is the first time this prompt dialog instance
64
+ * on the stack is prompting the user for input; otherwise, false.
65
+ * @returns A `Promise` representing the asynchronous operation.
66
+ */
67
+ protected async onPrompt (
68
+ context: TurnContext,
69
+ state: any,
70
+ options: PromptOptions,
71
+ isRetry: boolean
72
+ ): Promise<void> {
73
+ if (isRetry && options.retryPrompt) {
74
+ await context.sendActivity(options.retryPrompt, undefined, InputHints.ExpectingInput)
75
+ } else if (options.prompt) {
76
+ await context.sendActivity(options.prompt, undefined, InputHints.ExpectingInput)
77
+ }
78
+ }
79
+
80
+ /**
81
+ * Attempts to recognize the user's input.
82
+ *
83
+ * @param context TurnContext, context for the current
84
+ * turn of conversation with the user.
85
+ * @param _state Contains state for the current instance of the prompt on the dialog stack.
86
+ * @param _options A PromptOptions object constructed
87
+ * from the options initially provided in the call to Prompt.
88
+ * @returns A `Promise` representing the asynchronous operation.
89
+ */
90
+ protected async onRecognize (
91
+ context: TurnContext,
92
+ _state: any,
93
+ _options: PromptOptions
94
+ ): Promise<PromptRecognizerResult<DateTimeResolution[]>> {
95
+ const result: PromptRecognizerResult<DateTimeResolution[]> = { succeeded: false }
96
+ const activity: Activity = context.activity
97
+ const utterance: string = activity.text
98
+ if (!utterance) {
99
+ return result
100
+ }
101
+ const locale: string = activity.locale || this.defaultLocale || 'en-us'
102
+ const results: any[] = Recognizers.recognizeDateTime(utterance, locale)
103
+ if (results.length > 0 && results[0].resolution) {
104
+ result.succeeded = true
105
+ result.value = results[0].resolution.values
106
+ }
107
+
108
+ return result
109
+ }
110
+ }
@@ -0,0 +1,13 @@
1
+ /**
2
+ * Copyright (c) Microsoft Corporation. All rights reserved.
3
+ * Licensed under the MIT License.
4
+ */
5
+ export * from './activityPrompt'
6
+ export * from './attachmentPrompt'
7
+ export * from './choicePrompt'
8
+ export * from './confirmPrompt'
9
+ export * from './datetimePrompt'
10
+ export * from './numberPrompt'
11
+ export * from './prompt'
12
+ export * from './textPrompt'
13
+ export * from './promptCultureModels'
@@ -0,0 +1,117 @@
1
+ /**
2
+ * Copyright (c) Microsoft Corporation. All rights reserved.
3
+ * Licensed under the MIT License.
4
+ */
5
+
6
+ import Globalize from 'globalize'
7
+ import { recognizeNumber } from '@microsoft/recognizers-text-number'
8
+ import * as locales from '../i18n'
9
+ import { InputHints, TurnContext } from '@microsoft/agents-hosting'
10
+ import { Prompt, PromptOptions, PromptRecognizerResult, PromptValidator } from './prompt'
11
+
12
+ // Load all registered locales into Globalize library
13
+ Object.values(locales).forEach((locale) => Globalize.load(locale))
14
+
15
+ /**
16
+ * Prompts a user to enter a number.
17
+ *
18
+ * @remarks
19
+ * By default the prompt will return to the calling dialog a `number` representing the users input.
20
+ */
21
+ export class NumberPrompt extends Prompt<number> {
22
+ /**
23
+ * The prompts default locale that should be recognized.
24
+ */
25
+ defaultLocale?: string
26
+
27
+ /**
28
+ * Creates a new NumberPrompt instance.
29
+ *
30
+ * @param dialogId Unique ID of the dialog within its parent `DialogSet` or `ComponentDialog`.
31
+ * @param validator (Optional) validator that will be called each time the user responds to the prompt.
32
+ * @param defaultLocale (Optional) locale to use if `TurnContext.activity.locale` is not specified. Defaults to a value of `en-us`.
33
+ */
34
+ constructor (dialogId: string, validator?: PromptValidator<number>, defaultLocale?: string) {
35
+ super(dialogId, validator)
36
+ this.defaultLocale = defaultLocale
37
+ }
38
+
39
+ /**
40
+ * Prompts the user for input.
41
+ *
42
+ * @param context [TurnContext] context for the current
43
+ * turn of conversation with the user.
44
+ * @param state Contains state for the current instance of the prompt on the dialog stack.
45
+ * @param options A [PromptOptions] object constructed
46
+ * from the options initially provided in the call to Prompt.
47
+ * @param isRetry `true` if this is the first time this prompt dialog instance
48
+ * on the stack is prompting the user for input; otherwise, false.
49
+ * @returns A `Promise` representing the asynchronous operation.
50
+ */
51
+ protected async onPrompt (
52
+ context: TurnContext,
53
+ state: unknown,
54
+ options: PromptOptions,
55
+ isRetry: boolean
56
+ ): Promise<void> {
57
+ if (isRetry && options.retryPrompt) {
58
+ await context.sendActivity(options.retryPrompt, undefined, InputHints.ExpectingInput)
59
+ } else if (options.prompt) {
60
+ await context.sendActivity(options.prompt, undefined, InputHints.ExpectingInput)
61
+ }
62
+ }
63
+
64
+ /**
65
+ * Attempts to recognize the user's input.
66
+ *
67
+ * @param context [TurnContext], context for the current
68
+ * turn of conversation with the user.
69
+ * @param _state Contains state for the current instance of the prompt on the dialog stack.
70
+ * @param _options A [PromptOptions] object constructed
71
+ * from the options initially provided in the call to Prompt.
72
+ * @returns A `Promise` representing the asynchronous operation.
73
+ */
74
+ protected async onRecognize (
75
+ context: TurnContext,
76
+ _state: unknown,
77
+ _options: PromptOptions
78
+ ): Promise<PromptRecognizerResult<number>> {
79
+ const result: PromptRecognizerResult<number> = { succeeded: false }
80
+ const activity = context.activity
81
+
82
+ const utterance = activity.text
83
+ if (!utterance) {
84
+ return result
85
+ }
86
+
87
+ const defaultLocale = this.defaultLocale || 'en-us'
88
+ const locale = activity.locale || defaultLocale
89
+
90
+ const [{ resolution = null } = {}] = recognizeNumber(utterance, locale) || []
91
+ if (resolution) {
92
+ result.succeeded = true
93
+
94
+ // Note: if we encounter an exception loading a globalize number parser, fall back to the
95
+ // parser for the default locale
96
+ const parser = Globalize(this.getCultureFormattedForGlobalize(locale))
97
+ let numberParser: (value: string) => number
98
+ try {
99
+ numberParser = parser.numberParser()
100
+ } catch {
101
+ numberParser = Globalize(this.getCultureFormattedForGlobalize(defaultLocale)).numberParser()
102
+ }
103
+
104
+ result.value = numberParser(resolution.value)
105
+ }
106
+
107
+ return result
108
+ }
109
+
110
+ /**
111
+ * @private
112
+ * The portions of the Globalize parsing library we use only need the first letters for internationalization culture
113
+ */
114
+ private getCultureFormattedForGlobalize (culture: string): string {
115
+ return culture.slice(0, 2).toLowerCase()
116
+ }
117
+ }