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 Direct Line Speech null attachments and update test snapshots #3154

Merged
merged 4 commits into from
May 12, 2020
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
14 changes: 13 additions & 1 deletion packages/core/src/sagas/incomingActivitySaga.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,19 @@ function patchActivityWithFromRole(activity, userID) {
return activity;
}

function patchActivityWithNullAttachments(activity) {
return updateIn(activity, ['attachments'], attachments => attachments || []);
}

function patchActivityWithNullSuggestedActions(activity) {
return updateIn(activity, ['suggestedActions'], suggestedActions => suggestedActions || []);
}

function* observeActivity({ directLine, userID }) {
yield observeEach(directLine.activity$, function* observeActivity(activity) {
activity = patchActivityWithFromRole(activity, userID);
activity = patchActivityWithNullAttachments(activity);
activity = patchActivityWithNullSuggestedActions(activity);

yield put(incomingActivity(activity));

Expand All @@ -41,7 +51,9 @@ function* observeActivity({ directLine, userID }) {
const lastMessageActivity = messageActivities[messageActivities.length - 1];

if (activityFromBot(lastMessageActivity)) {
const { suggestedActions: { actions, to } = {} } = lastMessageActivity;
const { suggestedActions } = lastMessageActivity;
// Direct Line Speech will return "suggestedActions" as "null" instead of "undefined".
const { actions, to } = suggestedActions || {};

// If suggested actions is not destined to anyone, or is destined to the user, show it.
// In other words, if suggested actions is destined to someone else, don't show it.
Expand Down
6 changes: 3 additions & 3 deletions packages/directlinespeech/__tests__/sendSpeechActivity.js
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,8 @@ test('should echo back "Bellevue" when saying "bellview"', async () => {
`);
});

test('should not synthesis when "speak" is empty', async () => {
// 2020-05-11: Direct Line Speech protocol was updated to synthesize "text" if "speak" property is not set.
test('should synthesis if "speak" is empty', async () => {
const { directLine, sendTextAsSpeech } = await createTestHarness();

const connectedPromise = waitForConnected(directLine);
Expand All @@ -74,6 +75,5 @@ test('should not synthesis when "speak" is empty', async () => {
const activities = await activitiesPromise;
const activityUtterances = await Promise.all(activities.map(activity => recognizeActivityAsText(activity)));

expect(activityUtterances).toHaveProperty('length', 1);
expect(activityUtterances[0]).toBeFalsy();
expect(activityUtterances).toEqual([`Don't speak anything.`]);
});