Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Prevent Cortana from trying to use suggested actions in prompts #732

Merged
merged 4 commits into from
Jan 30, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 1 addition & 3 deletions libraries/botbuilder-dialogs/src/choices/choiceFactory.ts
Original file line number Diff line number Diff line change
Expand Up @@ -107,11 +107,9 @@ export class ChoiceFactory {

// Determine list style
const supportsSuggestedActions: boolean = channel.supportsSuggestedActions(channelId, choices.length);
const supportsCardActions: boolean = channel.supportsCardActions(channelId, choices.length);
const maxActionTitleLength: number = channel.maxActionTitleLength(channelId);
const hasMessageFeed: boolean = channel.hasMessageFeed(channelId);
const longTitles: boolean = maxTitleLength > maxActionTitleLength;
if (!longTitles && (supportsSuggestedActions || (!hasMessageFeed && supportsCardActions))) {
if (!longTitles && supportsSuggestedActions) {
// We always prefer showing choices using suggested actions. If the titles are too long, however,
// we'll have to show them as a text list.
return ChoiceFactory.suggestedAction(list, text, speak);
Expand Down
13 changes: 13 additions & 0 deletions libraries/botbuilder-dialogs/tests/choices_choiceFactory.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ function assertActivity(received, expected) {
}

const colorChoices = ['red', 'green', 'blue'];
const extraChoices = ['red', 'green', 'blue', 'alpha'];

const choicesWithActionTitle = [
{
Expand Down Expand Up @@ -167,6 +168,18 @@ describe('ChoiceFactory', function() {
done();
});

it('should choose correct styles for Cortana.', done => {
const inlineActivity = ChoiceFactory.forChannel('cortana', colorChoices, 'select from:');
assertActivity(inlineActivity, {
text: `select from: (1) red, (2) green, or (3) blue`
});
const listActivity = ChoiceFactory.forChannel('cortana', extraChoices, 'select from:');
assertActivity(listActivity, {
text: `select from:\n\n 1. red\n 2. green\n 3. blue\n 4. alpha`
});
done();
});

it('should use action.title to populate action.value if action.value is falsey.', done => {
const preparedChoices = ChoiceFactory.toChoices(choicesWithActionTitle);
assertChoices(preparedChoices, ['Red Color', 'Green Color', 'Blue Color']);
Expand Down