Skip to content

Commit 26deb14

Browse files
committed
Clean up docs
1 parent 9ddea38 commit 26deb14

3 files changed

Lines changed: 64 additions & 3 deletions

File tree

docs/MIDDLEWARE.md

Lines changed: 64 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
11
# Middleware
22

3-
## Cooking recipes
3+
## Recipes
44

5-
### Showing channel message as a badge
5+
### Show channel message as a badge
66

7-
When the following activity is received, the middleware will display it in a badge.
7+
This sample demonstrates the following:
8+
9+
- Add a new activity middleware component for a specific type of activity
810

911
#### Activity payload
1012

@@ -59,3 +61,62 @@ const polyMiddleware = [
5961
})
6062
];
6163
```
64+
65+
### Decorate activity with a border
66+
67+
This sample demonstrates the following:
68+
69+
- Decorate an activity
70+
- Use [hooks](./HOOKS.md#usestyleoptions) within the activity middleware component
71+
72+
#### Screenshot
73+
74+
![Web Chat showing message with a blue outline](./media/middleware/decorate-message.png)
75+
76+
#### Code snippet
77+
78+
```tsx
79+
import ReactWebChat, { createStoreWithOptions, hooks } from 'botframework-webchat';
80+
import {
81+
activityComponent,
82+
createActivityPolyMiddleware,
83+
type ActivityPolyMiddlewareProps,
84+
type ActivityPolyMiddlewareRenderer
85+
} from 'botframework-webchat/middleware';
86+
import React, { Fragment, memo, useMemo } from 'react';
87+
import { render } from 'react-dom';
88+
89+
const { useStyleOptions } = hooks;
90+
91+
type MessageBorderProps = ActivityPolyMiddlewareProps & {
92+
readonly render: ActivityPolyMiddlewareRenderer | undefined;
93+
};
94+
95+
const MessageBorder = memo<MessageBorderProps>(function MessageBorder({ render }) {
96+
const [{ accent }] = useStyleOptions();
97+
98+
const style = useMemo(() => ({ outlineColor: accent }), [accent]);
99+
100+
return (
101+
<div className="message-border" style={style}>
102+
<Fragment>{render?.({})}</Fragment>
103+
</div>
104+
);
105+
});
106+
107+
const polyMiddleware = [
108+
createActivityPolyMiddleware(next => request => {
109+
const { activity } = request;
110+
111+
if (activity.type === 'message') {
112+
const render = next(request)?.render;
113+
114+
return activityComponent<MessageBorderProps>(MessageBorder, {
115+
render
116+
});
117+
}
118+
119+
return next(request);
120+
})
121+
];
122+
```
12.8 KB
Loading
25.9 KB
Loading

0 commit comments

Comments
 (0)