@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.
- package/dist/index.js +20 -0
- package/dist/src/agentComponent.d.ts +18 -0
- package/dist/src/agentComponent.js +55 -0
- package/dist/src/agentComponent.js.map +1 -0
- package/dist/src/agentStateSet.d.ts +48 -0
- package/dist/src/agentStateSet.js +66 -0
- package/dist/src/agentStateSet.js.map +1 -0
- package/dist/src/choices/choice.d.ts +14 -0
- package/dist/src/choices/choice.js +7 -0
- package/dist/src/choices/choice.js.map +1 -0
- package/dist/src/choices/choiceFactory.d.ts +81 -0
- package/dist/src/choices/choiceFactory.js +133 -0
- package/dist/src/choices/choiceFactory.js.map +1 -0
- package/dist/src/choices/findChoices.d.ts +28 -0
- package/dist/src/choices/findChoices.js +46 -0
- package/dist/src/choices/findChoices.js.map +1 -0
- package/dist/src/choices/findValues.d.ts +36 -0
- package/dist/src/choices/findValues.js +129 -0
- package/dist/src/choices/findValues.js.map +1 -0
- package/dist/src/choices/index.d.ts +11 -0
- package/dist/src/choices/index.js +28 -0
- package/dist/src/choices/index.js.map +1 -0
- package/dist/src/choices/modelResult.d.ts +11 -0
- package/dist/src/choices/modelResult.js +3 -0
- package/dist/src/choices/modelResult.js.map +1 -0
- package/dist/src/choices/recognizeChoices.d.ts +16 -0
- package/dist/src/choices/recognizeChoices.js +81 -0
- package/dist/src/choices/recognizeChoices.js.map +1 -0
- package/dist/src/choices/tokenizer.d.ts +25 -0
- package/dist/src/choices/tokenizer.js +73 -0
- package/dist/src/choices/tokenizer.js.map +1 -0
- package/dist/src/componentDialog.d.ts +178 -0
- package/dist/src/componentDialog.js +252 -0
- package/dist/src/componentDialog.js.map +1 -0
- package/dist/src/componentRegistration.d.ts +22 -0
- package/dist/src/componentRegistration.js +32 -0
- package/dist/src/componentRegistration.js.map +1 -0
- package/dist/src/configurable.d.ts +22 -0
- package/dist/src/configurable.js +60 -0
- package/dist/src/configurable.js.map +1 -0
- package/dist/src/configuration.d.ts +11 -0
- package/dist/src/configuration.js +17 -0
- package/dist/src/configuration.js.map +1 -0
- package/dist/src/converter.d.ts +13 -0
- package/dist/src/converter.js +7 -0
- package/dist/src/converter.js.map +1 -0
- package/dist/src/dialog.d.ts +184 -0
- package/dist/src/dialog.js +201 -0
- package/dist/src/dialog.js.map +1 -0
- package/dist/src/dialogContainer.d.ts +61 -0
- package/dist/src/dialogContainer.js +82 -0
- package/dist/src/dialogContainer.js.map +1 -0
- package/dist/src/dialogContext.d.ts +272 -0
- package/dist/src/dialogContext.js +444 -0
- package/dist/src/dialogContext.js.map +1 -0
- package/dist/src/dialogContextError.d.ts +27 -0
- package/dist/src/dialogContextError.js +39 -0
- package/dist/src/dialogContextError.js.map +1 -0
- package/dist/src/dialogEvent.d.ts +20 -0
- package/dist/src/dialogEvent.js +3 -0
- package/dist/src/dialogEvent.js.map +1 -0
- package/dist/src/dialogEvents.d.ts +15 -0
- package/dist/src/dialogEvents.js +20 -0
- package/dist/src/dialogEvents.js.map +1 -0
- package/dist/src/dialogHelper.d.ts +32 -0
- package/dist/src/dialogHelper.js +116 -0
- package/dist/src/dialogHelper.js.map +1 -0
- package/dist/src/dialogInstance.d.ts +30 -0
- package/dist/src/dialogInstance.js +3 -0
- package/dist/src/dialogInstance.js.map +1 -0
- package/dist/src/dialogManager.d.ts +73 -0
- package/dist/src/dialogManager.js +156 -0
- package/dist/src/dialogManager.js.map +1 -0
- package/dist/src/dialogReason.d.ts +35 -0
- package/dist/src/dialogReason.js +40 -0
- package/dist/src/dialogReason.js.map +1 -0
- package/dist/src/dialogSet.d.ts +85 -0
- package/dist/src/dialogSet.js +138 -0
- package/dist/src/dialogSet.js.map +1 -0
- package/dist/src/dialogTurnResult.d.ts +34 -0
- package/dist/src/dialogTurnResult.js +3 -0
- package/dist/src/dialogTurnResult.js.map +1 -0
- package/dist/src/dialogTurnStateConstants.d.ts +12 -0
- package/dist/src/dialogTurnStateConstants.js +17 -0
- package/dist/src/dialogTurnStateConstants.js.map +1 -0
- package/dist/src/dialogTurnStatus.d.ts +34 -0
- package/dist/src/dialogTurnStatus.js +39 -0
- package/dist/src/dialogTurnStatus.js.map +1 -0
- package/dist/src/dialogsAgentComponent.d.ts +17 -0
- package/dist/src/dialogsAgentComponent.js +65 -0
- package/dist/src/dialogsAgentComponent.js.map +1 -0
- package/dist/src/dialogsComponentRegistration.d.ts +28 -0
- package/dist/src/dialogsComponentRegistration.js +45 -0
- package/dist/src/dialogsComponentRegistration.js.map +1 -0
- package/dist/src/i18n.d.ts +15 -0
- package/dist/src/i18n.js +28 -0
- package/dist/src/i18n.js.map +1 -0
- package/dist/src/index.d.ts +29 -0
- package/dist/src/index.js +48 -0
- package/dist/src/index.js.map +1 -0
- package/dist/src/intentScore.d.ts +11 -0
- package/dist/src/intentScore.js +3 -0
- package/dist/src/intentScore.js.map +1 -0
- package/dist/src/memory/componentMemoryScopes.d.ts +18 -0
- package/dist/src/memory/componentMemoryScopes.js +54 -0
- package/dist/src/memory/componentMemoryScopes.js.map +1 -0
- package/dist/src/memory/componentPathResolvers.d.ts +18 -0
- package/dist/src/memory/componentPathResolvers.js +52 -0
- package/dist/src/memory/componentPathResolvers.js.map +1 -0
- package/dist/src/memory/dialogPath.d.ts +17 -0
- package/dist/src/memory/dialogPath.js +30 -0
- package/dist/src/memory/dialogPath.js.map +1 -0
- package/dist/src/memory/dialogStateManager.d.ts +156 -0
- package/dist/src/memory/dialogStateManager.js +598 -0
- package/dist/src/memory/dialogStateManager.js.map +1 -0
- package/dist/src/memory/index.d.ts +12 -0
- package/dist/src/memory/index.js +29 -0
- package/dist/src/memory/index.js.map +1 -0
- package/dist/src/memory/pathResolvers/aliasPathResolver.d.ts +25 -0
- package/dist/src/memory/pathResolvers/aliasPathResolver.js +37 -0
- package/dist/src/memory/pathResolvers/aliasPathResolver.js.map +1 -0
- package/dist/src/memory/pathResolvers/atAtPathResolver.d.ts +11 -0
- package/dist/src/memory/pathResolvers/atAtPathResolver.js +18 -0
- package/dist/src/memory/pathResolvers/atAtPathResolver.js.map +1 -0
- package/dist/src/memory/pathResolvers/atPathResolver.d.ts +20 -0
- package/dist/src/memory/pathResolvers/atPathResolver.js +46 -0
- package/dist/src/memory/pathResolvers/atPathResolver.js.map +1 -0
- package/dist/src/memory/pathResolvers/dollarPathResolver.d.ts +11 -0
- package/dist/src/memory/pathResolvers/dollarPathResolver.js +18 -0
- package/dist/src/memory/pathResolvers/dollarPathResolver.js.map +1 -0
- package/dist/src/memory/pathResolvers/hashPathResolver.d.ts +11 -0
- package/dist/src/memory/pathResolvers/hashPathResolver.js +18 -0
- package/dist/src/memory/pathResolvers/hashPathResolver.js.map +1 -0
- package/dist/src/memory/pathResolvers/index.d.ts +11 -0
- package/dist/src/memory/pathResolvers/index.js +28 -0
- package/dist/src/memory/pathResolvers/index.js.map +1 -0
- package/dist/src/memory/pathResolvers/pathResolver.d.ts +13 -0
- package/dist/src/memory/pathResolvers/pathResolver.js +7 -0
- package/dist/src/memory/pathResolvers/pathResolver.js.map +1 -0
- package/dist/src/memory/pathResolvers/percentPathResolver.d.ts +11 -0
- package/dist/src/memory/pathResolvers/percentPathResolver.js +18 -0
- package/dist/src/memory/pathResolvers/percentPathResolver.js.map +1 -0
- package/dist/src/memory/scopePath.d.ts +18 -0
- package/dist/src/memory/scopePath.js +23 -0
- package/dist/src/memory/scopePath.js.map +1 -0
- package/dist/src/memory/scopes/agentStateMemoryScope.d.ts +53 -0
- package/dist/src/memory/scopes/agentStateMemoryScope.js +82 -0
- package/dist/src/memory/scopes/agentStateMemoryScope.js.map +1 -0
- package/dist/src/memory/scopes/classMemoryScope.d.ts +29 -0
- package/dist/src/memory/scopes/classMemoryScope.js +65 -0
- package/dist/src/memory/scopes/classMemoryScope.js.map +1 -0
- package/dist/src/memory/scopes/conversationMemoryScope.d.ts +15 -0
- package/dist/src/memory/scopes/conversationMemoryScope.js +23 -0
- package/dist/src/memory/scopes/conversationMemoryScope.js.map +1 -0
- package/dist/src/memory/scopes/dialogClassMemoryScope.d.ts +19 -0
- package/dist/src/memory/scopes/dialogClassMemoryScope.js +42 -0
- package/dist/src/memory/scopes/dialogClassMemoryScope.js.map +1 -0
- package/dist/src/memory/scopes/dialogContextMemoryScope.d.ts +19 -0
- package/dist/src/memory/scopes/dialogContextMemoryScope.js +48 -0
- package/dist/src/memory/scopes/dialogContextMemoryScope.js.map +1 -0
- package/dist/src/memory/scopes/dialogMemoryScope.d.ts +32 -0
- package/dist/src/memory/scopes/dialogMemoryScope.js +74 -0
- package/dist/src/memory/scopes/dialogMemoryScope.js.map +1 -0
- package/dist/src/memory/scopes/index.d.ts +15 -0
- package/dist/src/memory/scopes/index.js +32 -0
- package/dist/src/memory/scopes/index.js.map +1 -0
- package/dist/src/memory/scopes/memoryScope.d.ts +52 -0
- package/dist/src/memory/scopes/memoryScope.js +54 -0
- package/dist/src/memory/scopes/memoryScope.js.map +1 -0
- package/dist/src/memory/scopes/settingsMemoryScope.d.ts +68 -0
- package/dist/src/memory/scopes/settingsMemoryScope.js +216 -0
- package/dist/src/memory/scopes/settingsMemoryScope.js.map +1 -0
- package/dist/src/memory/scopes/thisMemoryScope.d.ts +26 -0
- package/dist/src/memory/scopes/thisMemoryScope.js +43 -0
- package/dist/src/memory/scopes/thisMemoryScope.js.map +1 -0
- package/dist/src/memory/scopes/turnMemoryScope.d.ts +29 -0
- package/dist/src/memory/scopes/turnMemoryScope.js +52 -0
- package/dist/src/memory/scopes/turnMemoryScope.js.map +1 -0
- package/dist/src/memory/scopes/userMemoryScope.d.ts +15 -0
- package/dist/src/memory/scopes/userMemoryScope.js +23 -0
- package/dist/src/memory/scopes/userMemoryScope.js.map +1 -0
- package/dist/src/memory/turnPath.d.ts +21 -0
- package/dist/src/memory/turnPath.js +38 -0
- package/dist/src/memory/turnPath.js.map +1 -0
- package/dist/src/prompts/activityPrompt.d.ts +101 -0
- package/dist/src/prompts/activityPrompt.js +166 -0
- package/dist/src/prompts/activityPrompt.js.map +1 -0
- package/dist/src/prompts/attachmentPrompt.d.ts +37 -0
- package/dist/src/prompts/attachmentPrompt.js +55 -0
- package/dist/src/prompts/attachmentPrompt.js.map +1 -0
- package/dist/src/prompts/choicePrompt.d.ts +83 -0
- package/dist/src/prompts/choicePrompt.js +116 -0
- package/dist/src/prompts/choicePrompt.js.map +1 -0
- package/dist/src/prompts/confirmPrompt.d.ts +82 -0
- package/dist/src/prompts/confirmPrompt.js +163 -0
- package/dist/src/prompts/confirmPrompt.js.map +1 -0
- package/dist/src/prompts/datetimePrompt.d.ts +65 -0
- package/dist/src/prompts/datetimePrompt.js +109 -0
- package/dist/src/prompts/datetimePrompt.js.map +1 -0
- package/dist/src/prompts/index.d.ts +13 -0
- package/dist/src/prompts/index.js +30 -0
- package/dist/src/prompts/index.js.map +1 -0
- package/dist/src/prompts/numberPrompt.d.ts +55 -0
- package/dist/src/prompts/numberPrompt.js +134 -0
- package/dist/src/prompts/numberPrompt.js.map +1 -0
- package/dist/src/prompts/prompt.d.ts +256 -0
- package/dist/src/prompts/prompt.js +260 -0
- package/dist/src/prompts/prompt.js.map +1 -0
- package/dist/src/prompts/promptCultureModels.d.ts +72 -0
- package/dist/src/prompts/promptCultureModels.js +123 -0
- package/dist/src/prompts/promptCultureModels.js.map +1 -0
- package/dist/src/prompts/textPrompt.d.ts +54 -0
- package/dist/src/prompts/textPrompt.js +72 -0
- package/dist/src/prompts/textPrompt.js.map +1 -0
- package/dist/src/recognizer.d.ts +43 -0
- package/dist/src/recognizer.js +104 -0
- package/dist/src/recognizer.js.map +1 -0
- package/dist/src/recognizerResult.d.ts +19 -0
- package/dist/src/recognizerResult.js +24 -0
- package/dist/src/recognizerResult.js.map +1 -0
- package/dist/src/serviceCollection.d.ts +112 -0
- package/dist/src/serviceCollection.js +209 -0
- package/dist/src/serviceCollection.js.map +1 -0
- package/dist/src/stringUtils.d.ts +36 -0
- package/dist/src/stringUtils.js +62 -0
- package/dist/src/stringUtils.js.map +1 -0
- package/dist/src/template.d.ts +18 -0
- package/dist/src/template.js +7 -0
- package/dist/src/template.js.map +1 -0
- package/dist/src/waterfallDialog.d.ts +101 -0
- package/dist/src/waterfallDialog.js +179 -0
- package/dist/src/waterfallDialog.js.map +1 -0
- package/dist/src/waterfallStepContext.d.ts +71 -0
- package/dist/src/waterfallStepContext.js +78 -0
- package/dist/src/waterfallStepContext.js.map +1 -0
- package/package.json +49 -0
- package/src/agentComponent.ts +23 -0
- package/src/agentStateSet.ts +75 -0
- package/src/choices/choice.ts +16 -0
- package/src/choices/choiceFactory.ts +189 -0
- package/src/choices/findChoices.ts +70 -0
- package/src/choices/findValues.ts +179 -0
- package/src/choices/index.ts +11 -0
- package/src/choices/modelResult.ts +11 -0
- package/src/choices/recognizeChoices.ts +94 -0
- package/src/choices/tokenizer.ts +93 -0
- package/src/componentDialog.ts +306 -0
- package/src/componentRegistration.ts +30 -0
- package/src/configurable.ts +55 -0
- package/src/configuration.ts +22 -0
- package/src/converter.ts +15 -0
- package/src/dialog.ts +243 -0
- package/src/dialogContainer.ts +90 -0
- package/src/dialogContext.ts +607 -0
- package/src/dialogContextError.ts +50 -0
- package/src/dialogEvent.ts +23 -0
- package/src/dialogEvents.ts +16 -0
- package/src/dialogHelper.ts +154 -0
- package/src/dialogInstance.ts +32 -0
- package/src/dialogManager.ts +202 -0
- package/src/dialogReason.ts +40 -0
- package/src/dialogSet.ts +168 -0
- package/src/dialogTurnResult.ts +37 -0
- package/src/dialogTurnStateConstants.ts +13 -0
- package/src/dialogTurnStatus.ts +38 -0
- package/src/dialogsAgentComponent.ts +71 -0
- package/src/dialogsComponentRegistration.ts +49 -0
- package/src/i18n.ts +17 -0
- package/src/index.ts +31 -0
- package/src/intentScore.ts +11 -0
- package/src/memory/componentMemoryScopes.ts +28 -0
- package/src/memory/componentPathResolvers.ts +29 -0
- package/src/memory/dialogPath.ts +33 -0
- package/src/memory/dialogStateManager.ts +661 -0
- package/src/memory/index.ts +12 -0
- package/src/memory/pathResolvers/aliasPathResolver.ts +44 -0
- package/src/memory/pathResolvers/atAtPathResolver.ts +14 -0
- package/src/memory/pathResolvers/atPathResolver.ts +45 -0
- package/src/memory/pathResolvers/dollarPathResolver.ts +14 -0
- package/src/memory/pathResolvers/hashPathResolver.ts +14 -0
- package/src/memory/pathResolvers/index.ts +11 -0
- package/src/memory/pathResolvers/pathResolver.ts +14 -0
- package/src/memory/pathResolvers/percentPathResolver.ts +14 -0
- package/src/memory/scopePath.ts +19 -0
- package/src/memory/scopes/agentStateMemoryScope.ts +92 -0
- package/src/memory/scopes/classMemoryScope.ts +71 -0
- package/src/memory/scopes/conversationMemoryScope.ts +19 -0
- package/src/memory/scopes/dialogClassMemoryScope.ts +43 -0
- package/src/memory/scopes/dialogContextMemoryScope.ts +51 -0
- package/src/memory/scopes/dialogMemoryScope.ts +79 -0
- package/src/memory/scopes/index.ts +15 -0
- package/src/memory/scopes/memoryScope.ts +70 -0
- package/src/memory/scopes/settingsMemoryScope.ts +239 -0
- package/src/memory/scopes/thisMemoryScope.ts +44 -0
- package/src/memory/scopes/turnMemoryScope.ts +54 -0
- package/src/memory/scopes/userMemoryScope.ts +19 -0
- package/src/memory/turnPath.ts +45 -0
- package/src/prompts/activityPrompt.ts +202 -0
- package/src/prompts/attachmentPrompt.ts +62 -0
- package/src/prompts/choicePrompt.ts +176 -0
- package/src/prompts/confirmPrompt.ts +182 -0
- package/src/prompts/datetimePrompt.ts +110 -0
- package/src/prompts/index.ts +13 -0
- package/src/prompts/numberPrompt.ts +117 -0
- package/src/prompts/prompt.ts +459 -0
- package/src/prompts/promptCultureModels.ts +178 -0
- package/src/prompts/textPrompt.ts +82 -0
- package/src/recognizer.ts +127 -0
- package/src/recognizerResult.ts +37 -0
- package/src/serviceCollection.ts +305 -0
- package/src/stringUtils.ts +62 -0
- package/src/template.ts +20 -0
- package/src/waterfallDialog.ts +215 -0
- package/src/waterfallStepContext.ts +96 -0
- package/vendor/cldr-data/README.md +5 -0
- package/vendor/cldr-data/main/de/numbers.json +156 -0
- package/vendor/cldr-data/main/en/numbers.json +159 -0
- package/vendor/cldr-data/main/es/numbers.json +156 -0
- package/vendor/cldr-data/main/fr/numbers.json +157 -0
- package/vendor/cldr-data/main/ja/numbers.json +120 -0
- package/vendor/cldr-data/main/nl/numbers.json +156 -0
- package/vendor/cldr-data/main/pt/numbers.json +156 -0
- package/vendor/cldr-data/main/zh/numbers.json +214 -0
- package/vendor/cldr-data/supplemental/likelySubtags.json +1844 -0
- 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
|
+
}
|