How to use the adaptive-expressions.Expression.functions function in adaptive-expressions

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 / samples / javascript_nodejs / language-generation / 20.custom-functions / bot.js View on Github external
constructor() {
        super();

        const lgFilePath = path.join(__dirname, './resources/main.lg');

        // add the custom function
        Expression.functions.add(mySqrtFnName, (args) => {
            let retValue = null;
            if (args[0] !== null) {
                try {
                    const dblValue = parseFloat(args[0]);
                    retValue = Math.sqrt(dblValue);
                } catch (ex) {
                    return retValue;
                }
            }
            return retValue;
        });

        // by default this uses Expression.functions.
        this.lgTemplates = Templates.parseFile(lgFilePath);

        // See https://aka.ms/about-bot-activity-message to learn more about the message and other activity types.