How to use adaptive-expressions - 10 common examples

To help you get started, we’ve selected a few adaptive-expressions examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github microsoft / BotBuilder-Samples / experimental / adaptive-dialog / javascript_nodejs / 05.multi-turn-prompt / dialogs / userProfileDialog.js View on Github external
constructor() {
        super('userProfileDialog');
        let lgFile = Templates.parseFile(path.join(__dirname, "userProfileDialog.lg"));
        let userProfileAdaptiveDialog = new AdaptiveDialog(ROOT_DIALOG).configure({
            generator: new TemplateEngineLanguageGenerator(lgFile),
            triggers: [
                new OnBeginDialog([
                    // Ask for user's age and set it in user.userProfile scope.
                    new TextInput().configure(
                    {
                        // Set the output of the text input to this property in memory.
                        property: new StringExpression("user.userProfile.Transport"),
                        prompt: new ActivityTemplate("${ModeOfTransportPrompt.Text()}")
                    }),
                    new TextInput().configure(
                    {
                        property: new StringExpression("user.userProfile.Name"),
                        prompt: new ActivityTemplate("${AskForName()}")
                    }),
                    // SendActivity supports full language generation resolution.
                    // See here to learn more about language generation
                    // https://aka.ms/language-generation
                    new SendActivity("${AckName()}"),
                    new ConfirmInput().configure(
                    {
                        property: new StringExpression("turn.ageConfirmation"),
                        prompt: new ActivityTemplate("${AgeConfirmPrompt()}")
                    }),
github microsoft / BotBuilder-Samples / experimental / adaptive-dialog / javascript_nodejs / 05.multi-turn-prompt / dialogs / userProfileDialog.js View on Github external
elseActions: [
                            new SendActivity("${NoAge()}") 
                        ]
                    }),
                    new IfCondition().configure(
                    {
                        condition: new BoolExpression("turn.activity.channelId == 'msteams'"),
                        actions: [
                            // This attachment prompt example is not designed to work for Teams attachments, so skip it in this case
                            new SendActivity('Skipping attachment prompt in Teams channel...')
                        ],
                        elseActions: [
                            new AttachmentInput().configure(
                            {
                                prompt: new ActivityTemplate("${AskForImage()}"),
                                property: new StringExpression("user.userProfile.picture"),
                                validations: [
                                    "this.value.contentType == 'image/jpeg' || this.value.contentType == 'image/png'"
                                ],
                                invalidPrompt: new ActivityTemplate("${AskForImage.Invalid()}")
                            })
                        ]
                    }),
                    new ConfirmInput().configure(
                    {
                        prompt: new ActivityTemplate("${ConfirmPrompt()}"),
                        property: new StringExpression("turn.finalConfirmation")
                    }),
                    // Use LG template to come back with the final read out.
                    // This LG template is a great example of what logic can be wrapped up in LG sub-system.
                    new SendActivity("${FinalUserProfileReadOut()}"), // examines turn.finalConfirmation
                ])
github microsoft / BotBuilder-Samples / experimental / adaptive-dialog / javascript_nodejs / 05.multi-turn-prompt / dialogs / userProfileDialog.js View on Github external
elseActions: [
                            new AttachmentInput().configure(
                            {
                                prompt: new ActivityTemplate("${AskForImage()}"),
                                property: new StringExpression("user.userProfile.picture"),
                                validations: [
                                    "this.value.contentType == 'image/jpeg' || this.value.contentType == 'image/png'"
                                ],
                                invalidPrompt: new ActivityTemplate("${AskForImage.Invalid()}")
                            })
                        ]
                    }),
                    new ConfirmInput().configure(
                    {
                        prompt: new ActivityTemplate("${ConfirmPrompt()}"),
                        property: new StringExpression("turn.finalConfirmation")
                    }),
                    // Use LG template to come back with the final read out.
                    // This LG template is a great example of what logic can be wrapped up in LG sub-system.
                    new SendActivity("${FinalUserProfileReadOut()}"), // examines turn.finalConfirmation
                ])
            ]
        });
        this.addDialog(userProfileAdaptiveDialog);
        this.initialDialogId = ROOT_DIALOG;
    }
}
github microsoft / BotBuilder-Samples / experimental / adaptive-dialog / javascript_nodejs / 05.multi-turn-prompt / dialogs / userProfileDialog.js View on Github external
new SendActivity("${AckName()}"),
                    new ConfirmInput().configure(
                    {
                        property: new StringExpression("turn.ageConfirmation"),
                        prompt: new ActivityTemplate("${AgeConfirmPrompt()}")
                    }),
                    new IfCondition().configure(
                    {
                        // All conditions are expressed using the common expression language.
                        // See https://aka.ms/adaptive-expressions to learn more
                        condition: new BoolExpression("turn.ageConfirmation == true"),
                        actions: [
                            new NumberInput().configure(
                            {
                                prompt: new ActivityTemplate("${AskForAge()}"),
                                property: new StringExpression("user.userProfile.Age"),
                                // Add validations
                                validations: [
                                    // Age must be greater than or equal 1
                                    "int(this.value) >= 1",
                                    // Age must be less than 150
                                    "int(this.value) < 150"
                                ],
                                invalidPrompt: new ActivityTemplate("${AskForAge.invalid()}"),
                                unrecognizedPrompt: new ActivityTemplate("${AskForAge.unRecognized()}")
                            }),
                            new SendActivity("${UserAgeReadBack()}")
                        ],
                        elseActions: [
                            new SendActivity("${NoAge()}") 
                        ]
                    }),
github microsoft / BotBuilder-Samples / experimental / adaptive-dialog / javascript_nodejs / 05.multi-turn-prompt / dialogs / userProfileDialog.js View on Github external
super('userProfileDialog');
        let lgFile = Templates.parseFile(path.join(__dirname, "userProfileDialog.lg"));
        let userProfileAdaptiveDialog = new AdaptiveDialog(ROOT_DIALOG).configure({
            generator: new TemplateEngineLanguageGenerator(lgFile),
            triggers: [
                new OnBeginDialog([
                    // Ask for user's age and set it in user.userProfile scope.
                    new TextInput().configure(
                    {
                        // Set the output of the text input to this property in memory.
                        property: new StringExpression("user.userProfile.Transport"),
                        prompt: new ActivityTemplate("${ModeOfTransportPrompt.Text()}")
                    }),
                    new TextInput().configure(
                    {
                        property: new StringExpression("user.userProfile.Name"),
                        prompt: new ActivityTemplate("${AskForName()}")
                    }),
                    // SendActivity supports full language generation resolution.
                    // See here to learn more about language generation
                    // https://aka.ms/language-generation
                    new SendActivity("${AckName()}"),
                    new ConfirmInput().configure(
                    {
                        property: new StringExpression("turn.ageConfirmation"),
                        prompt: new ActivityTemplate("${AgeConfirmPrompt()}")
                    }),
                    new IfCondition().configure(
                    {
                        // All conditions are expressed using the common expression language.
                        // See https://aka.ms/adaptive-expressions to learn more
                        condition: new BoolExpression("turn.ageConfirmation == true"),
github microsoft / BotBuilder-Samples / experimental / adaptive-dialog / javascript_nodejs / 05.multi-turn-prompt / dialogs / userProfileDialog.js View on Github external
// Set the output of the text input to this property in memory.
                        property: new StringExpression("user.userProfile.Transport"),
                        prompt: new ActivityTemplate("${ModeOfTransportPrompt.Text()}")
                    }),
                    new TextInput().configure(
                    {
                        property: new StringExpression("user.userProfile.Name"),
                        prompt: new ActivityTemplate("${AskForName()}")
                    }),
                    // SendActivity supports full language generation resolution.
                    // See here to learn more about language generation
                    // https://aka.ms/language-generation
                    new SendActivity("${AckName()}"),
                    new ConfirmInput().configure(
                    {
                        property: new StringExpression("turn.ageConfirmation"),
                        prompt: new ActivityTemplate("${AgeConfirmPrompt()}")
                    }),
                    new IfCondition().configure(
                    {
                        // All conditions are expressed using the common expression language.
                        // See https://aka.ms/adaptive-expressions to learn more
                        condition: new BoolExpression("turn.ageConfirmation == true"),
                        actions: [
                            new NumberInput().configure(
                            {
                                prompt: new ActivityTemplate("${AskForAge()}"),
                                property: new StringExpression("user.userProfile.Age"),
                                // Add validations
                                validations: [
                                    // Age must be greater than or equal 1
                                    "int(this.value) >= 1",
github microsoft / BotBuilder-Samples / experimental / adaptive-dialog / javascript_nodejs / 05.multi-turn-prompt / dialogs / userProfileDialog.js View on Github external
prompt: new ActivityTemplate("${AskForName()}")
                    }),
                    // SendActivity supports full language generation resolution.
                    // See here to learn more about language generation
                    // https://aka.ms/language-generation
                    new SendActivity("${AckName()}"),
                    new ConfirmInput().configure(
                    {
                        property: new StringExpression("turn.ageConfirmation"),
                        prompt: new ActivityTemplate("${AgeConfirmPrompt()}")
                    }),
                    new IfCondition().configure(
                    {
                        // All conditions are expressed using the common expression language.
                        // See https://aka.ms/adaptive-expressions to learn more
                        condition: new BoolExpression("turn.ageConfirmation == true"),
                        actions: [
                            new NumberInput().configure(
                            {
                                prompt: new ActivityTemplate("${AskForAge()}"),
                                property: new StringExpression("user.userProfile.Age"),
                                // Add validations
                                validations: [
                                    // Age must be greater than or equal 1
                                    "int(this.value) >= 1",
                                    // Age must be less than 150
                                    "int(this.value) < 150"
                                ],
                                invalidPrompt: new ActivityTemplate("${AskForAge.invalid()}"),
                                unrecognizedPrompt: new ActivityTemplate("${AskForAge.unRecognized()}")
                            }),
                            new SendActivity("${UserAgeReadBack()}")
github microsoft / BotBuilder-Samples / experimental / adaptive-dialog / javascript_nodejs / 05.multi-turn-prompt / dialogs / userProfileDialog.js View on Github external
"int(this.value) >= 1",
                                    // Age must be less than 150
                                    "int(this.value) < 150"
                                ],
                                invalidPrompt: new ActivityTemplate("${AskForAge.invalid()}"),
                                unrecognizedPrompt: new ActivityTemplate("${AskForAge.unRecognized()}")
                            }),
                            new SendActivity("${UserAgeReadBack()}")
                        ],
                        elseActions: [
                            new SendActivity("${NoAge()}") 
                        ]
                    }),
                    new IfCondition().configure(
                    {
                        condition: new BoolExpression("turn.activity.channelId == 'msteams'"),
                        actions: [
                            // This attachment prompt example is not designed to work for Teams attachments, so skip it in this case
                            new SendActivity('Skipping attachment prompt in Teams channel...')
                        ],
                        elseActions: [
                            new AttachmentInput().configure(
                            {
                                prompt: new ActivityTemplate("${AskForImage()}"),
                                property: new StringExpression("user.userProfile.picture"),
                                validations: [
                                    "this.value.contentType == 'image/jpeg' || this.value.contentType == 'image/png'"
                                ],
                                invalidPrompt: new ActivityTemplate("${AskForImage.Invalid()}")
                            })
                        ]
                    }),
github microsoft / BotBuilder-Samples / experimental / adaptive-tool / src / lg / buildinFunctions.ts View on Github external
this.params = params;
    this.returntype = returntype;
    this.introduction = introduction;
  }
  public params: string[];
  public returntype: ReturnType;
  public introduction: string;
}

// https://github.com/microsoft/BotBuilder-Samples/blob/master/experimental/common-expression-language/prebuilt-functions.md
export const buildInfunctionsMap: Map = new Map([
  [
    'add',
    new FunctionEntity(
      ['num1: number', 'num2: number'],
      ReturnType.Number,
      'Return the result from adding two numbers.'
    ),
  ],
  [
    'div',
    new FunctionEntity(
      ['dividend: number', 'divisor: number'],
      ReturnType.Number,
      'Return the integer result from dividing two numbers. To get the remainder result, see mod().'
    ),
  ],
  [
    'mod',
    new FunctionEntity(
      ['dividend: number', 'divisor: number'],
      ReturnType.Number,
github microsoft / BotBuilder-Samples / experimental / adaptive-tool / src / lg / buildinFunctions.ts View on Github external
'isBoolean',
  new FunctionEntity(['input: any'], ReturnType.Boolean, 'determine whether a given input is a boolean.'),
],
['isArray', new FunctionEntity(['input: any'], ReturnType.Boolean, 'determine whether a given input is an array.')],
['isObject', new FunctionEntity(['input: any'], ReturnType.Boolean, 'determine whether a given input is an object.')],
[
  'isDateTime',
  new FunctionEntity(
    ['input: any'],
    ReturnType.Boolean,
    'determine whether a given input is a UTC ISO format timestamp.'
  ),
],
['isString', new FunctionEntity(['input: any'], ReturnType.Boolean, 'determine whether a given input is a string.')],
['formatEpoch', new FunctionEntity(['epoch: number', 'format?: string'], ReturnType.String, 'Return a timestamp from UNIX Epoch time (Unix time, POSIX time).')],
['formatTicks', new FunctionEntity(['ticks: number', 'format?: string'], ReturnType.String, 'Return a timestamp from ticks.')],

['isPresent', new FunctionEntity(['timex: TimexProperty|string'], ReturnType.Boolean, 'Return true if the TimexProperty or Timex expression refers to the present.')],
['isDuration', new FunctionEntity(['timex: TimexProperty|string'], ReturnType.Boolean, 'Return true if the TimexProperty or Timex expression refers to a duration.')],
['isTime', new FunctionEntity(['timex: TimexProperty|string'], ReturnType.Boolean, 'Return true if the TimexProperty or Timex expression refers to a time.')],
['isDate', new FunctionEntity(['timex: TimexProperty|string'], ReturnType.Boolean, 'Return true if the TimexProperty or Timex expression refers to a date.')],
['isTimeRange', new FunctionEntity(['timex: TimexProperty|string'], ReturnType.Boolean, 'Return true if the TimexProperty or Timex expression refers to a time range.')],
['isDateRange', new FunctionEntity(['timex: TimexProperty|string'], ReturnType.Boolean, 'Return true if the TimexProperty or Timex expression refers to a date range.')],
['isDefinite', new FunctionEntity(['timex: TimexProperty|string'], ReturnType.Boolean, '	Return true if the TimexProperty or Timex expression refers to a definite day.')],

  // Functions injected from LG library
  // https://github.com/microsoft/BotBuilder-Samples/blob/master/experimental/language-generation/docs/Functions-injected-from-LG.md
  [
    'template',
    new FunctionEntity(
      ['templateName: string', '...params: any[]'],
      ReturnType.Object,