|
| 1 | +import { FunctionComponent } from 'react'; |
| 2 | +import Message, { |
| 3 | + ErrorMessage, |
| 4 | + MessageAndActions, |
| 5 | + MessageAttachmentItem, |
| 6 | + MessageAttachmentsContainer, |
| 7 | + MessageLoading |
| 8 | +} from '@patternfly/chatbot/dist/dynamic/Message'; |
| 9 | +import MarkdownContent from '@patternfly/chatbot/dist/dynamic/MarkdownContent'; |
| 10 | +import ToolCall from '@patternfly/chatbot/dist/dynamic/ToolCall'; |
| 11 | +import ToolResponse from '@patternfly/chatbot/dist/dynamic/ToolResponse'; |
| 12 | +import FileDetailsLabel from '@patternfly/chatbot/dist/dynamic/FileDetailsLabel'; |
| 13 | +import ResponseActions, { ResponseActionsGroups } from '@patternfly/chatbot/dist/dynamic/ResponseActions'; |
| 14 | +import patternflyAvatar from './patternfly_avatar.jpg'; |
| 15 | +import userAvatar from './user_avatar.svg'; |
| 16 | + |
| 17 | +export const MessageWithCustomStructure: FunctionComponent = () => ( |
| 18 | + <> |
| 19 | + <Message name="Bot" role="bot" avatar={patternflyAvatar}> |
| 20 | + <MessageAndActions> |
| 21 | + <MarkdownContent |
| 22 | + content={`This is a basic message with a more custom, fine-tuned structure. You can pass markdown to the MarkdownContent component, such as **bold content with double asterisks** or _italic content with single underscores_.`} |
| 23 | + /> |
| 24 | + <ToolCall titleText="Calling 'awesome_tool'" loadingText="Loading 'awesome_tool'" isLoading={true} /> |
| 25 | + <ToolResponse |
| 26 | + toggleContent="Tool response: fetch_user_data" |
| 27 | + subheading="Executed in 0.3 seconds" |
| 28 | + body="Successfully retrieved user data from the database." |
| 29 | + cardTitle="User Data Response" |
| 30 | + cardBody="The tool returned 150 user records matching the specified criteria." |
| 31 | + /> |
| 32 | + <ErrorMessage title="An issue placed within this custom structure." /> |
| 33 | + <MarkdownContent |
| 34 | + isMarkdownDisabled |
| 35 | + textComponent={`You can also pass plain text without markdown to the MarkdownContent component by passing the isMarkdownDisabled prop. Optionally, you can also use the textComponent prop instead of content.`} |
| 36 | + /> |
| 37 | + <ToolCall titleText="Calling 'more_awesome_tool'" loadingText="Loading 'more_awesome_tool'" isLoading={true} /> |
| 38 | + <ToolCall titleText="Calling 'even_more_awesome_tool'" loadingText="Loading 'even_more_awesome_tool'" /> |
| 39 | + <MessageLoading loadingWord="Loading something in the middle of a custom structured message" /> |
| 40 | + <MarkdownContent |
| 41 | + content={`You can even place a message loading state in the middle of a message, as seen above.`} |
| 42 | + /> |
| 43 | + <ResponseActionsGroups> |
| 44 | + <ResponseActions |
| 45 | + actions={{ |
| 46 | + positive: { onClick: () => console.log('Good response'), ariaLabel: 'Good response' }, |
| 47 | + negative: { onClick: () => console.log('Bad response'), ariaLabel: 'Bad response' } |
| 48 | + }} |
| 49 | + persistActionSelection={true} |
| 50 | + /> |
| 51 | + <ResponseActions |
| 52 | + actions={{ |
| 53 | + copy: { onClick: () => console.log('Copied!'), ariaLabel: 'Copy' }, |
| 54 | + download: { onClick: () => console.log('Downloaded!'), ariaLabel: 'Download' } |
| 55 | + }} |
| 56 | + persistActionSelection={false} |
| 57 | + /> |
| 58 | + <ResponseActions |
| 59 | + actions={{ |
| 60 | + listen: { onClick: () => console.log('Listening'), ariaLabel: 'Listen' } |
| 61 | + }} |
| 62 | + persistActionSelection={true} |
| 63 | + /> |
| 64 | + </ResponseActionsGroups> |
| 65 | + </MessageAndActions> |
| 66 | + </Message> |
| 67 | + <Message name="User" role="user" avatar={userAvatar}> |
| 68 | + <MessageAndActions> |
| 69 | + <MarkdownContent content="This message is in the MessageAndActions container, and the file attachments below are in their own separate MessageAttachmentsContainer!" /> |
| 70 | + </MessageAndActions> |
| 71 | + <MessageAttachmentsContainer> |
| 72 | + <MessageAttachmentItem> |
| 73 | + <FileDetailsLabel fileName="project-report.pdf" /> |
| 74 | + </MessageAttachmentItem> |
| 75 | + <MessageAttachmentItem> |
| 76 | + <FileDetailsLabel fileName="data-analysis.csv" /> |
| 77 | + </MessageAttachmentItem> |
| 78 | + <MessageAttachmentItem> |
| 79 | + <FileDetailsLabel fileName="presentation-slides.pptx" /> |
| 80 | + </MessageAttachmentItem> |
| 81 | + </MessageAttachmentsContainer> |
| 82 | + </Message> |
| 83 | + </> |
| 84 | +); |
0 commit comments