@droppii-org/chat-sdk 0.1.83 → 0.1.84
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -14,7 +14,7 @@ export declare const useBotFlow: ({ conversationId, isBotThread, }: UseBotFlowPa
|
|
|
14
14
|
currentButtonsBlock: BotInputButtonsBlock | null;
|
|
15
15
|
menuItems: import("../../types/conversation").BotButtonOption[];
|
|
16
16
|
isInCsSession: boolean;
|
|
17
|
-
|
|
17
|
+
isCsConfirmOpen: boolean;
|
|
18
18
|
start: () => Promise<void>;
|
|
19
19
|
selectButton: (actionId: string) => Promise<void>;
|
|
20
20
|
restart: () => Promise<void>;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useBotFlow.d.ts","sourceRoot":"","sources":["../../../src/hooks/conversation/useBotFlow.ts"],"names":[],"mappings":"AAMA,OAAO,EAKL,KAAK,oBAAoB,EACzB,KAAK,eAAe,EACrB,MAAM,sBAAsB,CAAC;AAgB9B,MAAM,MAAM,aAAa,GAAG,SAAS,GAAG,aAAa,CAAC;
|
|
1
|
+
{"version":3,"file":"useBotFlow.d.ts","sourceRoot":"","sources":["../../../src/hooks/conversation/useBotFlow.ts"],"names":[],"mappings":"AAMA,OAAO,EAKL,KAAK,oBAAoB,EACzB,KAAK,eAAe,EACrB,MAAM,sBAAsB,CAAC;AAgB9B,MAAM,MAAM,aAAa,GAAG,SAAS,GAAG,aAAa,CAAC;AAMtD,UAAU,gBAAgB;IACxB,cAAc,EAAE,MAAM,CAAC;IACvB,WAAW,EAAE,OAAO,CAAC;CACtB;AAsBD,eAAO,MAAM,UAAU,GAAI,kCAGxB,gBAAgB;;;;;;;;;;;;6BAkIqB,MAAM;;6BA0DN,eAAe;;;CAmDtD,CAAC"}
|
|
@@ -54,7 +54,7 @@ export const useBotFlow = ({ conversationId, isBotThread, }) => {
|
|
|
54
54
|
const { sendMergeMessage } = useSendMessage({
|
|
55
55
|
scrollEvent: "CONVERSATION_CHAT_SCROLL_TO_BOTTOM_IF_AT_BOTTOM",
|
|
56
56
|
});
|
|
57
|
-
const [
|
|
57
|
+
const [pendingCsAction, setPendingCsAction] = useState(null);
|
|
58
58
|
const menuQuery = useBotMainMenu(conversationId, isBotThread && botType === BOT_TYPE.FLOW);
|
|
59
59
|
const menuItems = filterVisibleBotButtons((_c = menuQuery.data) !== null && _c !== void 0 ? _c : []);
|
|
60
60
|
useEffect(() => {
|
|
@@ -89,7 +89,7 @@ export const useBotFlow = ({ conversationId, isBotThread, }) => {
|
|
|
89
89
|
emitter.off("PUSH_NEW_MSG", handleNewMessage);
|
|
90
90
|
};
|
|
91
91
|
}, [authUserID]);
|
|
92
|
-
const activeStep =
|
|
92
|
+
const activeStep = isActiveConversation ? flowCurrentStep : null;
|
|
93
93
|
const currentButtonsBlock = (_d = activeStep === null || activeStep === void 0 ? void 0 : activeStep.data.children.find((child) => child.type === BotBlockType.InputButtons)) !== null && _d !== void 0 ? _d : null;
|
|
94
94
|
const isInActiveCsSession = isInCsSession({ flowCurrentStep: activeStep });
|
|
95
95
|
const isProcessing = runMutation.isPending ||
|
|
@@ -142,7 +142,7 @@ export const useBotFlow = ({ conversationId, isBotThread, }) => {
|
|
|
142
142
|
}
|
|
143
143
|
await runStep(activeStep, actionId);
|
|
144
144
|
};
|
|
145
|
-
const
|
|
145
|
+
const performRestart = async () => {
|
|
146
146
|
var _a;
|
|
147
147
|
const flow = {
|
|
148
148
|
groupId: (_a = activeStep === null || activeStep === void 0 ? void 0 : activeStep.id) !== null && _a !== void 0 ? _a : "",
|
|
@@ -158,6 +158,13 @@ export const useBotFlow = ({ conversationId, isBotThread, }) => {
|
|
|
158
158
|
const resetDetail = await resetMutation.mutateAsync(conversationId);
|
|
159
159
|
await runStep(resetDetail.flowCurrentStep);
|
|
160
160
|
};
|
|
161
|
+
const restart = async () => {
|
|
162
|
+
if (isInActiveCsSession) {
|
|
163
|
+
setPendingCsAction({ type: "restart" });
|
|
164
|
+
return;
|
|
165
|
+
}
|
|
166
|
+
await performRestart();
|
|
167
|
+
};
|
|
161
168
|
const runMenuOption = async (item) => {
|
|
162
169
|
if (!activeStep)
|
|
163
170
|
return;
|
|
@@ -175,27 +182,32 @@ export const useBotFlow = ({ conversationId, isBotThread, }) => {
|
|
|
175
182
|
return;
|
|
176
183
|
}
|
|
177
184
|
if (isInActiveCsSession) {
|
|
178
|
-
|
|
185
|
+
setPendingCsAction({ type: "menu", item });
|
|
179
186
|
return;
|
|
180
187
|
}
|
|
181
188
|
await runMenuOption(item);
|
|
182
189
|
};
|
|
183
190
|
const confirmEndCsSession = async () => {
|
|
184
|
-
if (!
|
|
191
|
+
if (!pendingCsAction)
|
|
185
192
|
return;
|
|
186
|
-
const
|
|
193
|
+
const action = pendingCsAction;
|
|
187
194
|
try {
|
|
188
195
|
await closeSessionMutation.mutateAsync(conversationId);
|
|
189
|
-
|
|
190
|
-
|
|
196
|
+
setPendingCsAction(null);
|
|
197
|
+
if (action.type === "restart") {
|
|
198
|
+
await performRestart();
|
|
199
|
+
}
|
|
200
|
+
else {
|
|
201
|
+
await runMenuOption(action.item);
|
|
202
|
+
}
|
|
191
203
|
}
|
|
192
204
|
catch (_a) {
|
|
193
205
|
toastMessage.error(t("thread_detail.bot.cs_confirm.close_failed"));
|
|
194
|
-
|
|
206
|
+
setPendingCsAction(null);
|
|
195
207
|
}
|
|
196
208
|
};
|
|
197
209
|
const cancelMenuOption = () => {
|
|
198
|
-
|
|
210
|
+
setPendingCsAction(null);
|
|
199
211
|
};
|
|
200
212
|
return {
|
|
201
213
|
status,
|
|
@@ -207,7 +219,7 @@ export const useBotFlow = ({ conversationId, isBotThread, }) => {
|
|
|
207
219
|
currentButtonsBlock,
|
|
208
220
|
menuItems,
|
|
209
221
|
isInCsSession: isInActiveCsSession,
|
|
210
|
-
|
|
222
|
+
isCsConfirmOpen: !!pendingCsAction,
|
|
211
223
|
start,
|
|
212
224
|
selectButton,
|
|
213
225
|
restart,
|
|
@@ -77,6 +77,6 @@ const DChatConversationDetail = (_a) => {
|
|
|
77
77
|
!botFlow.flowIsEnd &&
|
|
78
78
|
botFlow.shouldShowButtons &&
|
|
79
79
|
botFlow.currentButtonsBlock ? (_jsx(BotButtonMessage, { buttons: botFlow.currentButtonsBlock.data.buttons, disabled: botFlow.isProcessing, onSelect: botFlow.selectButton, onRestart: botFlow.restart })) : null;
|
|
80
|
-
return (_jsxs("div", { "data-testid": "conversation-detail-root", className: clsx("relative flex h-full w-full flex-col overflow-hidden bg-white", className), children: [_jsx(ConversationDetailHeader, { conversation: conversation, onBack: handleBack, onProfileClick: openProfile }), _jsx(PinnedMessageBar, {}), _jsx("div", { className: "flex min-h-0 flex-1 flex-col", children: children !== null && children !== void 0 ? children : _jsx(ConversationMessageList, { bottomSlot: botButtonsSlot }) }), footer, isBotThread && (_jsxs(_Fragment, { children: [_jsx(BotMenuSheet, { open: isMenuOpen, items: botFlow.menuItems, disabled: botFlow.isProcessing, onClose: closeMenu, onSelect: botFlow.selectMenuOption }), _jsx(CsSessionConfirmModal, { open:
|
|
80
|
+
return (_jsxs("div", { "data-testid": "conversation-detail-root", className: clsx("relative flex h-full w-full flex-col overflow-hidden bg-white", className), children: [_jsx(ConversationDetailHeader, { conversation: conversation, onBack: handleBack, onProfileClick: openProfile }), _jsx(PinnedMessageBar, {}), _jsx("div", { className: "flex min-h-0 flex-1 flex-col", children: children !== null && children !== void 0 ? children : _jsx(ConversationMessageList, { bottomSlot: botButtonsSlot }) }), footer, isBotThread && (_jsxs(_Fragment, { children: [_jsx(BotMenuSheet, { open: isMenuOpen, items: botFlow.menuItems, disabled: botFlow.isProcessing, onClose: closeMenu, onSelect: botFlow.selectMenuOption }), _jsx(CsSessionConfirmModal, { open: botFlow.isCsConfirmOpen, loading: botFlow.isProcessing, onCancel: botFlow.cancelMenuOption, onConfirm: botFlow.confirmEndCsSession })] })), _jsx(ThreadProfilePanel, { open: isProfileOpen, conversation: conversation, onClose: closeProfile, onSelectResource: setResourceTab }), _jsx(MediaResourcePanel, { open: resourceTab !== null, initialTab: resourceTab !== null && resourceTab !== void 0 ? resourceTab : MediaResourceTabKey.Image, onClose: () => setResourceTab(null) })] }));
|
|
81
81
|
};
|
|
82
82
|
export default DChatConversationDetail;
|