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

Feature/middleware v2 init #5118

Draft
wants to merge 11 commits into
base: main
Choose a base branch
from
Prev Previous commit
Next Next commit
Polish and minor fixes
OEvgeny committed Jan 8, 2025
commit 2740a197a8fcb9dc1a36043877d6ad21817cae75
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.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<!DOCTYPE html>
<!doctype html>
<html lang="en-US">

<head>
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<!DOCTYPE html>
<!doctype html>
<html lang="en-US">

<head>
@@ -23,7 +23,7 @@
const {
ReactDOM: { render },
WebChat: {
Components: { BasicWebChat, Composer },
Components: { BasicWebChat, Composer }, v2Middleware
}
} = window;

Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<!DOCTYPE html>
<!doctype html>
<html lang="en-US">

<head>
@@ -23,7 +23,7 @@
const {
ReactDOM: { render },
WebChat: {
Components: { BasicWebChat, Composer },
Components: { BasicWebChat, Composer }, v2Middleware
}
} = window;

Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<!DOCTYPE html>
<!doctype html>
<html lang="en-US">

<head>
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<!DOCTYPE html>
<!doctype html>
<html lang="en-US">

<head>
@@ -23,7 +23,7 @@
const {
ReactDOM: { render },
WebChat: {
Components: { BasicWebChat, Composer },
Components: { BasicWebChat, Composer }, v2Middleware
}
} = window;

Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<!DOCTYPE html>
<!doctype html>
<html lang="en-US">

<head>
@@ -23,7 +23,7 @@
const {
ReactDOM: { render },
WebChat: {
Components: { BasicWebChat, Composer },
Components: { BasicWebChat, Composer }, v2Middleware
}
} = window;

2 changes: 1 addition & 1 deletion __tests__/html/middleware/v1/activity.add.decorate.html
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<!DOCTYPE html>
<!doctype html>
<html lang="en-US">

<head>
2 changes: 1 addition & 1 deletion __tests__/html/middleware/v1/activity.add.html
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<!DOCTYPE html>
<!doctype html>
<html lang="en-US">

<head>
7 changes: 4 additions & 3 deletions __tests__/html/middleware/v1/activity.decorate.html
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<!DOCTYPE html>
<!doctype html>
<html lang="en-US">

<head>
@@ -46,6 +46,7 @@
if (activity.text.includes('decorated')) {
const renderActivity = next(...args);
if (!renderActivity) return renderActivity;
if (activity.text.includes('dropped')) return false;
return (...args) => (
<CustomActivity activity={activity}>
{renderActivity.call ? renderActivity(...args) : renderActivity}
@@ -72,9 +73,9 @@
role: 'bot'
},
id: '1',
text: 'This is the decorated custom message.',
text: 'This is the dropped decorated message.',
timestamp: new Date(NOW).toISOString(),
type: 'custom-message'
type: 'message'
},
{
from: {
2 changes: 1 addition & 1 deletion __tests__/html/middleware/v1/activity.remove.html
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<!DOCTYPE html>
<!doctype html>
<html lang="en-US">

<head>
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<!DOCTYPE html>
<!doctype html>
<html lang="en-US">

<head>
4 changes: 2 additions & 2 deletions __tests__/html/middleware/v1/activity.replace.html
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<!DOCTYPE html>
<!doctype html>
<html lang="en-US">

<head>
@@ -23,7 +23,7 @@
const {
ReactDOM: { render },
WebChat: {
Components: { BasicWebChat, Composer },
Components: { BasicWebChat, Composer }, v2Middleware
}
} = window;

Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<!DOCTYPE html>
<!doctype html>
<html lang="en-US">

<head>
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<!DOCTYPE html>
<!doctype html>
<html lang="en-US">
<head>
<link href="/assets/index.css" rel="stylesheet" type="text/css" />
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<!DOCTYPE html>
<!doctype html>
<html lang="en-US">
<head>
<link href="/assets/index.css" rel="stylesheet" type="text/css" />
2 changes: 1 addition & 1 deletion __tests__/html/middleware/v2/activity.add.decorate.html
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<!DOCTYPE html>
<!doctype html>
<html lang="en-US">

<head>
2 changes: 1 addition & 1 deletion __tests__/html/middleware/v2/activity.add.html
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<!DOCTYPE html>
<!doctype html>
<html lang="en-US">

<head>
7 changes: 4 additions & 3 deletions __tests__/html/middleware/v2/activity.decorate.html
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<!DOCTYPE html>
<!doctype html>
<html lang="en-US">

<head>
@@ -46,6 +46,7 @@
if (activity.text.includes('decorated')) {
const Next = next(props);
if (!Next) return Next;
if (activity.text.includes('dropped')) return false;
return (props) => (
<CustomActivity>
<Next {...props} />
@@ -72,9 +73,9 @@
role: 'bot'
},
id: '1',
text: 'This is the dropped decorated custom message.',
text: 'This is the dropped decorated message.',
timestamp: new Date(NOW).toISOString(),
type: 'custom-message'
type: 'message'
},
{
from: {
2 changes: 1 addition & 1 deletion __tests__/html/middleware/v2/activity.remove.html
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<!DOCTYPE html>
<!doctype html>
<html lang="en-US">

<head>
4 changes: 2 additions & 2 deletions __tests__/html/middleware/v2/activity.remove.replace.html
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<!DOCTYPE html>
<!doctype html>
<html lang="en-US">

<head>
@@ -23,7 +23,7 @@
const {
ReactDOM: { render },
WebChat: {
Components: { BasicWebChat, Composer },
Components: { BasicWebChat, Composer }, v2Middleware
}
} = window;

2 changes: 1 addition & 1 deletion __tests__/html/middleware/v2/activity.replace.html
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<!DOCTYPE html>
<!doctype html>
<html lang="en-US">

<head>
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<!DOCTYPE html>
<!doctype html>
<html lang="en-US">

<head>
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<!DOCTYPE html>
<!doctype html>
<html lang="en-US">
<head>
<link href="/assets/index.css" rel="stylesheet" type="text/css" />
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<!DOCTYPE html>
<!doctype html>
<html lang="en-US">
<head>
<link href="/assets/index.css" rel="stylesheet" type="text/css" />
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<!DOCTYPE html>
<!doctype html>
<html lang="en-US">
<head>
<link href="/assets/index.css" rel="stylesheet" type="text/css" />
30 changes: 16 additions & 14 deletions packages/api/src/hooks/Composer.tsx
Original file line number Diff line number Diff line change
@@ -415,22 +415,24 @@ const ComposerCore = ({
[activityMiddleware]
);

const patchedActivityRenderer = useMemo(() => {
return applyMiddlewareForRenderer(
'activity',
{ strict: false },
...singleToArray(activityMiddleware),
const patchedActivityRenderer = useMemo(
() =>
applyMiddlewareForRenderer(
'activity',
{ strict: false },
...singleToArray(activityMiddleware),
() =>
() =>
() =>
({ activity }) => {
if (activity) {
throw new Error(`No renderer for activity of type "${activity.type}"`);
} else {
throw new Error('No activity to render');
}
({ activity }) => {
if (activity) {
throw new Error(`No renderer for activity of type "${activity.type}"`);
} else {
throw new Error('No activity to render');
}
)({});
}, [activityMiddleware, isUsingActivityMiddlewareV2]);
}
)({}),
[activityMiddleware]
);

const patchedActivityStatusRenderer = useMemo<RenderActivityStatus>(
() =>
1 change: 0 additions & 1 deletion packages/api/src/index.ts
Original file line number Diff line number Diff line change
@@ -43,7 +43,6 @@ import TypingIndicatorMiddleware, { type RenderTypingIndicator } from './types/T
import { type WebSpeechPonyfill } from './types/WebSpeechPonyfill';
import { type WebSpeechPonyfillFactory } from './types/WebSpeechPonyfillFactory';


import { v2Middleware } from './utils/v2Middleware';
const buildTool = process.env.build_tool;
const moduleFormat = process.env.module_format;
Original file line number Diff line number Diff line change
@@ -44,7 +44,7 @@ function useCreateActivityRendererV2(): ActivityComponentFactory {
return false;
}

return props => <Component {...createActivityRendererOptions} {...props}/>;
return props => <Component {...createActivityRendererOptions} {...props} />;
},
[enhancer]
);
1 change: 1 addition & 0 deletions packages/bundle/src/module/exports.ts
Original file line number Diff line number Diff line change
@@ -46,6 +46,7 @@ export {
decorator,
internal,
testIds,
v2Middleware,
version
} from './exports-minimal';