mirror of
https://github.com/hexastack/hexabot
synced 2025-06-26 18:27:28 +00:00
fix(widget): support showing quick replies after a refresh
This commit is contained in:
parent
76ecb900c5
commit
0eaef3cf60
@ -20,7 +20,9 @@ import { useSubscribeBroadcastChannel } from "../hooks/useSubscribeBroadcastChan
|
||||
import { StdEventType } from "../types/chat-io-messages.types";
|
||||
import {
|
||||
Direction,
|
||||
IncomingMessageType,
|
||||
IPayload,
|
||||
IQuickReply,
|
||||
ISubscriber,
|
||||
ISuggestion,
|
||||
QuickReplyType,
|
||||
@ -35,6 +37,16 @@ import { useSettings } from "./SettingsProvider";
|
||||
import { useSocket, useSubscribe } from "./SocketProvider";
|
||||
import { useWidget } from "./WidgetProvider";
|
||||
|
||||
const formatQuickReplies = (quick_replies?: IQuickReply[]): ISuggestion[] =>
|
||||
(quick_replies || []).map(
|
||||
(qr) =>
|
||||
({
|
||||
content_type: QuickReplyType.text,
|
||||
text: qr.title,
|
||||
payload: qr.payload,
|
||||
} as ISuggestion),
|
||||
);
|
||||
|
||||
interface Participant {
|
||||
id: string;
|
||||
name: string;
|
||||
@ -262,16 +274,11 @@ const ChatProvider: React.FC<{
|
||||
"data" in newIOMessage &&
|
||||
"quick_replies" in newIOMessage.data
|
||||
) {
|
||||
setSuggestions(
|
||||
(newIOMessage.data.quick_replies || []).map(
|
||||
(qr) =>
|
||||
({
|
||||
content_type: QuickReplyType.text,
|
||||
text: qr.title,
|
||||
payload: qr.payload,
|
||||
} as ISuggestion),
|
||||
),
|
||||
const formattedSuggestions = formatQuickReplies(
|
||||
newIOMessage.data.quick_replies,
|
||||
);
|
||||
|
||||
setSuggestions(formattedSuggestions);
|
||||
} else {
|
||||
setSuggestions([]);
|
||||
}
|
||||
@ -327,6 +334,18 @@ const ChatProvider: React.FC<{
|
||||
queryParams,
|
||||
).toString()}`,
|
||||
);
|
||||
const mostRecentMessage = body.messages.at(-1);
|
||||
|
||||
if (
|
||||
mostRecentMessage &&
|
||||
mostRecentMessage.type === IncomingMessageType.quick_replies
|
||||
) {
|
||||
const formattedSuggestions = formatQuickReplies(
|
||||
mostRecentMessage.data["quick_replies"],
|
||||
);
|
||||
|
||||
setSuggestions(formattedSuggestions);
|
||||
}
|
||||
|
||||
localStorage.setItem("profile", JSON.stringify(body.profile));
|
||||
setMessages(
|
||||
|
Loading…
Reference in New Issue
Block a user