1+ /* eslint-disable prefer-arrow-callback */
2+
3+ // Use code-splitting to speed up development time, just dummy import is sufficient.
4+ // esbuild will split out botframework-webchat* packages into their own chunks.
5+ await import ( 'botframework-webchat' ) ;
6+ await import ( 'botframework-webchat/middleware' ) ;
7+
8+ // #region Sample code
19import ReactWebChat , { createStoreWithOptions } from 'botframework-webchat' ;
210import { type WebChatActivity } from 'botframework-webchat-core' ;
311import {
412 activityComponent ,
513 createActivityPolyMiddleware ,
6- type ActivityPolyMiddlewareProps ,
7- type ActivityPolyMiddlewareRenderer
14+ type ActivityPolyMiddlewareProps
815} from 'botframework-webchat/middleware' ;
9- import React from 'react' ;
16+ import React , { memo } from 'react' ;
1017import { render } from 'react-dom' ;
11-
12- declare global {
13- const host : any ;
14- const pageConditions : any ;
15- const pageElements : any ;
16- const run : ( fn : ( ) => Promise < void > ) => Promise < void > ;
17- const testHelpers : any ;
18- }
19-
20- // Use code-splitting to speed up development time, just dummy import is sufficient.
21- // esbuild will split out botframework-webchat* packages into their own chunks.
22- await import ( 'botframework-webchat' ) ;
23- await import ( 'botframework-webchat/middleware' ) ;
18+ // #endregion Sample code
2419
2520run ( async ( ) => {
2621 // #region Sample code
2722
28- type MyActivityProps = ActivityPolyMiddlewareProps & {
29- readonly activity : WebChatActivity & { type : 'message' } ;
30- readonly render : ActivityPolyMiddlewareRenderer | undefined ;
23+ type ChannelMessageProps = ActivityPolyMiddlewareProps & {
24+ readonly activity : WebChatActivity & {
25+ type : 'message' ;
26+ } ;
3127 } ;
3228
33- function ChannelMessage ( { activity } : MyActivityProps ) {
29+ const ChannelMessage = memo < ChannelMessageProps > ( function ChannelMessage ( { activity } ) {
3430 return (
3531 < div className = "channel-message" >
3632 < div className = "channel-message__body" > { activity . text } </ div >
3733 </ div >
3834 ) ;
39- }
35+ } ) ;
4036
4137 const polyMiddleware = [
4238 createActivityPolyMiddleware ( next => request => {
4339 const { activity } = request ;
4440
4541 if ( activity . from . role === 'channel' && activity . type === 'message' ) {
46- const render = next ( request ) ?. render ;
47-
48- return activityComponent < MyActivityProps > ( ChannelMessage , {
49- activity,
50- render
51- } ) ;
42+ return activityComponent ( ChannelMessage , { activity } ) ;
5243 }
5344
5445 return next ( request ) ;
@@ -68,13 +59,13 @@ run(async () => {
6859
6960 await pageConditions . uiConnected ( ) ;
7061
71- directLine . emulateIncomingActivity ( {
62+ await directLine . emulateIncomingActivity ( {
7263 from : { id : 'channel' , role : 'channel' } ,
7364 text : 'An agent has joined the conversation' ,
7465 type : 'message'
7566 } ) ;
7667
77- directLine . emulateIncomingActivity ( {
68+ await directLine . emulateIncomingActivity ( {
7869 from : { id : 'bot' , role : 'bot' } ,
7970 text : 'Hello, World!' ,
8071 type : 'message'
0 commit comments