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 { StdEventType } from "../types/chat-io-messages.types";
|
||||||
import {
|
import {
|
||||||
Direction,
|
Direction,
|
||||||
|
IncomingMessageType,
|
||||||
IPayload,
|
IPayload,
|
||||||
|
IQuickReply,
|
||||||
ISubscriber,
|
ISubscriber,
|
||||||
ISuggestion,
|
ISuggestion,
|
||||||
QuickReplyType,
|
QuickReplyType,
|
||||||
@ -35,6 +37,16 @@ import { useSettings } from "./SettingsProvider";
|
|||||||
import { useSocket, useSubscribe } from "./SocketProvider";
|
import { useSocket, useSubscribe } from "./SocketProvider";
|
||||||
import { useWidget } from "./WidgetProvider";
|
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 {
|
interface Participant {
|
||||||
id: string;
|
id: string;
|
||||||
name: string;
|
name: string;
|
||||||
@ -262,16 +274,11 @@ const ChatProvider: React.FC<{
|
|||||||
"data" in newIOMessage &&
|
"data" in newIOMessage &&
|
||||||
"quick_replies" in newIOMessage.data
|
"quick_replies" in newIOMessage.data
|
||||||
) {
|
) {
|
||||||
setSuggestions(
|
const formattedSuggestions = formatQuickReplies(
|
||||||
(newIOMessage.data.quick_replies || []).map(
|
newIOMessage.data.quick_replies,
|
||||||
(qr) =>
|
|
||||||
({
|
|
||||||
content_type: QuickReplyType.text,
|
|
||||||
text: qr.title,
|
|
||||||
payload: qr.payload,
|
|
||||||
} as ISuggestion),
|
|
||||||
),
|
|
||||||
);
|
);
|
||||||
|
|
||||||
|
setSuggestions(formattedSuggestions);
|
||||||
} else {
|
} else {
|
||||||
setSuggestions([]);
|
setSuggestions([]);
|
||||||
}
|
}
|
||||||
@ -327,6 +334,18 @@ const ChatProvider: React.FC<{
|
|||||||
queryParams,
|
queryParams,
|
||||||
).toString()}`,
|
).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));
|
localStorage.setItem("profile", JSON.stringify(body.profile));
|
||||||
setMessages(
|
setMessages(
|
||||||
|
Loading…
Reference in New Issue
Block a user