Categories:
Aura utils
Aura utils is an utility found in Aura Bot common library to manage dialogs and prompts
Introduction
Aura utils utility allows managing Aura dialogs and prompts.
Find more information in the Github repository: https://github.com/Telefonica/aura-common-utilities/tree/master/packages/aura-bot-utilities/src/aura-bot-common/utils
It contains different methods, described in the following sections.
DialogUtils
Generic tools for any dialog.
setDataActiveDialog
It saves data between steps of a waterfall. Only valid in the same dialog.
| param | type | description | mandatory |
|---|---|---|---|
| context | WaterfallStepContext | Context in a step of a Waterfall | yes |
| keyData | string | Key to recover data saved | yes |
| data | any | Data to be saved | yes |
DialogUtils.setDataActiveDialog(stepContext, KEY_DESCRIPTION, description);
getDataActiveDialog
It gets data between the steps of a Waterfall through an identifier.
| param | type | description | mandatory |
|---|---|---|---|
| context | WaterfallStepContext | Context in a step of a Waterfall | yes |
| keyData | string | Key to recover data saved | yes |
const description = DialogUtils.getDataActiveDialog(stepContext, KEY_DESCRIPTION);
getResourcePath
It gets the whole resource path uploaded to blob-storage to be included in cards.
| param | type | description | mandatory |
|---|---|---|---|
| libraryName | string | Original file name, that was uploaded to the blob-storage. | yes |
| baseFilePath | string | Path in Azure Storage from library name (static-resources/libraries/library_name) to resource name. | yes |
| configuration | Configuration | Set of of configuration variables. | yes |
const uriGenericRaw= DialogUtils.getResourcePath('generic', `${this.configuration.GENERIC_RESOURCES_BASE_PATH}/config/${this.configuration.GENERIC_RAW_NAME}`, this.configuration)
If we need a full URL image path including device resolution, getImageUrl method from @telefonica/aura-bot-library-util should be used instead.
isDeeplink
It returns true if the passed URL is a deeplink, and false otherwise.
| param | type | description | mandatory |
|---|---|---|---|
| url | string | URL to check. | yes |
const isDeepLink = DialogUtils.isDeeplink('http://movistar.es/campain/ahora.html')
PromptUtils
getRetriesValidator
It gets a validator function that will be called each time the user responds to the prompt. In this function, it controls the number of retries to show the prompt.
If attempt is allowed, it is the recognizer that will let an attempt (when there are not results) or the dialog the will manage the result found.
If the retries exceed to maxRetries parameter, the control will be returned to dialog, managing results or not.
If an attempt is shown, the configured retryPrompt (or the same prompt as default) will be shown.
| param | type | description | mandatory |
|---|---|---|---|
| maxRetries | number | Number of retries to show the prompt | yes |
// Create a ChoicePrompt without retries
const myPrompt = new ChoicePrompt(ID_PROMPT,PromptUtils.getRetriesControl(0));
getRetriesValidatorAndOverwriteRecognizerResult
This validator function is similar to getRetriesValidator but also overwrites the recognizer result obtained by the prompt recognizer with a previous stored value.
This recognizer result value can be set with the function ContextUtils.setPromptRecognizedResult. By default, the result is: prompt-check-recognizer-middleware.
| param | type | description | mandatory |
|---|---|---|---|
| maxRetries | number | Number of retries to show the prompt | yes |
// Create a ChoicePrompt with 3 retries and use of ordinals control overwriting promptRecognizedResult with the value of aura-bot.
const myPrompt = new ChoicePrompt(ID_PROMPT,PromptUtils.getRetriesValidatorAndOverwriteRecognizerResult(3));
getAbsolutePath
It returns an absolute normalized file path.
| param | type | description | mandatory |
|---|---|---|---|
| filePath | string | File path to convert | yes |
const path: string = getAbsolutePath('/test/demo_path.txt');