fix(im): ingest DingTalk file/image messages into knowledge base (#1771)
The DingTalk adapter only ever classified incoming messages as text and did not implement FileDownloader, so files sent to the bot were never saved to the channel's configured knowledge base — unlike WeCom, which worked. Users saw the file received and read, but never stored. Parse file/picture msgtypes in both the webhook and stream paths (set MessageTypeFile/Image, FileName, FileKey=downloadCode, robot_code), and implement DownloadFile: exchange the downloadCode for a temporary URL via robot/messageFiles/download, then fetch it. robotCode comes from the callback (webhook) or the app client ID (stream). Pictures get a MsgID-derived name, mirroring the WeCom adapter.
This commit is contained in:
@@ -2,7 +2,6 @@ package dingtalk
|
||||
|
||||
import (
|
||||
"context"
|
||||
"strings"
|
||||
|
||||
"github.com/open-dingtalk/dingtalk-stream-sdk-go/chatbot"
|
||||
dtsdk "github.com/open-dingtalk/dingtalk-stream-sdk-go/client"
|
||||
@@ -59,33 +58,7 @@ func (c *LongConnClient) Close() {
|
||||
}
|
||||
|
||||
func (c *LongConnClient) onChatBotMessage(ctx context.Context, data *chatbot.BotCallbackDataModel) ([]byte, error) {
|
||||
chatType := im.ChatTypeDirect
|
||||
chatID := ""
|
||||
if data.ConversationType == dingtalkConvTypeGroup {
|
||||
chatType = im.ChatTypeGroup
|
||||
chatID = data.ConversationId
|
||||
}
|
||||
|
||||
userID := data.SenderStaffId
|
||||
if userID == "" {
|
||||
userID = data.SenderId
|
||||
}
|
||||
|
||||
content := strings.TrimSpace(data.Text.Content)
|
||||
|
||||
incoming := &im.IncomingMessage{
|
||||
Platform: im.PlatformDingtalk,
|
||||
UserID: userID,
|
||||
UserName: data.SenderNick,
|
||||
ChatID: chatID,
|
||||
ChatType: chatType,
|
||||
MessageID: data.MsgId,
|
||||
MessageType: im.MessageTypeText,
|
||||
Content: content,
|
||||
Extra: map[string]string{
|
||||
"session_webhook": data.SessionWebhook,
|
||||
},
|
||||
}
|
||||
incoming := streamToIncoming(data, c.clientID)
|
||||
|
||||
if err := c.handler(ctx, incoming); err != nil {
|
||||
logger.Errorf(ctx, "[DingTalk] Handle message error: %v", err)
|
||||
|
||||
Reference in New Issue
Block a user