Chat
Use a Chat component to allow users to leave comments for each other or chat directly with ChatGPT powered by the OpenAI integration
Chat Properties
Component Properties
Property | Description |
---|---|
Content | |
Header | Set the chat title |
Message history | Array containing the message history. Each object in the array represents a message |
Message | Field name to use to access the message |
Name | Field name to use to access the user's display name |
Avatar URL (optional) | Field name to use to access the avatar image URL |
Timestamp (optional) | Field name to use to access the timestamp of a message |
Appearance | |
Header style | Changes the style (font, size, color, etc.) of the chat's header text. Configure styles in the Typography settings |
Placeholder text | Sets the placeholder text for the chat input |
Timestamp format | Sets the format of the timestamp |
Show pending message | While the onSendMessage action is running, show the message as pending |
Enable pending state | Enables the pending state for the chat widget after a message has been sent |
pending state text | Sets the text for the pending state |
pending state timeout | Length of time between sending the message and showing the pending state in seconds |
Allow emojis | Show emoji menu in editor, values are a boolean |
Layout | |
Width | Controls the width of the component |
Height | Controls the height of the component |
Visible | Controls the visibility of the component, values are a boolean |
Collapse when invisible | Controls what happens when the component is invisible. When true , other components shift to fill its space; when false , it leaves a blank space. This has no effect in edit mode. |
Interaction | |
Search | Allow users to search for messages, values are a boolean |
Send on "Enter" | Hitting enter will send the message, values are a boolean |
Allow images | Allow users to add images to their messages, values are a boolean |
Reference Properties
Properties can be accessed from other frontend components and backend APIs by adding the name of the Chat component, and dot referencing the property. For a Chat component named Chat1
:
Property | Description |
---|---|
Chat1.userMessageText | Returns a string of the current text in the message field in plain text |
Chat1.messageHistory | Returns an array of objects containing the message history |
Chat1.userMessageRichText | Returns a string of the current text in the message field in HTML format |
Chat1.userMessageImages | Returns an array of image URLs currently in the message field |
Chat1.lastMessage | Returns an object of the last message in the message history |
Chat1.isVisible | Returns the boolean value of the component's visibility (True, if it is visible) |
Chat1.isDisabled | Returns the boolean value of the component's disabled state (True, if it is disabled) |
Events
The following events are triggered by user interactions with Chat components. Use event handlers to trigger actions in response to user events.
Property | Description |
---|---|
onMessageSend | Trigger an action when a message is sent |
Example Usage:
Power the Chat component with ChatGPT
info
To create a Chat component that streams messages in real time, follow the guide
here.
- Set up the OpenAI integration
- Add a Chat component to the canvas
- Create a new backend API with an OpenAI step
- Set Action to "Generate ChatGPT Response"
- Set Prompt to
{{Chat1.userMessageText}}
- Set Message History to
{{Chat1.messageHistory}}
- Set the Message History Data field in the Chat component to
{{API1.response.messageHistory}}
- Add an event handler
onMessageSend
to run the API
Now, when you type in the Chat component, you can interact directly with ChatGPT in your Superblocks application.