Skip to content

Commit 11c7591

Browse files
authored
Fix payload handling for msg_id in QQ API (#6604)
Remove msg_id from payload to prevent errors with proactive tool-call path and avoid permission issues. Co-authored-by: Naer <88199249+V-YOP@users.noreply.github.com>
1 parent d7f8af5 commit 11c7591

1 file changed

Lines changed: 3 additions & 4 deletions

File tree

astrbot/core/platform/sources/qqofficial/qqofficial_platform_adapter.py

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -238,6 +238,9 @@ async def _send_by_session_common(
238238
)
239239

240240
elif session.message_type == MessageType.FRIEND_MESSAGE:
241+
# 参考 https://bot.q.qq.com/wiki/develop/pythonsdk/api/message/post_message.html
242+
# msg_id 缺失时认为是主动推送,而似乎至少在私聊上主动推送是没有被限制的,这里直接移除 msg_id 可以避免越权或 msg_id 不可用的bug
243+
payload.pop("msg_id", None)
241244
payload["msg_seq"] = random.randint(1, 10000)
242245
if image_base64:
243246
media = await QQOfficialMessageEvent.upload_group_and_c2c_image(
@@ -268,9 +271,6 @@ async def _send_by_session_common(
268271
if media:
269272
payload["media"] = media
270273
payload["msg_type"] = 7
271-
# QQ API rejects msg_id for media (video/file) messages sent
272-
# via the proactive tool-call path; remove it to avoid 越权 error.
273-
payload.pop("msg_id", None)
274274
if file_source:
275275
media = await QQOfficialMessageEvent.upload_group_and_c2c_media(
276276
send_helper, # type: ignore
@@ -282,7 +282,6 @@ async def _send_by_session_common(
282282
if media:
283283
payload["media"] = media
284284
payload["msg_type"] = 7
285-
payload.pop("msg_id", None)
286285

287286
ret = await QQOfficialMessageEvent.post_c2c_message(
288287
send_helper, # type: ignore

0 commit comments

Comments
 (0)