@patternfly/chatbot 2.2.0-prerelease.30 → 2.2.0-prerelease.31
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cjs/Message/ErrorMessage/ErrorMessage.d.ts +4 -0
- package/dist/cjs/Message/ErrorMessage/ErrorMessage.js +26 -0
- package/dist/cjs/Message/Message.d.ts +3 -1
- package/dist/cjs/Message/Message.js +4 -3
- package/dist/cjs/Message/Message.test.js +25 -0
- package/dist/cjs/index.d.ts +2 -0
- package/dist/cjs/index.js +4 -1
- package/dist/cjs/tracking/console_tracking_provider.d.ts +10 -0
- package/dist/cjs/tracking/console_tracking_provider.js +27 -0
- package/dist/cjs/tracking/index.d.ts +2 -0
- package/dist/cjs/tracking/index.js +23 -0
- package/dist/cjs/tracking/posthog_tracking_provider.d.ts +9 -0
- package/dist/cjs/tracking/posthog_tracking_provider.js +37 -0
- package/dist/cjs/tracking/segment_tracking_provider.d.ts +10 -0
- package/dist/cjs/tracking/segment_tracking_provider.js +50 -0
- package/dist/cjs/tracking/trackingProviderProxy.d.ts +9 -0
- package/dist/cjs/tracking/trackingProviderProxy.js +24 -0
- package/dist/cjs/tracking/tracking_api.d.ts +8 -0
- package/dist/cjs/tracking/tracking_api.js +2 -0
- package/dist/cjs/tracking/tracking_registry.d.ts +4 -0
- package/dist/cjs/tracking/tracking_registry.js +33 -0
- package/dist/cjs/tracking/tracking_spi.d.ts +9 -0
- package/dist/cjs/tracking/tracking_spi.js +2 -0
- package/dist/cjs/tracking/umami_tracking_provider.d.ts +14 -0
- package/dist/cjs/tracking/umami_tracking_provider.js +44 -0
- package/dist/dynamic/tracking/package.json +1 -0
- package/dist/esm/Message/ErrorMessage/ErrorMessage.d.ts +4 -0
- package/dist/esm/Message/ErrorMessage/ErrorMessage.js +21 -0
- package/dist/esm/Message/Message.d.ts +3 -1
- package/dist/esm/Message/Message.js +4 -3
- package/dist/esm/Message/Message.test.js +25 -0
- package/dist/esm/index.d.ts +2 -0
- package/dist/esm/index.js +2 -0
- package/dist/esm/tracking/console_tracking_provider.d.ts +10 -0
- package/dist/esm/tracking/console_tracking_provider.js +23 -0
- package/dist/esm/tracking/index.d.ts +2 -0
- package/dist/esm/tracking/index.js +2 -0
- package/dist/esm/tracking/posthog_tracking_provider.d.ts +9 -0
- package/dist/esm/tracking/posthog_tracking_provider.js +33 -0
- package/dist/esm/tracking/segment_tracking_provider.d.ts +10 -0
- package/dist/esm/tracking/segment_tracking_provider.js +46 -0
- package/dist/esm/tracking/trackingProviderProxy.d.ts +9 -0
- package/dist/esm/tracking/trackingProviderProxy.js +22 -0
- package/dist/esm/tracking/tracking_api.d.ts +8 -0
- package/dist/esm/tracking/tracking_api.js +1 -0
- package/dist/esm/tracking/tracking_registry.d.ts +4 -0
- package/dist/esm/tracking/tracking_registry.js +26 -0
- package/dist/esm/tracking/tracking_spi.d.ts +9 -0
- package/dist/esm/tracking/tracking_spi.js +1 -0
- package/dist/esm/tracking/umami_tracking_provider.d.ts +14 -0
- package/dist/esm/tracking/umami_tracking_provider.js +40 -0
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/package.json +2 -2
- package/patternfly-docs/content/extensions/chatbot/about-chatbot.md +3 -0
- package/patternfly-docs/content/extensions/chatbot/examples/Analytics/Analytics.md +214 -0
- package/patternfly-docs/content/extensions/chatbot/examples/Messages/BotMessage.tsx +24 -1
- package/patternfly-docs/content/extensions/chatbot/examples/Messages/UserMessage.tsx +24 -1
- package/patternfly-docs/content/extensions/chatbot/examples/demos/Chatbot.md +2 -0
- package/patternfly-docs/content/extensions/chatbot/examples/demos/Chatbot.tsx +37 -24
- package/patternfly-docs/content/extensions/chatbot/img/analytics-example.svg +118 -0
- package/patternfly-docs/content/extensions/chatbot/img/chatbot-analytics.svg +51 -0
- package/patternfly-docs/content/extensions/chatbot/img/posthog.svg +30 -0
- package/patternfly-docs/content/extensions/chatbot/img/segment.svg +36 -0
- package/patternfly-docs/content/extensions/chatbot/img/umami.svg +30 -0
- package/src/Message/ErrorMessage/ErrorMessage.tsx +14 -0
- package/src/Message/Message.test.tsx +32 -0
- package/src/Message/Message.tsx +50 -41
- package/src/index.ts +3 -0
- package/src/tracking/console_tracking_provider.ts +30 -0
- package/src/tracking/index.ts +3 -0
- package/src/tracking/posthog_tracking_provider.ts +42 -0
- package/src/tracking/segment_tracking_provider.ts +62 -0
- package/src/tracking/trackingProviderProxy.ts +28 -0
- package/src/tracking/tracking_api.ts +11 -0
- package/src/tracking/tracking_registry.ts +33 -0
- package/src/tracking/tracking_spi.ts +14 -0
- package/src/tracking/umami_tracking_provider.ts +54 -0
@@ -2,7 +2,7 @@ import React from 'react';
|
|
2
2
|
|
3
3
|
import Message from '@patternfly/chatbot/dist/dynamic/Message';
|
4
4
|
import userAvatar from './user_avatar.svg';
|
5
|
-
import { Form, FormGroup, Radio } from '@patternfly/react-core';
|
5
|
+
import { AlertActionLink, Form, FormGroup, Radio } from '@patternfly/react-core';
|
6
6
|
|
7
7
|
export const UserMessageExample: React.FunctionComponent = () => {
|
8
8
|
const [variant, setVariant] = React.useState('code');
|
@@ -140,6 +140,21 @@ _Italic text, formatted with single underscores_
|
|
140
140
|
|
141
141
|
const image = ``;
|
142
142
|
|
143
|
+
const error = {
|
144
|
+
title: 'Could not load chat',
|
145
|
+
children: 'Wait a few minutes and check your network settings. If the issue persists: ',
|
146
|
+
actionLinks: (
|
147
|
+
<React.Fragment>
|
148
|
+
<AlertActionLink component="a" href="#">
|
149
|
+
Start a new chat
|
150
|
+
</AlertActionLink>
|
151
|
+
<AlertActionLink component="a" href="#">
|
152
|
+
Contact support
|
153
|
+
</AlertActionLink>
|
154
|
+
</React.Fragment>
|
155
|
+
)
|
156
|
+
};
|
157
|
+
|
143
158
|
return (
|
144
159
|
<>
|
145
160
|
<Message
|
@@ -235,6 +250,13 @@ _Italic text, formatted with single underscores_
|
|
235
250
|
label="Image"
|
236
251
|
id="user-image"
|
237
252
|
/>
|
253
|
+
<Radio
|
254
|
+
isChecked={variant === 'error'}
|
255
|
+
onChange={() => setVariant('error')}
|
256
|
+
name="user-message-error"
|
257
|
+
label="Error"
|
258
|
+
id="user-error"
|
259
|
+
/>
|
238
260
|
</FormGroup>
|
239
261
|
</Form>
|
240
262
|
<Message
|
@@ -245,6 +267,7 @@ _Italic text, formatted with single underscores_
|
|
245
267
|
tableProps={
|
246
268
|
variant === 'table' ? { 'aria-label': 'App information and user roles for user messages' } : undefined
|
247
269
|
}
|
270
|
+
error={variant === 'error' ? error : undefined}
|
248
271
|
/>
|
249
272
|
</>
|
250
273
|
);
|
@@ -57,6 +57,8 @@ import PFIconLogoColor from '../UI/PF-IconLogo-Color.svg';
|
|
57
57
|
import PFIconLogoReverse from '../UI/PF-IconLogo-Reverse.svg';
|
58
58
|
import userAvatar from '../Messages/user_avatar.svg';
|
59
59
|
import patternflyAvatar from '../Messages/patternfly_avatar.jpg';
|
60
|
+
import { getTrackingProviders } from "@patternfly/chatbot/dist/dynamic/tracking";
|
61
|
+
|
60
62
|
|
61
63
|
### Basic ChatBot
|
62
64
|
|
@@ -32,6 +32,8 @@ import PFIconLogoColor from '../UI/PF-IconLogo-Color.svg';
|
|
32
32
|
import PFIconLogoReverse from '../UI/PF-IconLogo-Reverse.svg';
|
33
33
|
import userAvatar from '../Messages/user_avatar.svg';
|
34
34
|
import patternflyAvatar from '../Messages/patternfly_avatar.jpg';
|
35
|
+
import { getTrackingProviders } from '@patternfly/chatbot/dist/dynamic/tracking';
|
36
|
+
import { InitProps } from '@patternfly/chatbot/dist/dynamic/tracking';
|
35
37
|
|
36
38
|
const footnoteProps = {
|
37
39
|
label: 'ChatBot uses AI. Check for mistakes.',
|
@@ -95,6 +97,20 @@ export default MessageLoading;
|
|
95
97
|
// The timestamps re-render with them.
|
96
98
|
const date = new Date();
|
97
99
|
|
100
|
+
const initProps: InitProps = {
|
101
|
+
segmentKey: 'TODO-key', // TODO add your key here
|
102
|
+
posthogKey: 'TODO-key',
|
103
|
+
umamiKey: 'TODO-key',
|
104
|
+
umamiHostUrl: 'http://localhost:3000', // TODO where is your JS provider?
|
105
|
+
console: true,
|
106
|
+
something: 'test'
|
107
|
+
};
|
108
|
+
|
109
|
+
const tracking = getTrackingProviders(initProps);
|
110
|
+
tracking.identify('user-123'); // TODO get real user id
|
111
|
+
tracking.trackPageView(window.document.documentURI);
|
112
|
+
|
113
|
+
const actionEventName = 'MessageAction';
|
98
114
|
const initialMessages: MessageProps[] = [
|
99
115
|
{
|
100
116
|
id: '1',
|
@@ -113,16 +129,11 @@ const initialMessages: MessageProps[] = [
|
|
113
129
|
avatar: patternflyAvatar,
|
114
130
|
timestamp: date.toLocaleString(),
|
115
131
|
actions: {
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
copy: { onClick: () => console.log('Copy') },
|
122
|
-
// eslint-disable-next-line no-console
|
123
|
-
share: { onClick: () => console.log('Share') },
|
124
|
-
// eslint-disable-next-line no-console
|
125
|
-
listen: { onClick: () => console.log('Listen') }
|
132
|
+
positive: { onClick: () => tracking.trackSingleItem(actionEventName, { response: 'Good response' }) },
|
133
|
+
negative: { onClick: () => tracking.trackSingleItem(actionEventName, { response: 'Bad response' }) },
|
134
|
+
copy: { onClick: () => tracking.trackSingleItem(actionEventName, { response: 'Copy' }) },
|
135
|
+
share: { onClick: () => tracking.trackSingleItem(actionEventName, { response: 'Share' }) },
|
136
|
+
listen: { onClick: () => tracking.trackSingleItem(actionEventName, { response: 'Listen' }) }
|
126
137
|
}
|
127
138
|
}
|
128
139
|
];
|
@@ -164,6 +175,7 @@ const initialConversations = {
|
|
164
175
|
]
|
165
176
|
};
|
166
177
|
|
178
|
+
const actionEvent2 = 'ActionEvent2';
|
167
179
|
export const ChatbotDemo: React.FunctionComponent = () => {
|
168
180
|
const [chatbotVisible, setChatbotVisible] = React.useState<boolean>(true);
|
169
181
|
const [displayMode, setDisplayMode] = React.useState<ChatbotDisplayMode>(ChatbotDisplayMode.default);
|
@@ -180,7 +192,7 @@ export const ChatbotDemo: React.FunctionComponent = () => {
|
|
180
192
|
const chatbotRef = React.useRef<HTMLDivElement>(null);
|
181
193
|
const historyRef = React.useRef<HTMLButtonElement>(null);
|
182
194
|
|
183
|
-
//
|
195
|
+
// Auto-scrolls to the latest message
|
184
196
|
React.useEffect(() => {
|
185
197
|
// don't scroll the first load - in this demo, we know we start with two messages
|
186
198
|
if (messages.length > 2) {
|
@@ -193,6 +205,7 @@ export const ChatbotDemo: React.FunctionComponent = () => {
|
|
193
205
|
value: string | number | undefined
|
194
206
|
) => {
|
195
207
|
setSelectedModel(value as string);
|
208
|
+
tracking.trackSingleItem('ModelSelected', { model: value });
|
196
209
|
};
|
197
210
|
|
198
211
|
const onSelectDisplayMode = (
|
@@ -210,6 +223,7 @@ export const ChatbotDemo: React.FunctionComponent = () => {
|
|
210
223
|
|
211
224
|
const handleSend = (message: string) => {
|
212
225
|
setIsSendButtonDisabled(true);
|
226
|
+
tracking.trackSingleItem('UserInputReceived', { text: message });
|
213
227
|
const newMessages: MessageProps[] = [];
|
214
228
|
// We can't use structuredClone since messages contains functions, but we can't mutate
|
215
229
|
// items that are going into state or the UI won't update correctly
|
@@ -255,21 +269,17 @@ export const ChatbotDemo: React.FunctionComponent = () => {
|
|
255
269
|
avatar: patternflyAvatar,
|
256
270
|
timestamp: date.toLocaleString(),
|
257
271
|
actions: {
|
258
|
-
|
259
|
-
|
260
|
-
|
261
|
-
|
262
|
-
|
263
|
-
copy: { onClick: () => console.log('Copy') },
|
264
|
-
// eslint-disable-next-line no-console
|
265
|
-
share: { onClick: () => console.log('Share') },
|
266
|
-
// eslint-disable-next-line no-console
|
267
|
-
listen: { onClick: () => console.log('Listen') }
|
272
|
+
positive: { onClick: () => tracking.trackSingleItem(actionEvent2, { response: 'Good response' }) },
|
273
|
+
negative: { onClick: () => tracking.trackSingleItem(actionEvent2, { response: 'Bad response' }) },
|
274
|
+
copy: { onClick: () => tracking.trackSingleItem(actionEvent2, { response: 'Copy' }) },
|
275
|
+
share: { onClick: () => tracking.trackSingleItem(actionEvent2, { response: 'Share' }) },
|
276
|
+
listen: { onClick: () => tracking.trackSingleItem(actionEvent2, { response: 'Listen' }) }
|
268
277
|
}
|
269
278
|
});
|
270
279
|
setMessages(loadedMessages);
|
271
280
|
// make announcement to assistive devices that new message has loaded
|
272
281
|
setAnnouncement(`Message from Bot: API response goes here`);
|
282
|
+
tracking.trackSingleItem('BotResponded', { undefined });
|
273
283
|
setIsSendButtonDisabled(false);
|
274
284
|
}, 5000);
|
275
285
|
};
|
@@ -339,7 +349,10 @@ export const ChatbotDemo: React.FunctionComponent = () => {
|
|
339
349
|
<ChatbotToggle
|
340
350
|
tooltipLabel="Chatbot"
|
341
351
|
isChatbotVisible={chatbotVisible}
|
342
|
-
onToggleChatbot={()
|
352
|
+
onToggleChatbot={function () {
|
353
|
+
setChatbotVisible(!chatbotVisible);
|
354
|
+
tracking.trackSingleItem('Chatbot Visible', { isVisible: !chatbotVisible }); // TODO correct?
|
355
|
+
}}
|
343
356
|
id="chatbot-toggle"
|
344
357
|
ref={toggleRef}
|
345
358
|
/>
|
@@ -441,9 +454,9 @@ export const ChatbotDemo: React.FunctionComponent = () => {
|
|
441
454
|
prompts={welcomePrompts}
|
442
455
|
/>
|
443
456
|
{/* This code block enables scrolling to the top of the last message.
|
444
|
-
You can instead choose to move the div with scrollToBottomRef on it below
|
457
|
+
You can instead choose to move the div with scrollToBottomRef on it below
|
445
458
|
the map of messages, so that users are forced to scroll to the bottom.
|
446
|
-
If you are using streaming, you will want to take a different approach;
|
459
|
+
If you are using streaming, you will want to take a different approach;
|
447
460
|
see: https://github.com/patternfly/chatbot/issues/201#issuecomment-2400725173 */}
|
448
461
|
{messages.map((message, index) => {
|
449
462
|
if (index === messages.length - 1) {
|