fix(feishu): route thread replies via Lark reply endpoint

Bot responses to messages inside Lark topic threads were dropped
outside the thread because outbound Send always used the new-message
endpoint. This change:

- Adds LarkClient.ReplyMessage() that POSTs to
  /open-apis/im/v1/messages/{id}/reply with reply_in_thread=true
- Parses thread_id from im.message.receive_v1 events (distinct from
  root_id which fires on any quote reply) and stamps
  feishu_reply_target_id into the message metadata
- Propagates the key through cmd/gateway_consumer_normal.go and the
  new package-level routingMetaKeys var in internal/channels/events.go
  so block replies and retry notifications also land in thread
- Routes sendText, sendMarkdownCard, sendImage, sendFile, and
  sendMediaAttachment via a new deliverMessage helper that falls back
  to SendMessage with a warning log on reply endpoint errors (e.g.
  thread root deleted)
- Adds 10 unit tests covering routing, fallback, content
  double-encoding, and the thread_id gate that prevents plain quote
  replies from being silently promoted to threads

Closes #818
This commit is contained in:
viettranx committed 2026-04-11 21:22:23 +07:00
1 parent e8e00d1884
commit bf272d8dbf
13 files changed
+504 -35

No files matched your search

+2
View File
@@ -16,6 +16,7 @@ func (c *Channel) parseMessageEvent(event *MessageEvent) *messageContext {
contentType := msg.MessageType
rootID := msg.RootID
parentID := msg.ParentID
threadID := msg.ThreadID
senderID := ""
if sender != nil {
@@ -58,6 +59,7 @@ func (c *Channel) parseMessageEvent(event *MessageEvent) *messageContext {
MentionedBot: mentionedBot,
RootID: rootID,
ParentID: parentID,
ThreadID: threadID,
Mentions: mentions,
}
}