botbuilder-js: ChoiceInput\ConfirmInput shows TypeError: Cannot read property 'getValue' of undefined in Telegram channel

Versions

bot framework v 4.9.2. nodejs 12.18.0 botbuilder-dialogs-adaptive@4.9.2-preview OS - Windows Channel Telegram

Describe the bug

I have tried to build an adaptive dialog based on the sample here : https://github.com/microsoft/BotBuilder-Samples/tree/master/experimental/adaptive-dialog/javascript_nodejs/06.todo-bot

ConfirmInput code:

new ConfirmInput().configure({
    property: new StringExpression('turn.addTodo.cancelConfirmation'),
    prompt: new ActivityTemplate('${ConfirmCancellation()}'),
    // Allow interruptions is an expression. So you can write any expression to determine if an interruption should be allowed.
    // In this case, we will disallow interruptions since this is a cancellation confirmation.
    allowInterruptions: new BoolExpression(false),
    // Controls the number of times user is prompted for this input.
    maxTurnCount: new NumberExpression(1),
    // Default value to use if we have hit the MaxTurnCount
    defaultValue: new BoolExpression('=false'),
    // You can refer to properties of this input via %propertyName notation.
    // The default response is sent if we have prompted the user for MaxTurnCount number of times
    // and if a default value is assumed for the property.
    defaultValueResponse: new ActivityTemplate("Sorry, I do not recognize '${this.value}'. I'm going with '${%DefaultValue}' for now to be safe.")
}),

ChoiceInput code:

new ChoiceInput().configure({
    id: 'questionID',
    property: new StringExpression('turn.userAnswer'),
    prompt: new ActivityTemplate('${Question()}'),
    style: new EnumExpression(ListStyle.auto),
    choices: new ArrayExpression(this.getChoices(this.taskProperties.choices)),
    alwaysPrompt: new BoolExpression(true),
    unrecognizedPrompt: new ActivityTemplate('${errUseButtons()}'),
    maxTurnCount: new IntExpression(1),
    allowInterruptions: new BoolExpression(true),
    outputFormat: new EnumExpression(ChoiceOutputFormat.index)
}),

Everything is working on a WebChat and Emulator, but when I try to use Telegram channel, I get the following error : [onTurnError] unhandled error: TypeError: Cannot read property ‘getValue’ of undefined

Expected behavior

If I am correct Choices are supported in Telegram channel , so I expect see prompt with choices in Telegram.

[bug]

About this issue

  • Original URL
  • State: closed
  • Created 4 years ago
  • Comments: 15 (11 by maintainers)

Most upvoted comments

I have investigated the issue and found possible problem in choiceInput.ts file.

protected async onRenderPrompt(dc: DialogContext, state: InputState): Promise<Partial<Activity>> {
        // Determine locale
        let locale: string = dc.context.activity.locale || this.**defaultLocale**.getValue(dc.state);
        if (!locale || !ChoiceInput.defaultChoiceOptions.hasOwnProperty(locale)) {
            locale = 'en-us';
        }

the problem appears when defaultLocale is not set in ChoiceInput configuration AND in Telegram channel the context.activity.locale is not set. So onRenderPrompt() it throws an error.

In WebChat channel the context.activity.locale has a value = en-us , that’s why there is no error there.

So, I guess, defaultLocale should be a mandatory and I think the code also should be fixed, because there is no sense to check for (!locale) on the next line if it throws an error before that.