feat: add msglib receive adapter

This commit is contained in:
zhaoyilun
2026-07-10 08:59:36 +08:00
parent 44d27879f6
commit 0820717767
8 changed files with 295 additions and 13 deletions

View File

@@ -131,8 +131,8 @@ func receiveMessagesResultToMap(result isphere.ReceiveMessagesResult, started ti
"subject": message.Subject,
"receipt_id": message.ReceiptID,
"read": message.Read,
"source": "local_readonly",
"raw_ref": "packetlog_message",
"source": receiveMessageSource(message),
"raw_ref": receiveMessageRawRef(message),
})
}
return map[string]any{
@@ -244,6 +244,18 @@ func contractConversationType(value string) string {
}
func receiveMessageAttachments(message isphere.Message) []map[string]any {
if len(message.Attachments) > 0 {
attachments := make([]map[string]any, 0, len(message.Attachments))
for _, attachment := range message.Attachments {
attachments = append(attachments, map[string]any{
"file_id": attachment.FileID,
"file_name": attachment.FileName,
"size_bytes": attachment.SizeBytes,
"download_ref": nullableString(attachment.DownloadRef),
})
}
return attachments
}
files := isphere.ListFilesFromMessages([]isphere.Message{message}, isphere.ListFilesQuery{})
attachments := make([]map[string]any, 0, len(files.Files))
for _, file := range files.Files {
@@ -257,6 +269,20 @@ func receiveMessageAttachments(message isphere.Message) []map[string]any {
return attachments
}
func receiveMessageSource(message isphere.Message) string {
if strings.TrimSpace(message.Source) != "" {
return message.Source
}
return "local_readonly"
}
func receiveMessageRawRef(message isphere.Message) string {
if strings.TrimSpace(message.RawRef) != "" {
return message.RawRef
}
return "packetlog_message"
}
func receiveMessageContentType(message isphere.Message, attachments []map[string]any) string {
if len(attachments) > 0 {
return "file"