Refactor delivery event handling to improve integration channel checks

- Update the delivery handling logic to only push messages to integration channels when the task originates from one, ensuring more accurate message routing.
- Enhance the error logging to include channel information for better debugging during integration reply failures.
- Streamline the conditions for message delivery to improve code clarity and maintainability.
This commit is contained in:
Max 2026-03-02 09:23:36 +08:00
parent 3eb43a59ab
commit a0307d4d6d

View file

@ -91,11 +91,12 @@ func (h *robotHandler) handleDelivery(ctx context.Context, ev *eventtypes.Event,
} }
} }
// Push delivery to integration channels (Telegram, etc.) via ReplyFunc // Push delivery to integration channels only when the task originated from one
if reply := getReplyFunc(); reply != nil { if reply := getReplyFunc(); reply != nil && payload.ChatID != "" {
channel, chatID := splitChannelChatID(payload.ChatID)
if channel != "" && chatID != "" {
msg := buildDeliveryMessage(content) msg := buildDeliveryMessage(content)
if msg != nil { if msg != nil {
channel, chatID := splitChannelChatID(payload.ChatID)
extra := map[string]any{ extra := map[string]any{
"member_id": payload.MemberID, "member_id": payload.MemberID,
"execution_id": payload.ExecutionID, "execution_id": payload.ExecutionID,
@ -109,7 +110,8 @@ func (h *robotHandler) handleDelivery(ctx context.Context, ev *eventtypes.Event,
Extra: extra, Extra: extra,
} }
if err := reply(ctx, msg, metadata); err != nil { if err := reply(ctx, msg, metadata); err != nil {
log.Error("delivery handler: integration reply failed execution=%s: %v", payload.ExecutionID, err) log.Error("delivery handler: integration reply failed channel=%s execution=%s: %v", channel, payload.ExecutionID, err)
}
} }
} }
} }