@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.
Files changed (77) hide show
  1. package/dist/cjs/Message/ErrorMessage/ErrorMessage.d.ts +4 -0
  2. package/dist/cjs/Message/ErrorMessage/ErrorMessage.js +26 -0
  3. package/dist/cjs/Message/Message.d.ts +3 -1
  4. package/dist/cjs/Message/Message.js +4 -3
  5. package/dist/cjs/Message/Message.test.js +25 -0
  6. package/dist/cjs/index.d.ts +2 -0
  7. package/dist/cjs/index.js +4 -1
  8. package/dist/cjs/tracking/console_tracking_provider.d.ts +10 -0
  9. package/dist/cjs/tracking/console_tracking_provider.js +27 -0
  10. package/dist/cjs/tracking/index.d.ts +2 -0
  11. package/dist/cjs/tracking/index.js +23 -0
  12. package/dist/cjs/tracking/posthog_tracking_provider.d.ts +9 -0
  13. package/dist/cjs/tracking/posthog_tracking_provider.js +37 -0
  14. package/dist/cjs/tracking/segment_tracking_provider.d.ts +10 -0
  15. package/dist/cjs/tracking/segment_tracking_provider.js +50 -0
  16. package/dist/cjs/tracking/trackingProviderProxy.d.ts +9 -0
  17. package/dist/cjs/tracking/trackingProviderProxy.js +24 -0
  18. package/dist/cjs/tracking/tracking_api.d.ts +8 -0
  19. package/dist/cjs/tracking/tracking_api.js +2 -0
  20. package/dist/cjs/tracking/tracking_registry.d.ts +4 -0
  21. package/dist/cjs/tracking/tracking_registry.js +33 -0
  22. package/dist/cjs/tracking/tracking_spi.d.ts +9 -0
  23. package/dist/cjs/tracking/tracking_spi.js +2 -0
  24. package/dist/cjs/tracking/umami_tracking_provider.d.ts +14 -0
  25. package/dist/cjs/tracking/umami_tracking_provider.js +44 -0
  26. package/dist/dynamic/tracking/package.json +1 -0
  27. package/dist/esm/Message/ErrorMessage/ErrorMessage.d.ts +4 -0
  28. package/dist/esm/Message/ErrorMessage/ErrorMessage.js +21 -0
  29. package/dist/esm/Message/Message.d.ts +3 -1
  30. package/dist/esm/Message/Message.js +4 -3
  31. package/dist/esm/Message/Message.test.js +25 -0
  32. package/dist/esm/index.d.ts +2 -0
  33. package/dist/esm/index.js +2 -0
  34. package/dist/esm/tracking/console_tracking_provider.d.ts +10 -0
  35. package/dist/esm/tracking/console_tracking_provider.js +23 -0
  36. package/dist/esm/tracking/index.d.ts +2 -0
  37. package/dist/esm/tracking/index.js +2 -0
  38. package/dist/esm/tracking/posthog_tracking_provider.d.ts +9 -0
  39. package/dist/esm/tracking/posthog_tracking_provider.js +33 -0
  40. package/dist/esm/tracking/segment_tracking_provider.d.ts +10 -0
  41. package/dist/esm/tracking/segment_tracking_provider.js +46 -0
  42. package/dist/esm/tracking/trackingProviderProxy.d.ts +9 -0
  43. package/dist/esm/tracking/trackingProviderProxy.js +22 -0
  44. package/dist/esm/tracking/tracking_api.d.ts +8 -0
  45. package/dist/esm/tracking/tracking_api.js +1 -0
  46. package/dist/esm/tracking/tracking_registry.d.ts +4 -0
  47. package/dist/esm/tracking/tracking_registry.js +26 -0
  48. package/dist/esm/tracking/tracking_spi.d.ts +9 -0
  49. package/dist/esm/tracking/tracking_spi.js +1 -0
  50. package/dist/esm/tracking/umami_tracking_provider.d.ts +14 -0
  51. package/dist/esm/tracking/umami_tracking_provider.js +40 -0
  52. package/dist/tsconfig.tsbuildinfo +1 -1
  53. package/package.json +2 -2
  54. package/patternfly-docs/content/extensions/chatbot/about-chatbot.md +3 -0
  55. package/patternfly-docs/content/extensions/chatbot/examples/Analytics/Analytics.md +214 -0
  56. package/patternfly-docs/content/extensions/chatbot/examples/Messages/BotMessage.tsx +24 -1
  57. package/patternfly-docs/content/extensions/chatbot/examples/Messages/UserMessage.tsx +24 -1
  58. package/patternfly-docs/content/extensions/chatbot/examples/demos/Chatbot.md +2 -0
  59. package/patternfly-docs/content/extensions/chatbot/examples/demos/Chatbot.tsx +37 -24
  60. package/patternfly-docs/content/extensions/chatbot/img/analytics-example.svg +118 -0
  61. package/patternfly-docs/content/extensions/chatbot/img/chatbot-analytics.svg +51 -0
  62. package/patternfly-docs/content/extensions/chatbot/img/posthog.svg +30 -0
  63. package/patternfly-docs/content/extensions/chatbot/img/segment.svg +36 -0
  64. package/patternfly-docs/content/extensions/chatbot/img/umami.svg +30 -0
  65. package/src/Message/ErrorMessage/ErrorMessage.tsx +14 -0
  66. package/src/Message/Message.test.tsx +32 -0
  67. package/src/Message/Message.tsx +50 -41
  68. package/src/index.ts +3 -0
  69. package/src/tracking/console_tracking_provider.ts +30 -0
  70. package/src/tracking/index.ts +3 -0
  71. package/src/tracking/posthog_tracking_provider.ts +42 -0
  72. package/src/tracking/segment_tracking_provider.ts +62 -0
  73. package/src/tracking/trackingProviderProxy.ts +28 -0
  74. package/src/tracking/tracking_api.ts +11 -0
  75. package/src/tracking/tracking_registry.ts +33 -0
  76. package/src/tracking/tracking_spi.ts +14 -0
  77. 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 = `![Multi-colored wavy lines on a black background](https://cdn.dribbble.com/userupload/10651749/file/original-8a07b8e39d9e8bf002358c66fce1223e.gif)`;
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
- // eslint-disable-next-line no-console
117
- positive: { onClick: () => console.log('Good response') },
118
- // eslint-disable-next-line no-console
119
- negative: { onClick: () => console.log('Bad response') },
120
- // eslint-disable-next-line no-console
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
- // Autu-scrolls to the latest message
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
- // eslint-disable-next-line no-console
259
- positive: { onClick: () => console.log('Good response') },
260
- // eslint-disable-next-line no-console
261
- negative: { onClick: () => console.log('Bad response') },
262
- // eslint-disable-next-line no-console
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={() => setChatbotVisible(!chatbotVisible)}
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) {