Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Support top suggested replies #404

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 14 additions & 10 deletions src/components/chat/ui/ChatMessageList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,18 @@ export const ChatMessageList = () => {
filteredMessages[index + 1],
enableMessageGrouping,
);

const renderSuggestedReplies = showRepliesOnLastMessage && suggestedReplies.length > 0;
const { suggestedRepliesOptions, suggestedRepliesDirection } = botStudioEditProps ?? {};
const isSuggestedRepliesAtTop = suggestedRepliesOptions?.location === 'top';
const SuggestedReplies =
<SuggestedRepliesContainer
replies={suggestedReplies}
type={suggestedRepliesOptions?.direction ?? suggestedRepliesDirection}
sendUserMessage={(params) => {
dataSource.sendUserMessage(params, handlers.onAfterSendMessage).then(handlers.onAfterSendMessage);
}}
/>;

return (
<div style={{ padding: '0 16px' }} key={getComponentKeyFromMessage(message)}>
Expand All @@ -72,6 +84,7 @@ export const ChatMessageList = () => {
/>
)}
<div style={{ marginBottom: index === filteredMessages.length - 1 ? 0 : 16 }}>
{renderSuggestedReplies && isSuggestedRepliesAtTop && SuggestedReplies}
<CustomMessage
message={message as any}
activeSpinnerId={typingTargetMessageId}
Expand All @@ -84,16 +97,7 @@ export const ChatMessageList = () => {
message.messageId === channel?.lastMessage?.messageId && (
<MessageDataContent messageData={message.data} />
)}

{showRepliesOnLastMessage && suggestedReplies.length > 0 && (
<SuggestedRepliesContainer
replies={suggestedReplies}
type={botStudioEditProps?.suggestedRepliesDirection}
sendUserMessage={(params) => {
dataSource.sendUserMessage(params, handlers.onAfterSendMessage).then(handlers.onAfterSendMessage);
}}
/>
)}
{renderSuggestedReplies && !isSuggestedRepliesAtTop && SuggestedReplies}
</div>
</div>
);
Expand Down
7 changes: 7 additions & 0 deletions src/const.ts
Original file line number Diff line number Diff line change
Expand Up @@ -108,12 +108,19 @@ export interface BotInfo {
nickname?: string;
}

interface SuggestedRepliesOptions {
direction?: 'horizontal' | 'vertical';
location?: 'top' | 'bottom';
}

export interface BotStudioEditProps {
botInfo?: BotInfo;
aiAttributes?: Record<string, unknown>;
welcomeMessages?: WelcomeUserMessage[];
styles?: WidgetStyles;
// @deprecated Use `SuggestedRepliesOptions` instead.
suggestedRepliesDirection?: 'horizontal' | 'vertical';
suggestedRepliesOptions?: SuggestedRepliesOptions;
}

export interface MessageInputControls {
Expand Down
Loading