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

fix: [#4007] Bot framework V4. Unable to use ⭐ emoji in suggested actions #4031

Merged
merged 3 commits into from
Jan 3, 2022
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
22 changes: 22 additions & 0 deletions libraries/botbuilder-dialogs/src/choices/findValues.ts
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,28 @@ export function findValues(
return -1;
}

function findExactMatch(utterance: string, values: SortedValue[]): ModelResult<FoundValue> {
const entry = values.find(({ value }) => value.toLowerCase() === utterance.toLowerCase());
if (!entry) {
return null;
}
return {
text: utterance,
start: 0,
end: utterance.length - 1,
typeName: 'value',
resolution: {
value: entry.value,
index: entry.index,
score: 1,
},
};
}
const exactMatch = findExactMatch(utterance, values);
if (exactMatch) {
return [exactMatch];
}

function matchValue(
index: number,
value: string,
Expand Down
14 changes: 14 additions & 0 deletions libraries/botbuilder-dialogs/tests/choices_recognizers.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,12 @@ const similarValues = [
{ value: 'option C', index: 2 },
];

const valuesWithSpecialCharacters = [
{ value: 'A < B', index: 0 },
{ value: 'A >= B', index: 1 },
{ value: 'A ??? B', index: 2 },
];

describe('findValues()', function () {
this.timeout(5000);

Expand Down Expand Up @@ -91,6 +97,14 @@ describe('findValues()', function () {
assert(found.length === 1, `Invalid token count of '${found.length}' returned.`);
assertValue(found[0], 'option B', 1, 1.0);
});

it('should prefer exact match.', function () {
const index = 1;
const utterance = valuesWithSpecialCharacters[index].value;
const found = findValues(utterance, valuesWithSpecialCharacters);
assert(found.length === 1, `Invalid token count of '${found.length}' returned.`);
assertValue(found[0], utterance, index, 1);
});
});

//=============================================================================
Expand Down