From 63dcda8609ed82a156e12aa13aa9d5d7732ee964 Mon Sep 17 00:00:00 2001
From: MAX-TAB <60381043+MAX-TAB@users.noreply.github.com>
Date: Fri, 22 Aug 2025 01:39:16 +0800
Subject: [PATCH] feat: Send Quick Reply Before Message Generation (#4407)
* feat: Send Quick Reply Before Message Generation
* fix: Use correct event and check for dry runs on before-generation
* Replace icon
* Skip for events in groups outside of group wrapper
* Compatibility with API and slash commands
---------
Co-authored-by: Cohee <18619528+Cohee1207@users.noreply.github.com>
---
.../extensions/quick-reply/api/QuickReplyApi.js | 6 ++++++
.../extensions/quick-reply/html/qrEditor.html | 4 ++++
public/scripts/extensions/quick-reply/index.js | 14 ++++++++++++++
.../quick-reply/src/AutoExecuteHandler.js | 5 +++++
.../extensions/quick-reply/src/QuickReply.js | 9 +++++++++
.../quick-reply/src/SlashCommandHandler.js | 4 ++++
6 files changed, 42 insertions(+)
diff --git a/public/scripts/extensions/quick-reply/api/QuickReplyApi.js b/public/scripts/extensions/quick-reply/api/QuickReplyApi.js
index 6565ff3bb..926003634 100644
--- a/public/scripts/extensions/quick-reply/api/QuickReplyApi.js
+++ b/public/scripts/extensions/quick-reply/api/QuickReplyApi.js
@@ -202,6 +202,7 @@ export class QuickReplyApi {
* @param {boolean} [props.executeOnChatChange] whether to execute the quick reply when a new chat is loaded
* @param {boolean} [props.executeOnGroupMemberDraft] whether to execute the quick reply when a group member is selected
* @param {boolean} [props.executeOnNewChat] whether to execute the quick reply when a new chat is created
+ * @param {boolean} [props.executeBeforeGeneration] whether to execute the quick reply before message generation
* @param {string} [props.automationId] when not empty, the quick reply will be executed when the WI with the given automation ID is activated
* @returns {QuickReply} the new quick reply
*/
@@ -217,6 +218,7 @@ export class QuickReplyApi {
executeOnChatChange,
executeOnGroupMemberDraft,
executeOnNewChat,
+ executeBeforeGeneration,
automationId,
} = {}) {
const set = this.getSetByName(setName);
@@ -236,6 +238,7 @@ export class QuickReplyApi {
qr.executeOnChatChange = executeOnChatChange ?? false;
qr.executeOnGroupMemberDraft = executeOnGroupMemberDraft ?? false;
qr.executeOnNewChat = executeOnNewChat ?? false;
+ qr.executeBeforeGeneration = executeBeforeGeneration ?? false;
qr.automationId = automationId ?? '';
qr.onUpdate();
return qr;
@@ -259,6 +262,7 @@ export class QuickReplyApi {
* @param {boolean} [props.executeOnChatChange] whether to execute the quick reply when a new chat is loaded
* @param {boolean} [props.executeOnGroupMemberDraft] whether to execute the quick reply when a group member is selected
* @param {boolean} [props.executeOnNewChat] whether to execute the quick reply when a new chat is created
+ * @param {boolean} [props.executeBeforeGeneration] whether to execute the quick reply before message generation
* @param {string} [props.automationId] when not empty, the quick reply will be executed when the WI with the given automation ID is activated
* @returns {QuickReply} the altered quick reply
*/
@@ -275,6 +279,7 @@ export class QuickReplyApi {
executeOnChatChange,
executeOnGroupMemberDraft,
executeOnNewChat,
+ executeBeforeGeneration,
automationId,
} = {}) {
const qr = this.getQrByLabel(setName, label);
@@ -293,6 +298,7 @@ export class QuickReplyApi {
qr.executeOnChatChange = executeOnChatChange ?? qr.executeOnChatChange;
qr.executeOnGroupMemberDraft = executeOnGroupMemberDraft ?? qr.executeOnGroupMemberDraft;
qr.executeOnNewChat = executeOnNewChat ?? qr.executeOnNewChat;
+ qr.executeBeforeGeneration = executeBeforeGeneration ?? qr.executeBeforeGeneration;
qr.automationId = automationId ?? qr.automationId;
qr.onUpdate();
return qr;
diff --git a/public/scripts/extensions/quick-reply/html/qrEditor.html b/public/scripts/extensions/quick-reply/html/qrEditor.html
index e81a11ba2..6fc47b573 100644
--- a/public/scripts/extensions/quick-reply/html/qrEditor.html
+++ b/public/scripts/extensions/quick-reply/html/qrEditor.html
@@ -116,6 +116,10 @@
Execute on group member draft
+