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

WebChat 4.15.1 has backward compatibility issues with groupActivityMiddleware #4312

Closed
elopezanaya opened this issue Jun 8, 2022 · 5 comments · Fixed by #4378
Closed

WebChat 4.15.1 has backward compatibility issues with groupActivityMiddleware #4312

elopezanaya opened this issue Jun 8, 2022 · 5 comments · Fixed by #4378
Labels
bug Indicates an unexpected problem or an unintended behavior. external-omnichannel

Comments

@elopezanaya
Copy link

Please view our Technical Support Guide before filing a new issue.

Screenshots

Version

4.15.1

To determine what version of Web Chat you are running, open your browser's development tools, and paste the following line of code into the console.

[].map.call(document.head.querySelectorAll('meta[name^="botframework-"]'), function (meta) { return meta.outerHTML; }).join('\n')

If you are using Web Chat outside of a browser, please specify your hosting environment. For example, React Native on iOS, Cordova on Android, SharePoint, PowerApps, etc.

Describe the bug

when using 4.15.1 in LCW we have detected multiple issues with groupActivityMiddleware , the issue is not present for previous versions

Steps to reproduce

  1. Go to '...'
  2. Click on '....'
  3. Scroll down to '....'
  4. See error

Expected behavior

Additional context

[Bug]

@elopezanaya elopezanaya added Bot Services Required for internal Azure reporting. Do not delete. Do not change color. bug Indicates an unexpected problem or an unintended behavior. customer-reported Required for internal Azure reporting. Do not delete. labels Jun 8, 2022
@compulim
Copy link
Contributor

compulim commented Jun 10, 2022

Please fill out the issue form and elaborate more, preferably with code snippets showing before and after.

@compulim compulim added external-omnichannel and removed customer-reported Required for internal Azure reporting. Do not delete. Bot Services Required for internal Azure reporting. Do not delete. Do not change color. labels Jun 10, 2022
@charliewang95
Copy link

charliewang95 commented Jun 15, 2022

Seeing below error with 4.15.1 and groupActivitiesMiddleware image

@charliewang95
Copy link

charliewang95 commented Jun 15, 2022

Our implementation:

/******
 * GroupActivitiesMiddleware
 * 
 * This middleware controls which messages are grouped together regarding to timestamps. It does the following processing:
 * 1. Distinguishes different messages by sender name and whether it is a system message
 ******/

import { Constants } from "../../../../../common/Constants";

function bin<T>(items: T[], grouping: (last: T, current: T) => boolean): T[][] {
    let lastBin: T[];
    const bins: T[][] = [];
    let lastItem: T;
    if (items.length > 0) {
        items.forEach(item => {
            if (lastItem && grouping(lastItem, item)) {
                lastBin.push(item);
            } else {
                lastBin = [item];
                bins.push(lastBin);
            }
            lastItem = item;
        });
    }
    return bins;
}

// eslint-disable-next-line @typescript-eslint/no-unused-vars, @typescript-eslint/no-explicit-any
export const groupActivitiesMiddleware = () => (next: any) => (args: any) => {
    const {
        activities
    } = args;

    if (activities != null && activities.length > 0) {
        const { status } = next({ activities });
        return {
            // eslint-disable-next-line @typescript-eslint/no-explicit-any
            sender: bin(activities, (x: any, y: any) => {
                const roleX = (x.channelData && x.channelData.tags) ? x.channelData.tags.includes(Constants.systemMessageTag) ? Constants.systemMessageTag : x.from.name : x.from.name;
                const roleY = (y.channelData && y.channelData.tags) ? y.channelData.tags.includes(Constants.systemMessageTag) ? Constants.systemMessageTag : y.from.name : y.from.name;
                return roleX === roleY;
            }),
            status
        };
    }
    else {
        return () => false;
    }
};

@compulim
Copy link
Contributor

compulim commented Aug 3, 2022

Working on this now. Confirmed it does not repro on 4.14.0 and repro on 4.15.0 (and probably more recent versions).

image

@compulim
Copy link
Contributor

compulim commented Aug 4, 2022

The error is caused by an invalid result was returned by the groupActivityMiddleware.

In the code snippet by @charliewang95, it may return () => false, which does not conform to the return type of { sender: [][], status: [][] }.

In 4.14.0, Web Chat tolerated the invalid return value. However, in 4.15, Web Chat did not tolerate and threw exceptions.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Indicates an unexpected problem or an unintended behavior. external-omnichannel
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants