How to use the @microsoft/recognizers-text-data-types-timex-expression.TimexProperty function in @microsoft/recognizers-text-data-types-timex-expression

To help you get started, we’ve selected a few @microsoft/recognizers-text-data-types-timex-expression 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 / 13.core-bot / dialogs / dateResolverDialog.js View on Github external
async dateTimePromptValidator(promptContext) {
        if (promptContext.recognized.succeeded) {
            // This value will be a TIMEX. And we are only interested in a Date so grab the first result and drop the Time part.
            // TIMEX is a format that represents DateTime expressions that include some ambiguity. e.g. missing a Year.
            const timex = promptContext.recognized.value[0].timex.split('T')[0];

            // If this is a definite Date including year, month and day we are good otherwise reprompt.
            // A better solution might be to let the user know what part is actually missing.
            return new TimexProperty(timex).types.has('definite');
        }
        return false;
    }
}
github microsoft / BotBuilder-Samples / samples / typescript_nodejs / 13.core-bot / src / dialogs / dateResolverDialog.ts View on Github external
const promptMessageText = 'On what date would you like to travel?';
        const promptMessage = MessageFactory.text(promptMessageText, promptMessageText, InputHints.ExpectingInput);

        const repromptMessageText = 'I\'m sorry, for best results, please enter your travel date including the month, day and year.';
        const repromptMessage = MessageFactory.text(repromptMessageText, repromptMessageText, InputHints.ExpectingInput);

        if (!timex) {
            // We were not given any date at all so prompt the user.
            return await stepContext.prompt(DATETIME_PROMPT,
                {
                    prompt: promptMessage,
                    retryPrompt: repromptMessage
                });
        }
        // We have a Date we just need to check it is unambiguous.
        const timexProperty = new TimexProperty(timex);
        if (!timexProperty.types.has('definite')) {
            // This is essentially a "reprompt" of the data we were given up front.
            return await stepContext.prompt(DATETIME_PROMPT, { prompt: repromptMessage });
        }
        return await stepContext.next([{ timex }]);
    }
github microsoft / BotBuilder-Samples / samples / javascript_nodejs / 51.cafe-bot / dialogs / shared / stateProperties / reservationProperty.js View on Github external
returnResult.newReservation.time = ((parseInt(parsedTimex.hour) < 10) ? '0' + parsedTimex.hour : parsedTimex.hour);
                returnResult.newReservation.time += ':';
                returnResult.newReservation.time += ((parseInt(parsedTimex.minute) < 10) ? '0' + parsedTimex.minute : parsedTimex.minute);
                returnResult.newReservation.time += ':';
                returnResult.newReservation.time += ((parseInt(parsedTimex.second) < 10) ? '0' + parsedTimex.second : parsedTimex.second);

                if (!validtime || (validtime.length === 0)) {
                    // Validation failed!
                    returnResult.outcome.push(new ReservationOutcome(`Sorry, that time does not work. I can only make reservations that are in the daytime (6AM - 6PM)`, DATE_TIME_ENTITY));
                    returnResult.newReservation.time = '';
                    returnResult.status = reservationStatus.INCOMPLETE;
                }
            }
            // Get date time LG string if we have both date and time
            if (returnResult.newReservation.date !== '' && returnResult.newReservation.time !== '') {
                returnResult.newReservation.dateTimeLGString = new TimexProperty(returnResult.newReservation.date + 'T' + returnResult.newReservation.time).toNaturalLanguage(today);
            }
        }
    }
    // Take the first found value.
    if (locationEntity !== undefined) {
        let cafeLocation = locationEntity.entityValue[0][0];

        // Capitalize cafe location.
        returnResult.newReservation.location = cafeLocation.charAt(0).toUpperCase() + cafeLocation.substr(1);
    }

    // Accept confirmation entity if available only if we have a complete reservation
    if (confirmationEntity !== undefined) {
        if (confirmationEntity.entityValue[0][0] === 'yes') {
            returnResult.newReservation.reservationConfirmed = true;
            returnResult.newReservation.needsChange = undefined;
github microsoft / BotBuilder-Samples / samples / javascript_typescript / 13.core-bot / src / dialogs / dateResolverDialog.ts View on Github external
private async initialStep(stepContext: WaterfallStepContext): Promise {
        const timex = (stepContext.options as any).date;

        const promptMsg = 'On what date would you like to travel?';
        const repromptMsg = 'I\'m sorry, for best results, please enter your travel date including the month, day and year.';

        if (!timex) {
            // We were not given any date at all so prompt the user.
            return await stepContext.prompt(DATETIME_PROMPT,
                {
                    prompt: promptMsg,
                    retryPrompt: repromptMsg,
                });
        } else {
            // We have a Date we just need to check it is unambiguous.
            const timexProperty = new TimexProperty(timex);
            if (!timexProperty.types.has('definite')) {
                // This is essentially a "reprompt" of the data we were given up front.
                return await stepContext.prompt(DATETIME_PROMPT, { prompt: repromptMsg });
            } else {
                return await stepContext.next({ timex });
            }
        }
    }
github microsoft / BotBuilder-Samples / samples / javascript_nodejs / 13.core-bot / dialogs / mainDialog.js View on Github external
async finalStep(stepContext) {
        // If the child dialog ("bookingDialog") was cancelled or the user failed to confirm, the Result here will be null.
        if (stepContext.result) {
            const result = stepContext.result;
            // Now we have all the booking details.

            // This is where calls to the booking AOU service or database would go.

            // If the call to the booking service was successful tell the user.
            const timeProperty = new TimexProperty(result.travelDate);
            const travelDateMsg = timeProperty.toNaturalLanguage(new Date(Date.now()));
            const msg = `I have you booked to ${ result.destination } from ${ result.origin } on ${ travelDateMsg }.`;
            await stepContext.context.sendActivity(msg);
        } else {
            await stepContext.context.sendActivity('Thank you.');
        }
        return await stepContext.endDialog();
    }
}
github microsoft / BotBuilder-Samples / samples / javascript_nodejs / 40.timex-resolution / parsing.js View on Github external
module.exports.examples = () => {
    describe(new TimexProperty('2017-05-29'));
    describe(new TimexProperty('XXXX-WXX-6'));
    describe(new TimexProperty('XXXX-WXX-6T16'));
    describe(new TimexProperty('T12'));
};
github microsoft / BotBuilder-Samples / samples / javascript_nodejs / 21.corebot-app-insights / dialogs / bookingDialog.js View on Github external
isAmbiguous(timex) {
        const timexPropery = new TimexProperty(timex);
        return !timexPropery.types.has('definite');
    }
}
github microsoft / BotBuilder-Samples / samples / javascript_nodejs / language-generation / 13.core-bot / dialogs / bookingDialog.js View on Github external
isAmbiguous(timex) {
        const timexPropery = new TimexProperty(timex);
        return !timexPropery.types.has('definite');
    }
}
github microsoft / BotBuilder-Samples / samples / javascript_typescript / 13.core-bot / src / dialogs / bookingDialog.ts View on Github external
private isAmbiguous(timex: string): boolean {
        const timexPropery = new TimexProperty(timex);
        return !timexPropery.types.has('definite');
    }
}