|
12 | 12 | <body> |
13 | 13 | <main id="webchat"></main> |
14 | 14 | <script type="module"> |
| 15 | + const streamingFormat = new URL(window.location.href).searchParams.get('streamingFormat') ?? 'channelData'; // can be entity or channelData |
| 16 | + |
| 17 | + function addLivestreamingMetadata(activity, livestreamingMetadata) { |
| 18 | + return streamingFormat === 'entity' |
| 19 | + ? { |
| 20 | + ...activity, |
| 21 | + entities: [...(activity.entities ?? []), { ...livestreamingMetadata, type: 'streaminfo' }] |
| 22 | + } |
| 23 | + : { |
| 24 | + ...activity, |
| 25 | + channelData: { ...activity.channelData, ...livestreamingMetadata } |
| 26 | + }; |
| 27 | + } |
| 28 | + |
15 | 29 | run(async function () { |
16 | 30 | const { |
17 | 31 | React: { createElement }, |
|
21 | 35 | decorator: { WebChatDecorator }, |
22 | 36 | hooks: { useActivityKeys, useGetActivitiesByKey } |
23 | 37 | } |
24 | | - } = window; // Imports in UMD fashion.pkve |
| 38 | + } = window; // Imports in UMD fashion. |
25 | 39 |
|
26 | 40 | const { directLine, store } = testHelpers.createDirectLineEmulator(); |
27 | 41 | let currentActivityKeysWithId = []; |
28 | 42 |
|
29 | | - const url = new URL(window.location.href); |
30 | | - const streamingFormat = url.searchParams.get('streamingFormat') ?? 'channelData'; // can be entity or channelData |
31 | | - |
32 | | - const makeActivity = (input, stream) => { |
33 | | - if (!stream) return input; |
34 | | - if (streamingFormat == 'entity') { |
35 | | - input.entities = [{ |
36 | | - ...stream, |
37 | | - type: 'streaminfo' |
38 | | - }] |
39 | | - } else { |
40 | | - input.channelData = stream; |
41 | | - } |
42 | | - return input; |
43 | | - } |
44 | | - |
45 | 43 | const Monitor = () => { |
46 | 44 | const [activityKeys] = useActivityKeys(); |
47 | 45 | const getActivitiesByKey = useGetActivitiesByKey(); |
|
65 | 63 | await pageConditions.uiConnected(); |
66 | 64 |
|
67 | 65 | // SETUP: Bot sent a message. |
68 | | - await directLine.emulateIncomingActivity( |
69 | | - makeActivity({ |
70 | | - id: 'a-00001', |
71 | | - from: { id: 'u-00001', name: 'Bot', role: 'bot' }, |
72 | | - text: 'Adipisicing cupidatat eu Lorem anim ut aute magna occaecat id cillum.', |
73 | | - type: 'message' |
74 | | - }) |
75 | | - ); |
| 66 | + await directLine.emulateIncomingActivity({ |
| 67 | + id: 'a-00001', |
| 68 | + from: { id: 'u-00001', name: 'Bot', role: 'bot' }, |
| 69 | + text: 'Adipisicing cupidatat eu Lorem anim ut aute magna occaecat id cillum.', |
| 70 | + type: 'message' |
| 71 | + }); |
76 | 72 |
|
77 | 73 | let firstActivityKey = currentActivityKeysWithId[0][0]; |
78 | 74 |
|
79 | 75 | // WHEN: Bot is typing a message. |
80 | 76 | const firstTypingActivityId = 't-00001'; |
81 | 77 |
|
82 | 78 | await directLine.emulateIncomingActivity( |
83 | | - makeActivity({ |
84 | | - from: { id: 'u-00001', name: 'Bot', role: 'bot' }, |
85 | | - id: firstTypingActivityId, |
86 | | - text: 'A quick', |
87 | | - type: 'typing' |
88 | | - }, { streamSequence: 1, streamType: 'streaming' }) |
| 79 | + addLivestreamingMetadata( |
| 80 | + { |
| 81 | + from: { id: 'u-00001', name: 'Bot', role: 'bot' }, |
| 82 | + id: firstTypingActivityId, |
| 83 | + text: 'A quick', |
| 84 | + type: 'typing' |
| 85 | + }, |
| 86 | + { streamSequence: 1, streamType: 'streaming' } |
| 87 | + ) |
89 | 88 | ); |
90 | 89 |
|
91 | 90 | let secondActivityKey = currentActivityKeysWithId[1][0]; |
|
109 | 108 | // --- |
110 | 109 |
|
111 | 110 | // WHEN: Bot send another message. |
112 | | - await directLine.emulateIncomingActivity( |
113 | | - makeActivity({ |
114 | | - id: 'a-00003', |
115 | | - from: { id: 'u-00001', name: 'Bot', role: 'bot' }, |
116 | | - text: 'Amet consequat enim incididunt excepteur aliquip magna duis et tempor.', |
117 | | - type: 'message' |
118 | | - }) |
119 | | - ); |
| 111 | + await directLine.emulateIncomingActivity({ |
| 112 | + id: 'a-00003', |
| 113 | + from: { id: 'u-00001', name: 'Bot', role: 'bot' }, |
| 114 | + text: 'Amet consequat enim incididunt excepteur aliquip magna duis et tempor.', |
| 115 | + type: 'message' |
| 116 | + }); |
120 | 117 |
|
121 | 118 | let thirdActivityKey = currentActivityKeysWithId[2][0]; |
122 | 119 |
|
|
145 | 142 |
|
146 | 143 | // WHEN: Bot continue typing the message. |
147 | 144 | await directLine.emulateIncomingActivity( |
148 | | - makeActivity({ |
149 | | - from: { id: 'u-00001', name: 'Bot', role: 'bot' }, |
150 | | - id: 't-00002', |
151 | | - text: 'A quick brown fox', |
152 | | - type: 'typing' |
153 | | - }, { streamId: firstTypingActivityId, streamSequence: 2, streamType: 'streaming' }) |
| 145 | + addLivestreamingMetadata( |
| 146 | + { |
| 147 | + from: { id: 'u-00001', name: 'Bot', role: 'bot' }, |
| 148 | + id: 't-00002', |
| 149 | + text: 'A quick brown fox', |
| 150 | + type: 'typing' |
| 151 | + }, |
| 152 | + { streamId: firstTypingActivityId, streamSequence: 2, streamType: 'streaming' } |
| 153 | + ) |
154 | 154 | ); |
155 | 155 |
|
156 | 156 | // THEN: Should display 3 messages, the order should kept the same. |
|
178 | 178 |
|
179 | 179 | // WHEN: Bot continue typing the message. |
180 | 180 | await directLine.emulateIncomingActivity( |
181 | | - makeActivity({ |
182 | | - from: { id: 'u-00001', name: 'Bot', role: 'bot' }, |
183 | | - id: 't-00003', |
184 | | - text: 'A quick brown fox jumped over', |
185 | | - type: 'typing' |
186 | | - }, { streamId: firstTypingActivityId, streamSequence: 3, streamType: 'streaming' }) |
| 181 | + addLivestreamingMetadata( |
| 182 | + { |
| 183 | + from: { id: 'u-00001', name: 'Bot', role: 'bot' }, |
| 184 | + id: 't-00003', |
| 185 | + text: 'A quick brown fox jumped over', |
| 186 | + type: 'typing' |
| 187 | + }, |
| 188 | + { streamId: firstTypingActivityId, streamSequence: 3, streamType: 'streaming' } |
| 189 | + ) |
187 | 190 | ); |
188 | 191 |
|
189 | 192 | // THEN: Should display 3 messages, the order should kept the same. |
|
211 | 214 |
|
212 | 215 | // WHEN: Bot finished typing the message. |
213 | 216 | await directLine.emulateIncomingActivity( |
214 | | - makeActivity({ |
215 | | - from: { id: 'u-00001', name: 'Bot', role: 'bot' }, |
216 | | - id: 'a-00002', |
217 | | - text: 'A quick brown fox jumped over the lazy dogs.', |
218 | | - type: 'message' |
219 | | - }, { streamId: firstTypingActivityId, streamType: 'final' }) |
| 217 | + addLivestreamingMetadata( |
| 218 | + { |
| 219 | + from: { id: 'u-00001', name: 'Bot', role: 'bot' }, |
| 220 | + id: 'a-00002', |
| 221 | + text: 'A quick brown fox jumped over the lazy dogs.', |
| 222 | + type: 'message' |
| 223 | + }, |
| 224 | + { streamId: firstTypingActivityId, streamType: 'final' } |
| 225 | + ) |
220 | 226 | ); |
221 | 227 |
|
222 | 228 | // THEN: Should display 3 messages. |
|
0 commit comments