|
92 | 92 | let truncateMsgId = ""; |
93 | 93 | let indication = ""; |
94 | 94 | let mode = ''; |
| 95 | + let notificationText = ''; |
95 | 96 |
|
96 | 97 | /** @type {number} */ |
97 | 98 | let messageInputTimeout; |
|
158 | 159 | let disableSpeech = false; |
159 | 160 | let isLoading = false; |
160 | 161 | let isCreatingNewConv = false; |
| 162 | + let isDisplayNotification = false; |
161 | 163 | |
162 | 164 | $: { |
163 | 165 | const editor = lastBotMsg?.rich_content?.editor || ''; |
|
184 | 186 | signalr.onMessageReceivedFromClient = onMessageReceivedFromClient; |
185 | 187 | signalr.onMessageReceivedFromCsr = onMessageReceivedFromCsr; |
186 | 188 | signalr.onMessageReceivedFromAssistant = onMessageReceivedFromAssistant; |
| 189 | + signalr.onNotificationGenerated = onNotificationGenerated; |
187 | 190 | signalr.onConversationContentLogGenerated = onConversationContentLogGenerated; |
188 | 191 | signalr.onConversationStateLogGenerated = onConversationStateLogGenerated; |
189 | 192 | signalr.onStateChangeGenerated = onStateChangeGenerated; |
|
255 | 258 | } |
256 | 259 |
|
257 | 260 | /** @param {import('$conversationTypes').ChatResponseModel} message */ |
258 | | - function sendReceivedMessage(message) { |
| 261 | + function sendReceivedNotification(message) { |
259 | 262 | if (isFrame) { |
260 | | - window.parent.postMessage({ action: ChatAction.ReceiveMsg, data: message }, "*"); |
| 263 | + window.parent.postMessage({ action: ChatAction.ReceiveNotification, data: message }, "*"); |
261 | 264 | } |
262 | 265 | } |
263 | 266 |
|
|
431 | 434 | ...message, |
432 | 435 | is_chat_message: true |
433 | 436 | }); |
434 | | - sendReceivedMessage(message); |
435 | 437 | refresh(); |
436 | 438 | } |
437 | 439 |
|
| 440 | + /** @param {import('$conversationTypes').ChatResponseModel} message */ |
| 441 | + function onNotificationGenerated(message) { |
| 442 | + notificationText = message?.rich_content?.message?.text || message.text || ''; |
| 443 | + isDisplayNotification = true; |
| 444 | + setTimeout(() => { |
| 445 | + isDisplayNotification = false; |
| 446 | + notificationText = ''; |
| 447 | + }, notificationText?.length > 200 ? 8000 : 3000); |
| 448 | +
|
| 449 | + sendReceivedNotification(message); |
| 450 | + } |
| 451 | +
|
438 | 452 | /** @param {import('$conversationTypes').ConversationContentLogModel} log */ |
439 | 453 | function onConversationContentLogGenerated(log) { |
440 | 454 | if (!isLoadPersistLog) return; |
|
1094 | 1108 | }; |
1095 | 1109 | sendChatMessage(text, data); |
1096 | 1110 | } |
| 1111 | +
|
| 1112 | + function toggleNotificationModal() { |
| 1113 | + isDisplayNotification = !isDisplayNotification; |
| 1114 | + if (!isDisplayNotification) { |
| 1115 | + notificationText = ''; |
| 1116 | + } |
| 1117 | + } |
1097 | 1118 | </script> |
1098 | 1119 |
|
1099 | 1120 |
|
|
1103 | 1124 | <Loader size={35} /> |
1104 | 1125 | {/if} |
1105 | 1126 |
|
| 1127 | +<DialogModal |
| 1128 | + title={'Notification'} |
| 1129 | + size={'md'} |
| 1130 | + isOpen={isDisplayNotification} |
| 1131 | + closeable |
| 1132 | + toggleModal={() => toggleNotificationModal()} |
| 1133 | + confirmBtnText={''} |
| 1134 | + cancelBtnText={''} |
| 1135 | + close={() => toggleNotificationModal()} |
| 1136 | +> |
| 1137 | + <div slot='title-icon' class="color: text-warning"> |
| 1138 | + <i class="mdi mdi-bell-ring" /> |
| 1139 | + </div> |
| 1140 | + <div class="chat-notification"> |
| 1141 | + {notificationText} |
| 1142 | + </div> |
| 1143 | +</DialogModal> |
| 1144 | +
|
| 1145 | +
|
1106 | 1146 | <DialogModal |
1107 | 1147 | title={'Edit message'} |
1108 | 1148 | size={'md'} |
|
0 commit comments