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,25 +91,27 @@ 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 != "" {
msg := buildDeliveryMessage(content) channel, chatID := splitChannelChatID(payload.ChatID)
if msg != nil { if channel != "" && chatID != "" {
channel, chatID := splitChannelChatID(payload.ChatID) msg := buildDeliveryMessage(content)
extra := map[string]any{ if msg != nil {
"member_id": payload.MemberID, extra := map[string]any{
"execution_id": payload.ExecutionID, "member_id": payload.MemberID,
} "execution_id": payload.ExecutionID,
for k, v := range payload.Extra { }
extra[k] = v for k, v := range payload.Extra {
} extra[k] = v
metadata := &MessageMetadata{ }
Channel: channel, metadata := &MessageMetadata{
ChatID: chatID, Channel: channel,
Extra: extra, ChatID: chatID,
} Extra: extra,
if err := reply(ctx, msg, metadata); err != nil { }
log.Error("delivery handler: integration reply failed execution=%s: %v", payload.ExecutionID, err) if err := reply(ctx, msg, metadata); err != nil {
log.Error("delivery handler: integration reply failed channel=%s execution=%s: %v", channel, payload.ExecutionID, err)
}
} }
} }
} }