@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,166 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.ActivityPrompt = void 0;
|
|
4
|
+
/**
|
|
5
|
+
* Copyright (c) Microsoft Corporation. All rights reserved.
|
|
6
|
+
* Licensed under the MIT License.
|
|
7
|
+
*/
|
|
8
|
+
const agents_hosting_1 = require("@microsoft/agents-hosting");
|
|
9
|
+
const dialog_1 = require("../dialog");
|
|
10
|
+
/**
|
|
11
|
+
* Waits for an activity to be received.
|
|
12
|
+
*
|
|
13
|
+
* @remarks
|
|
14
|
+
* This prompt requires a validator be passed in and is useful when waiting for non-message
|
|
15
|
+
* activities like an event to be received. The validator can ignore received events until the
|
|
16
|
+
* expected activity is received.
|
|
17
|
+
*/
|
|
18
|
+
class ActivityPrompt extends dialog_1.Dialog {
|
|
19
|
+
/**
|
|
20
|
+
* Creates a new ActivityPrompt instance.
|
|
21
|
+
*
|
|
22
|
+
* @param dialogId Unique ID of the dialog within its parent `DialogSet` or `ComponentDialog`.
|
|
23
|
+
* @param validator Validator that will be called each time a new activity is received.
|
|
24
|
+
*/
|
|
25
|
+
constructor(dialogId, validator) {
|
|
26
|
+
super(dialogId);
|
|
27
|
+
this.validator = validator;
|
|
28
|
+
}
|
|
29
|
+
/**
|
|
30
|
+
* Called when a prompt dialog is pushed onto the dialog stack and is being activated.
|
|
31
|
+
*
|
|
32
|
+
* @param dialogContext The DialogContext for the current
|
|
33
|
+
* turn of the conversation.
|
|
34
|
+
* @param options PromptOptions, additional
|
|
35
|
+
* information to pass to the prompt being started.
|
|
36
|
+
* @returns A `Promise` representing the asynchronous operation.
|
|
37
|
+
* @remarks
|
|
38
|
+
* If the promise is successful, the result indicates whether the prompt is still
|
|
39
|
+
* active after the turn has been processed by the prompt.
|
|
40
|
+
*/
|
|
41
|
+
async beginDialog(dialogContext, options) {
|
|
42
|
+
// Ensure prompts have input hint set
|
|
43
|
+
const opt = { ...options };
|
|
44
|
+
if (opt.prompt && typeof opt.prompt === 'object' && typeof opt.prompt.inputHint !== 'string') {
|
|
45
|
+
opt.prompt.inputHint = agents_hosting_1.InputHints.ExpectingInput;
|
|
46
|
+
}
|
|
47
|
+
if (opt.retryPrompt && typeof opt.retryPrompt === 'object' && typeof opt.retryPrompt.inputHint !== 'string') {
|
|
48
|
+
opt.retryPrompt.inputHint = agents_hosting_1.InputHints.ExpectingInput;
|
|
49
|
+
}
|
|
50
|
+
// Initialize prompt state
|
|
51
|
+
const state = dialogContext.activeDialog.state;
|
|
52
|
+
state.options = opt;
|
|
53
|
+
state.state = {};
|
|
54
|
+
// Send initial prompt
|
|
55
|
+
await this.onPrompt(dialogContext.context, state.state, state.options, false);
|
|
56
|
+
return dialog_1.Dialog.EndOfTurn;
|
|
57
|
+
}
|
|
58
|
+
/**
|
|
59
|
+
* Called when a prompt dialog is the active dialog and the user replied with a new activity.
|
|
60
|
+
*
|
|
61
|
+
* @param dialogContext The DialogContext for the current
|
|
62
|
+
* turn of conversation.
|
|
63
|
+
* @returns A `Promise` representing the asynchronous operation.
|
|
64
|
+
* @remarks
|
|
65
|
+
* If the promise is successful, the result indicates whether the dialog is still
|
|
66
|
+
* active after the turn has been processed by the dialog.
|
|
67
|
+
* The prompt generally continues to receive the user's replies until it accepts the
|
|
68
|
+
* user's reply as valid input for the prompt.
|
|
69
|
+
*/
|
|
70
|
+
async continueDialog(dialogContext) {
|
|
71
|
+
// Perform base recognition
|
|
72
|
+
const state = dialogContext.activeDialog.state;
|
|
73
|
+
const recognized = await this.onRecognize(dialogContext.context, state.state, state.options);
|
|
74
|
+
if (state.state['attemptCount'] === undefined) {
|
|
75
|
+
state.state['attemptCount'] = 0;
|
|
76
|
+
}
|
|
77
|
+
// Validate the return value
|
|
78
|
+
// - Unlike the other prompts a validator is required for an ActivityPrompt so we don't
|
|
79
|
+
// need to check for its existence before calling it.
|
|
80
|
+
const isValid = await this.validator({
|
|
81
|
+
context: dialogContext.context,
|
|
82
|
+
recognized,
|
|
83
|
+
state: state.state,
|
|
84
|
+
options: state.options,
|
|
85
|
+
attemptCount: ++state.state['attemptCount'],
|
|
86
|
+
});
|
|
87
|
+
// Return recognized value or re-prompt
|
|
88
|
+
if (isValid) {
|
|
89
|
+
return await dialogContext.endDialog(recognized.value);
|
|
90
|
+
}
|
|
91
|
+
else {
|
|
92
|
+
if (dialogContext.context.activity.type === agents_hosting_1.ActivityTypes.Message && !dialogContext.context.responded) {
|
|
93
|
+
await this.onPrompt(dialogContext.context, state.state, state.options, true);
|
|
94
|
+
}
|
|
95
|
+
return dialog_1.Dialog.EndOfTurn;
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
/**
|
|
99
|
+
* Called when a prompt dialog resumes being the active dialog on the dialog stack, such as
|
|
100
|
+
* when the previous active dialog on the stack completes.
|
|
101
|
+
*
|
|
102
|
+
* @param dialogContext The DialogContext for the current turn
|
|
103
|
+
* of the conversation.
|
|
104
|
+
* @param _reason DialogReason, an enum indicating why
|
|
105
|
+
* the dialog resumed.
|
|
106
|
+
* @param _result Optional. Value returned from the previous dialog on the stack.
|
|
107
|
+
* The type of the value returned is dependent on the previous dialog.
|
|
108
|
+
* @returns A `Promise` representing the asynchronous operation.
|
|
109
|
+
*/
|
|
110
|
+
async resumeDialog(dialogContext, _reason, _result) {
|
|
111
|
+
// Prompts are typically leaf nodes on the stack but the dev is free to push other dialogs
|
|
112
|
+
// on top of the stack which will result in the prompt receiving an unexpected call to
|
|
113
|
+
// resumeDialog() when the pushed on dialog ends.
|
|
114
|
+
// To avoid the prompt prematurely ending we need to implement this method and
|
|
115
|
+
// simply re-prompt the user.
|
|
116
|
+
await this.repromptDialog(dialogContext.context, dialogContext.activeDialog);
|
|
117
|
+
return dialog_1.Dialog.EndOfTurn;
|
|
118
|
+
}
|
|
119
|
+
/**
|
|
120
|
+
* Called when a prompt dialog has been requested to re-prompt the user for input.
|
|
121
|
+
*
|
|
122
|
+
* @param context TurnContext, context for the current
|
|
123
|
+
* turn of conversation with the user.
|
|
124
|
+
* @param instance DialogInstance, the instance
|
|
125
|
+
* of the dialog on the stack.
|
|
126
|
+
* @returns A `Promise` representing the asynchronous operation.
|
|
127
|
+
*/
|
|
128
|
+
async repromptDialog(context, instance) {
|
|
129
|
+
const state = instance.state;
|
|
130
|
+
await this.onPrompt(context, state.state, state.options, false);
|
|
131
|
+
}
|
|
132
|
+
/**
|
|
133
|
+
* When overridden in a derived class, prompts the user for input.
|
|
134
|
+
*
|
|
135
|
+
* @param context TurnContext, context for the current
|
|
136
|
+
* turn of conversation with the user.
|
|
137
|
+
* @param state Contains state for the current instance of the prompt on the dialog stack.
|
|
138
|
+
* @param options A PromptOptions object constructed
|
|
139
|
+
* from the options initially provided in the call to Prompt.
|
|
140
|
+
* @param isRetry A boolean representing if the prompt is a retry.
|
|
141
|
+
* @returns A `Promise` representing the asynchronous operation.
|
|
142
|
+
*/
|
|
143
|
+
async onPrompt(context, state, options, isRetry) {
|
|
144
|
+
if (isRetry && options.retryPrompt) {
|
|
145
|
+
await context.sendActivity(options.retryPrompt, undefined, agents_hosting_1.InputHints.ExpectingInput);
|
|
146
|
+
}
|
|
147
|
+
else if (options.prompt) {
|
|
148
|
+
await context.sendActivity(options.prompt, undefined, agents_hosting_1.InputHints.ExpectingInput);
|
|
149
|
+
}
|
|
150
|
+
}
|
|
151
|
+
/**
|
|
152
|
+
* When overridden in a derived class, attempts to recognize the incoming Activity.
|
|
153
|
+
*
|
|
154
|
+
* @param context TurnContext, context for the current
|
|
155
|
+
* turn of conversation with the user.
|
|
156
|
+
* @param _state Contains state for the current instance of the prompt on the dialog stack.
|
|
157
|
+
* @param _options A PromptOptions object constructed
|
|
158
|
+
* from the options initially provided in the call to Prompt.
|
|
159
|
+
* @returns A `Promise` representing the asynchronous operation.
|
|
160
|
+
*/
|
|
161
|
+
async onRecognize(context, _state, _options) {
|
|
162
|
+
return { succeeded: true, value: context.activity };
|
|
163
|
+
}
|
|
164
|
+
}
|
|
165
|
+
exports.ActivityPrompt = ActivityPrompt;
|
|
166
|
+
//# sourceMappingURL=activityPrompt.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"activityPrompt.js","sourceRoot":"","sources":["../../../src/prompts/activityPrompt.ts"],"names":[],"mappings":";;;AAAA;;;GAGG;AACH,8DAA4F;AAC5F,sCAAkC;AAOlC;;;;;;;GAOG;AACH,MAAa,cAAe,SAAQ,eAAM;IACxC;;;;;SAKK;IACL,YACE,QAAgB,EACR,SAAoC;QAE5C,KAAK,CAAC,QAAQ,CAAC,CAAA;QAFP,cAAS,GAAT,SAAS,CAA2B;IAG9C,CAAC;IAED;;;;;;;;;;;SAWK;IACL,KAAK,CAAC,WAAW,CAAE,aAA4B,EAAE,OAAsB;QACrE,qCAAqC;QACrC,MAAM,GAAG,GAA2B,EAAE,GAAG,OAAO,EAAE,CAAA;QAClD,IAAI,GAAG,CAAC,MAAM,IAAI,OAAO,GAAG,CAAC,MAAM,KAAK,QAAQ,IAAI,OAAO,GAAG,CAAC,MAAM,CAAC,SAAS,KAAK,QAAQ,EAAE,CAAC;YAC7F,GAAG,CAAC,MAAM,CAAC,SAAS,GAAG,2BAAU,CAAC,cAAc,CAAA;QAClD,CAAC;QACD,IAAI,GAAG,CAAC,WAAW,IAAI,OAAO,GAAG,CAAC,WAAW,KAAK,QAAQ,IAAI,OAAO,GAAG,CAAC,WAAW,CAAC,SAAS,KAAK,QAAQ,EAA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AAC,MAAM,EAAE,CAAC;YAC1B,MAAM,OAAO,CAAC,YAAY,CAAC,OAAO,CAAC,MAAM,EAAE,SAAS,EAAE,2BAAU,CAAC,cAAc,CAAC,CAAA;QAClF,CAAC;IACH,CAAC;IAED;;;;;;;;;SASK;IACK,KAAK,CAAC,WAAW,CACzB,OAAoB,EACpB,MAAc,EACd,QAAuB;QAEvB,OAAO,EAAE,SAAS,EAAE,IAAI,EAAE,KAAK,EAAE,OAAO,CAAC,QAAQ,EAAE,CAAA;IACrD,CAAC;CACF;AA7KD,wCA6KC"}
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright (c) Microsoft Corporation. All rights reserved.
|
|
3
|
+
* Licensed under the MIT License.
|
|
4
|
+
*/
|
|
5
|
+
import { Attachment, TurnContext } from '@microsoft/agents-hosting';
|
|
6
|
+
import { Prompt, PromptOptions, PromptRecognizerResult, PromptValidator } from './prompt';
|
|
7
|
+
/**
|
|
8
|
+
* Prompts a user to upload attachments like images.
|
|
9
|
+
*
|
|
10
|
+
* @remarks
|
|
11
|
+
* By default the prompt will return to the calling dialog an `Attachment[]`.
|
|
12
|
+
*/
|
|
13
|
+
export declare class AttachmentPrompt extends Prompt<Attachment[]> {
|
|
14
|
+
constructor(dialogId: string, validator?: PromptValidator<Attachment[]>);
|
|
15
|
+
/**
|
|
16
|
+
* Prompts the user for input.
|
|
17
|
+
*
|
|
18
|
+
* @param context Context for the current turn of conversation with the user.
|
|
19
|
+
* @param state Contains state for the current instance of the prompt on the dialog stack.
|
|
20
|
+
* @param options A prompt options object constructed from the options initially provided
|
|
21
|
+
* in the call to Prompt.
|
|
22
|
+
* @param isRetry `true` if this is the first time this prompt dialog instance
|
|
23
|
+
* on the stack is prompting the user for input; otherwise, false.
|
|
24
|
+
* @returns A Promise representing the asynchronous operation.
|
|
25
|
+
*/
|
|
26
|
+
protected onPrompt(context: TurnContext, state: any, options: PromptOptions, isRetry: boolean): Promise<void>;
|
|
27
|
+
/**
|
|
28
|
+
* Attempts to recognize the user's input.
|
|
29
|
+
*
|
|
30
|
+
* @param context Context for the current turn of conversation with the user.
|
|
31
|
+
* @param _state Contains state for the current instance of the prompt on the dialog stack.
|
|
32
|
+
* @param _options A prompt options object constructed from the options initially provided
|
|
33
|
+
* in the call to Prompt.
|
|
34
|
+
* @returns A Promise representing the asynchronous operation.
|
|
35
|
+
*/
|
|
36
|
+
protected onRecognize(context: TurnContext, _state: any, _options: PromptOptions): Promise<PromptRecognizerResult<Attachment[]>>;
|
|
37
|
+
}
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.AttachmentPrompt = void 0;
|
|
4
|
+
/**
|
|
5
|
+
* Copyright (c) Microsoft Corporation. All rights reserved.
|
|
6
|
+
* Licensed under the MIT License.
|
|
7
|
+
*/
|
|
8
|
+
const agents_hosting_1 = require("@microsoft/agents-hosting");
|
|
9
|
+
const prompt_1 = require("./prompt");
|
|
10
|
+
/**
|
|
11
|
+
* Prompts a user to upload attachments like images.
|
|
12
|
+
*
|
|
13
|
+
* @remarks
|
|
14
|
+
* By default the prompt will return to the calling dialog an `Attachment[]`.
|
|
15
|
+
*/
|
|
16
|
+
class AttachmentPrompt extends prompt_1.Prompt {
|
|
17
|
+
// eslint-disable-next-line @typescript-eslint/no-useless-constructor
|
|
18
|
+
constructor(dialogId, validator) {
|
|
19
|
+
super(dialogId, validator);
|
|
20
|
+
}
|
|
21
|
+
/**
|
|
22
|
+
* Prompts the user for input.
|
|
23
|
+
*
|
|
24
|
+
* @param context Context for the current turn of conversation with the user.
|
|
25
|
+
* @param state Contains state for the current instance of the prompt on the dialog stack.
|
|
26
|
+
* @param options A prompt options object constructed from the options initially provided
|
|
27
|
+
* in the call to Prompt.
|
|
28
|
+
* @param isRetry `true` if this is the first time this prompt dialog instance
|
|
29
|
+
* on the stack is prompting the user for input; otherwise, false.
|
|
30
|
+
* @returns A Promise representing the asynchronous operation.
|
|
31
|
+
*/
|
|
32
|
+
async onPrompt(context, state, options, isRetry) {
|
|
33
|
+
if (isRetry && options.retryPrompt) {
|
|
34
|
+
await context.sendActivity(options.retryPrompt, undefined, agents_hosting_1.InputHints.ExpectingInput);
|
|
35
|
+
}
|
|
36
|
+
else if (options.prompt) {
|
|
37
|
+
await context.sendActivity(options.prompt, undefined, agents_hosting_1.InputHints.ExpectingInput);
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
/**
|
|
41
|
+
* Attempts to recognize the user's input.
|
|
42
|
+
*
|
|
43
|
+
* @param context Context for the current 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 prompt options object constructed from the options initially provided
|
|
46
|
+
* in the call to Prompt.
|
|
47
|
+
* @returns A Promise representing the asynchronous operation.
|
|
48
|
+
*/
|
|
49
|
+
async onRecognize(context, _state, _options) {
|
|
50
|
+
const value = context.activity.attachments;
|
|
51
|
+
return Array.isArray(value) && value.length > 0 ? { succeeded: true, value } : { succeeded: false };
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
exports.AttachmentPrompt = AttachmentPrompt;
|
|
55
|
+
//# sourceMappingURL=attachmentPrompt.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"attachmentPrompt.js","sourceRoot":"","sources":["../../../src/prompts/attachmentPrompt.ts"],"names":[],"mappings":";;;AAAA;;;GAGG;AACH,8DAA+E;AAC/E,qCAAyF;AAEzF;;;;;GAKG;AACH,MAAa,gBAAiB,SAAQ,eAAoB;IACxD,qEAAqE;IACrE,YAAa,QAAgB,EAAE,SAAyC;QACtE,KAAK,CAAC,QAAQ,EAAE,SAAS,CAAC,CAAA;IAC5B,CAAC;IAED;;;;;;;;;;SAUK;IACK,KAAK,CAAC,QAAQ,CACtB,OAAoB,EACpB,KAAU,EACV,OAAsB,EACtB,OAAgB;QAEhB,IAAI,OAAO,IAAI,OAAO,CAAC,WAAW,EAAE,CAAC;YACnC,MAAM,OAAO,CAAC,YAAY,CAAC,OAAO,CAAC,WAAW,EAAE,SAAS,EAAE,2BAAU,CAAC,cAAc,CAAC,CAAA;QACvF,CAAC;aAAM,IAAI,OAAO,CAAC,MAAM,EAAE,CAAC;YAC1B,MAAM,OAAO,CAAC,YAAY,CAAC,OAAO,CAAC,MAAM,EAAE,SAAS,EAAE,2BAAU,CAAC,cAAc,CAAC,CAAA;QAClF,CAAC;IACH,CAAC;IAED;;;;;;;;SAQK;IACK,KAAK,CAAC,WAAW,CACzB,OAAoB,EACpB,MAAW,EACX,QAAuB;QAEvB,MAAM,KAAK,GAAiB,OAAO,CAAC,QAAQ,CAAC,WAAW,CAAA;QAExD,OAAO,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC,IAAI,KAAK,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC,CAAC,EAAE,SAAS,EAAE,IAAI,EAAE,KAAK,EAAE,CAAC,CAAC,CAAC,EAAE,SAAS,EAAE,KAAK,EAAE,CAAA;IACrG,CAAC;CACF;AAhDD,4CAgDC"}
|
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright (c) Microsoft Corporation. All rights reserved.
|
|
3
|
+
* Licensed under the MIT License.
|
|
4
|
+
*/
|
|
5
|
+
import { TurnContext } from '@microsoft/agents-hosting';
|
|
6
|
+
import { ChoiceFactoryOptions, FindChoicesOptions, FoundChoice } from '../choices';
|
|
7
|
+
import { ListStyle, Prompt, PromptOptions, PromptRecognizerResult, PromptValidator } from './prompt';
|
|
8
|
+
interface ChoiceDefaultsChoicePrompt {
|
|
9
|
+
[locale: string]: ChoiceFactoryOptions;
|
|
10
|
+
}
|
|
11
|
+
/**
|
|
12
|
+
* Prompts a user to select from a list of choices.
|
|
13
|
+
*
|
|
14
|
+
* @remarks
|
|
15
|
+
* By default the prompt will return to the calling dialog a `FoundChoice` object containing the
|
|
16
|
+
* choice that was selected.
|
|
17
|
+
*/
|
|
18
|
+
export declare class ChoicePrompt extends Prompt<FoundChoice> {
|
|
19
|
+
/**
|
|
20
|
+
* A dictionary of Default Choices based on [[PromptCultureModels.getSupportedCultures()]].
|
|
21
|
+
* Can be replaced by user using the constructor that contains choiceDefaults.
|
|
22
|
+
*/
|
|
23
|
+
private choiceDefaults;
|
|
24
|
+
/**
|
|
25
|
+
* The prompts default locale that should be recognized.
|
|
26
|
+
*/
|
|
27
|
+
defaultLocale: string | undefined;
|
|
28
|
+
/**
|
|
29
|
+
* Style of the "yes" and "no" choices rendered to the user when prompting.
|
|
30
|
+
*
|
|
31
|
+
* @remarks
|
|
32
|
+
* Defaults to `ListStyle.auto`.
|
|
33
|
+
*/
|
|
34
|
+
style: ListStyle;
|
|
35
|
+
/**
|
|
36
|
+
* Additional options passed to the `ChoiceFactory` and used to tweak the style of choices
|
|
37
|
+
* rendered to the user.
|
|
38
|
+
*/
|
|
39
|
+
choiceOptions: ChoiceFactoryOptions | undefined;
|
|
40
|
+
/**
|
|
41
|
+
* Additional options passed to the underlying `recognizeChoices()` function.
|
|
42
|
+
*/
|
|
43
|
+
recognizerOptions: FindChoicesOptions | undefined;
|
|
44
|
+
/**
|
|
45
|
+
* Creates a new `ChoicePrompt` instance.
|
|
46
|
+
*
|
|
47
|
+
* @param dialogId Unique ID of the dialog within its parent `DialogSet`.
|
|
48
|
+
* @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.
|
|
49
|
+
* @param defaultLocale (Optional) locale to use if `dc.context.activity.locale` not specified. Defaults to a value of `en-us`.
|
|
50
|
+
* @param choiceDefaults (Optional) Overrides the dictionary of Bot Framework SDK-supported _choiceDefaults (for prompt localization).
|
|
51
|
+
* Must be passed in to each ConfirmPrompt that needs the custom choice defaults.
|
|
52
|
+
*/
|
|
53
|
+
constructor(dialogId: string, validator?: PromptValidator<FoundChoice>, defaultLocale?: string, choiceDefaults?: ChoiceDefaultsChoicePrompt);
|
|
54
|
+
/**
|
|
55
|
+
* Prompts the user for input.
|
|
56
|
+
*
|
|
57
|
+
* @param context TurnContext, context for the current
|
|
58
|
+
* turn of conversation with the user.
|
|
59
|
+
* @param state Contains state for the current instance of the prompt on the dialog stack.
|
|
60
|
+
* @param options A PromptOptions object constructed
|
|
61
|
+
* from the options initially provided in the call to Prompt.
|
|
62
|
+
* @param isRetry `true` if this is the first time this prompt dialog instance
|
|
63
|
+
* on the stack is prompting the user for input; otherwise, false.
|
|
64
|
+
* @returns A `Promise` representing the asynchronous operation.
|
|
65
|
+
*/
|
|
66
|
+
protected onPrompt(context: TurnContext, state: any, options: PromptOptions, isRetry: boolean): Promise<void>;
|
|
67
|
+
/**
|
|
68
|
+
* Attempts to recognize the user's input.
|
|
69
|
+
*
|
|
70
|
+
* @param context TurnContext context for the current
|
|
71
|
+
* turn of conversation with the user.
|
|
72
|
+
* @param state Contains state for the current instance of the prompt on the dialog stack.
|
|
73
|
+
* @param options A PromptOptions object constructed
|
|
74
|
+
* from the options initially provided in the call to Prompt.
|
|
75
|
+
* @returns A `Promise` representing the asynchronous operation.
|
|
76
|
+
*/
|
|
77
|
+
protected onRecognize(context: TurnContext, state: any, options: PromptOptions): Promise<PromptRecognizerResult<FoundChoice>>;
|
|
78
|
+
/**
|
|
79
|
+
* @private
|
|
80
|
+
*/
|
|
81
|
+
private determineCulture;
|
|
82
|
+
}
|
|
83
|
+
export {};
|
|
@@ -0,0 +1,116 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.ChoicePrompt = void 0;
|
|
4
|
+
const choices_1 = require("../choices");
|
|
5
|
+
const prompt_1 = require("./prompt");
|
|
6
|
+
const promptCultureModels_1 = require("./promptCultureModels");
|
|
7
|
+
/**
|
|
8
|
+
* Prompts a user to select from a list of choices.
|
|
9
|
+
*
|
|
10
|
+
* @remarks
|
|
11
|
+
* By default the prompt will return to the calling dialog a `FoundChoice` object containing the
|
|
12
|
+
* choice that was selected.
|
|
13
|
+
*/
|
|
14
|
+
class ChoicePrompt extends prompt_1.Prompt {
|
|
15
|
+
/**
|
|
16
|
+
* Creates a new `ChoicePrompt` instance.
|
|
17
|
+
*
|
|
18
|
+
* @param dialogId Unique ID of the dialog within its parent `DialogSet`.
|
|
19
|
+
* @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.
|
|
20
|
+
* @param defaultLocale (Optional) locale to use if `dc.context.activity.locale` not specified. Defaults to a value of `en-us`.
|
|
21
|
+
* @param choiceDefaults (Optional) Overrides the dictionary of Bot Framework SDK-supported _choiceDefaults (for prompt localization).
|
|
22
|
+
* Must be passed in to each ConfirmPrompt that needs the custom choice defaults.
|
|
23
|
+
*/
|
|
24
|
+
constructor(dialogId, validator, defaultLocale, choiceDefaults) {
|
|
25
|
+
super(dialogId, validator);
|
|
26
|
+
this.style = prompt_1.ListStyle.auto;
|
|
27
|
+
this.defaultLocale = defaultLocale;
|
|
28
|
+
if (choiceDefaults === undefined) {
|
|
29
|
+
const supported = {};
|
|
30
|
+
promptCultureModels_1.PromptCultureModels.getSupportedCultures().forEach((culture) => {
|
|
31
|
+
supported[culture.locale] = {
|
|
32
|
+
inlineSeparator: culture.separator,
|
|
33
|
+
inlineOr: culture.inlineOr,
|
|
34
|
+
inlineOrMore: culture.inlineOrMore,
|
|
35
|
+
includeNumbers: true,
|
|
36
|
+
};
|
|
37
|
+
});
|
|
38
|
+
this.choiceDefaults = supported;
|
|
39
|
+
}
|
|
40
|
+
else {
|
|
41
|
+
this.choiceDefaults = choiceDefaults;
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
/**
|
|
45
|
+
* Prompts the user for input.
|
|
46
|
+
*
|
|
47
|
+
* @param context TurnContext, context for the current
|
|
48
|
+
* turn of conversation with the user.
|
|
49
|
+
* @param state Contains state for the current instance of the prompt on the dialog stack.
|
|
50
|
+
* @param options A PromptOptions object constructed
|
|
51
|
+
* from the options initially provided in the call to Prompt.
|
|
52
|
+
* @param isRetry `true` if this is the first time this prompt dialog instance
|
|
53
|
+
* on the stack is prompting the user for input; otherwise, false.
|
|
54
|
+
* @returns A `Promise` representing the asynchronous operation.
|
|
55
|
+
*/
|
|
56
|
+
async onPrompt(context, state, options, isRetry) {
|
|
57
|
+
// Determine locale
|
|
58
|
+
const locale = this.determineCulture(context.activity);
|
|
59
|
+
// Format prompt to send
|
|
60
|
+
let prompt;
|
|
61
|
+
const choices = (this.style === prompt_1.ListStyle.suggestedAction ? choices_1.ChoiceFactory.toChoices(options.choices) : options.choices) ||
|
|
62
|
+
[];
|
|
63
|
+
const channelId = context.activity.channelId;
|
|
64
|
+
const choiceOptions = this.choiceOptions || this.choiceDefaults[locale];
|
|
65
|
+
const choiceStyle = options.style === 0 ? 0 : options.style || this.style;
|
|
66
|
+
if (isRetry && options.retryPrompt) {
|
|
67
|
+
prompt = this.appendChoices(options.retryPrompt, channelId, choices, choiceStyle, choiceOptions);
|
|
68
|
+
}
|
|
69
|
+
else {
|
|
70
|
+
prompt = this.appendChoices(options.prompt, channelId, choices, choiceStyle, choiceOptions);
|
|
71
|
+
}
|
|
72
|
+
// Send prompt
|
|
73
|
+
await context.sendActivity(prompt);
|
|
74
|
+
}
|
|
75
|
+
/**
|
|
76
|
+
* Attempts to recognize the user's input.
|
|
77
|
+
*
|
|
78
|
+
* @param context TurnContext context for the current
|
|
79
|
+
* turn of conversation with the user.
|
|
80
|
+
* @param state Contains state for the current instance of the prompt on the dialog stack.
|
|
81
|
+
* @param options A PromptOptions object constructed
|
|
82
|
+
* from the options initially provided in the call to Prompt.
|
|
83
|
+
* @returns A `Promise` representing the asynchronous operation.
|
|
84
|
+
*/
|
|
85
|
+
async onRecognize(context, state, options) {
|
|
86
|
+
const result = { succeeded: false };
|
|
87
|
+
const activity = context.activity;
|
|
88
|
+
const utterance = activity.text;
|
|
89
|
+
if (!utterance) {
|
|
90
|
+
return result;
|
|
91
|
+
}
|
|
92
|
+
const choices = (this.style === prompt_1.ListStyle.suggestedAction ? choices_1.ChoiceFactory.toChoices(options.choices) : options.choices) ||
|
|
93
|
+
[];
|
|
94
|
+
const opt = this.recognizerOptions || {};
|
|
95
|
+
opt.locale = this.determineCulture(activity, opt);
|
|
96
|
+
const results = (0, choices_1.recognizeChoices)(utterance, choices, opt);
|
|
97
|
+
if (Array.isArray(results) && results.length > 0) {
|
|
98
|
+
result.succeeded = true;
|
|
99
|
+
result.value = results[0].resolution;
|
|
100
|
+
}
|
|
101
|
+
return result;
|
|
102
|
+
}
|
|
103
|
+
/**
|
|
104
|
+
* @private
|
|
105
|
+
*/
|
|
106
|
+
determineCulture(activity, opt) {
|
|
107
|
+
const optLocale = opt && opt.locale ? opt.locale : null;
|
|
108
|
+
let culture = promptCultureModels_1.PromptCultureModels.mapToNearestLanguage(activity.locale || optLocale || this.defaultLocale || promptCultureModels_1.PromptCultureModels.English.locale);
|
|
109
|
+
if (!(culture && this.choiceDefaults[culture])) {
|
|
110
|
+
culture = promptCultureModels_1.PromptCultureModels.English.locale;
|
|
111
|
+
}
|
|
112
|
+
return culture;
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
exports.ChoicePrompt = ChoicePrompt;
|
|
116
|
+
//# sourceMappingURL=choicePrompt.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"choicePrompt.js","sourceRoot":"","sources":["../../../src/prompts/choicePrompt.ts"],"names":[],"mappings":";;;AAKA,wCAAmH;AACnH,qCAAoG;AACpG,+DAA2D;AAO3D;;;;;;GAMG;AACH,MAAa,YAAa,SAAQ,eAAmB;IA+BnD;;;;;;;;SAQK;IACL,YACE,QAAgB,EAChB,SAAwC,EACxC,aAAsB,EACtB,cAA2C;QAE3C,KAAK,CAAC,QAAQ,EAAE,SAAS,CAAC,CAAA;QAC1B,IAAI,CAAC,KAAK,GAAG,kBAAS,CAAC,IAAI,CAAA;QAC3B,IAAI,CAAC,aAAa,GAAG,aAAa,CA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AAC,MAAM,GAAG,CAAC,EAAE,CAAC;YACjD,MAAM,CAAC,SAAS,GAAG,IAAI,CAAA;YACvB,MAAM,CAAC,KAAK,GAAG,OAAO,CAAC,CAAC,CAAC,CAAC,UAAU,CAAA;QACtC,CAAC;QAED,OAAO,MAAM,CAAA;IACf,CAAC;IAED;;SAEK;IACG,gBAAgB,CAAE,QAAkB,EAAE,GAAwB;QACpE,MAAM,SAAS,GAAG,GAAG,IAAI,GAAG,CAAC,MAAM,CAAC,CAAC,CAAC,GAAG,CAAC,MAAM,CAAC,CAAC,CAAC,IAAI,CAAA;QACvD,IAAI,OAAO,GAAG,yCAAmB,CAAC,oBAAoB,CACpD,QAAQ,CAAC,MAAM,IAAI,SAAS,IAAI,IAAI,CAAC,aAAa,IAAI,yCAAmB,CAAC,OAAO,CAAC,MAAM,CACzF,CAAA;QACD,IAAI,CAAC,CAAC,OAAO,IAAI,IAAI,CAAC,cAAc,CAAC,OAAO,CAAC,CAAC,EAAE,CAAC;YAC/C,OAAO,GAAG,yCAAmB,CAAC,OAAO,CAAC,MAAM,CAAA;QAC9C,CAAC;QAED,OAAO,OAAO,CAAA;IAChB,CAAC;CACF;AA1JD,oCA0JC"}
|
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
import { TurnContext } from '@microsoft/agents-hosting';
|
|
2
|
+
import { Choice, ChoiceFactoryOptions } from '../choices';
|
|
3
|
+
import { ListStyle, Prompt, PromptOptions, PromptRecognizerResult, PromptValidator } from './prompt';
|
|
4
|
+
interface ChoiceDefaultsConfirmPrompt {
|
|
5
|
+
[locale: string]: {
|
|
6
|
+
choices: (string | Choice)[];
|
|
7
|
+
options: ChoiceFactoryOptions;
|
|
8
|
+
};
|
|
9
|
+
}
|
|
10
|
+
/**
|
|
11
|
+
* Prompts a user to confirm something with a "yes" or "no" response.
|
|
12
|
+
*
|
|
13
|
+
* @remarks
|
|
14
|
+
* By default the prompt will return to the calling dialog a `boolean` representing the users
|
|
15
|
+
* selection.
|
|
16
|
+
*/
|
|
17
|
+
export declare class ConfirmPrompt extends Prompt<boolean> {
|
|
18
|
+
/**
|
|
19
|
+
* A dictionary of Default Choices based on [[PromptCultureModels.getSupportedCultures()]].
|
|
20
|
+
* Can be replaced by user using the constructor that contains choiceDefaults.
|
|
21
|
+
* This is initially set in the constructor.
|
|
22
|
+
*/
|
|
23
|
+
private choiceDefaults;
|
|
24
|
+
/**
|
|
25
|
+
* The prompts default locale that should be recognized.
|
|
26
|
+
*/
|
|
27
|
+
defaultLocale: string | undefined;
|
|
28
|
+
/**
|
|
29
|
+
* Style of the "yes" and "no" choices rendered to the user when prompting.
|
|
30
|
+
*
|
|
31
|
+
* @remarks
|
|
32
|
+
* Defaults to `ListStyle.auto`.
|
|
33
|
+
*/
|
|
34
|
+
style: ListStyle;
|
|
35
|
+
/**
|
|
36
|
+
* Additional options passed to the `ChoiceFactory` and used to tweak the style of choices
|
|
37
|
+
* rendered to the user.
|
|
38
|
+
*/
|
|
39
|
+
choiceOptions: ChoiceFactoryOptions | undefined;
|
|
40
|
+
/**
|
|
41
|
+
* Custom list of choices to send for the prompt.
|
|
42
|
+
*/
|
|
43
|
+
confirmChoices: (string | Choice)[] | undefined;
|
|
44
|
+
/**
|
|
45
|
+
* Creates a new ConfirmPrompt instance.
|
|
46
|
+
*
|
|
47
|
+
* @param dialogId Unique ID of the dialog within its parent `DialogSet` or `ComponentDialog`.
|
|
48
|
+
* @param validator (Optional) validator that will be called each time the user responds to the prompt.
|
|
49
|
+
* @param defaultLocale (Optional) locale to use if `TurnContext.activity.locale` is not specified. Defaults to a value of `en-us`.
|
|
50
|
+
* @param choiceDefaults (Optional) Overrides the dictionary of Default Choices on [[PromptCultureModels.getSupportedCultures()]].
|
|
51
|
+
*/
|
|
52
|
+
constructor(dialogId: string, validator?: PromptValidator<boolean>, defaultLocale?: string, choiceDefaults?: ChoiceDefaultsConfirmPrompt);
|
|
53
|
+
/**
|
|
54
|
+
* Prompts the user for input.
|
|
55
|
+
*
|
|
56
|
+
* @param context TurnContext, context for the current
|
|
57
|
+
* turn of conversation with the user.
|
|
58
|
+
* @param state Contains state for the current instance of the prompt on the dialog stack.
|
|
59
|
+
* @param options A PromptOptions object constructed
|
|
60
|
+
* from the options initially provided in the call to Prompt.
|
|
61
|
+
* @param isRetry `true` if this is the first time this prompt dialog instance
|
|
62
|
+
* on the stack is prompting the user for input; otherwise, false.
|
|
63
|
+
* @returns A `Promise` representing the asynchronous operation.
|
|
64
|
+
*/
|
|
65
|
+
protected onPrompt(context: TurnContext, state: any, options: PromptOptions, isRetry: boolean): Promise<void>;
|
|
66
|
+
/**
|
|
67
|
+
* Attempts to recognize the user's input.
|
|
68
|
+
*
|
|
69
|
+
* @param context TurnContext, context for the current
|
|
70
|
+
* turn of conversation with the user.
|
|
71
|
+
* @param _state Contains state for the current instance of the prompt on the dialog stack.
|
|
72
|
+
* @param _options A PromptOptions object constructed
|
|
73
|
+
* from the options initially provided in the call to Prompt.
|
|
74
|
+
* @returns A `Promise` representing the asynchronous operation.
|
|
75
|
+
*/
|
|
76
|
+
protected onRecognize(context: TurnContext, _state: any, _options: PromptOptions): Promise<PromptRecognizerResult<boolean>>;
|
|
77
|
+
/**
|
|
78
|
+
* @private
|
|
79
|
+
*/
|
|
80
|
+
private determineCulture;
|
|
81
|
+
}
|
|
82
|
+
export {};
|