-
Notifications
You must be signed in to change notification settings - Fork 1.6k
Expand file tree
/
Copy pathsupportPolymiddleware.renderWebChat.skip.html
More file actions
80 lines (69 loc) · 2.66 KB
/
supportPolymiddleware.renderWebChat.skip.html
File metadata and controls
80 lines (69 loc) · 2.66 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
<!doctype html>
<html lang="en-US">
<head>
<link href="/assets/index.css" rel="stylesheet" type="text/css" />
<script crossorigin="anonymous" src="/test-harness.js"></script>
<script crossorigin="anonymous" src="/test-page-object.js"></script>
</head>
<body>
<main id="webchat"></main>
<script type="importmap">
{
"imports": {
"botframework-webchat": "/__dist__/packages/bundle/dist/botframework-webchat.mjs",
"botframework-webchat/middleware": "/__dist__/packages/bundle/dist/botframework-webchat/middleware.mjs",
"react": "https://esm.sh/react@18",
"react-dom": "https://esm.sh/react-dom@18"
}
}
</script>
<script type="module">
import React from 'react';
import ReactDOM from 'react-dom';
// We should allow using React from environment.
// When web devs import Web Chat as <script type="module">, we want to enable customization.
// Customization requires React.createElement() and calling some hooks.
window.React = React;
window.ReactDOM = ReactDOM;
</script>
<script type="module">
import { createDirectLine, createStoreWithOptions, hooks, renderWebChat } from 'botframework-webchat';
import { activityComponent, createActivityPolymiddleware } from 'botframework-webchat/middleware';
import { createElement } from 'react';
const { useStyleOptions } = hooks;
const {
testHelpers: { createDirectLineEmulator }
} = window;
// TODO: This is for `createDirectLineEmulator` only, should find ways to eliminate this line.
window.WebChat = { createStoreWithOptions };
run(async function () {
const { directLine, store } = createDirectLineEmulator();
function MyMiddleware({ nextResult }) {
// THEN: Web Chat hooks can be called.
const [{ accent }] = useStyleOptions();
return createElement(
'div',
{ style: { borderColor: accent, borderStyle: 'solid', borderWidth: 2 } },
nextResult?.render({})
);
}
renderWebChat(
{
directLine,
polymiddleware: [
createActivityPolymiddleware(
next => request => activityComponent(MyMiddleware, { nextResult: next(request) })
)
],
store
},
document.getElementsByTagName('main')[0]
);
await pageConditions.uiConnected();
await directLine.emulateIncomingActivity('Hello, World!');
await pageConditions.numActivitiesShown(1);
await host.snapshot('local');
});
</script>
</body>
</html>