GOWA - WhatsApp REST API with support for UI, Multi Account, Webhooks, and MCP, and Chatwoot. Built with Golang for efficient memory use.
Go botgogolanggolang-whatsappgolang-whatsapp-apirestrest-apiwhatsappwhatsapp-apiwhatsapp-api-gowhatsapp-multi-devicewhatsapp-web-multi-device
fix: store media metadata for sent messages in chat storage
Aldino Kemal8eb40a51ef05
diff --git a/src/domains/chatstorage/interfaces.go b/src/domains/chatstorage/interfaces.goindex 8eda0963..e891edf7 100644--- a/src/domains/chatstorage/interfaces.go+++ b/src/domains/chatstorage/interfaces.go@@ -4,6 +4,7 @@ import ("context""time"+ "go.mau.fi/whatsmeow/proto/waE2E""go.mau.fi/whatsmeow/types""go.mau.fi/whatsmeow/types/events")@@ -26,7 +27,7 @@ type IChatStorageRepository interface {SearchMessages(deviceID, chatJID, searchText string, limit int) ([]*Message, error) // Database-level search with device isolationDeleteMessage(id, chatJID string) errorDeleteMessageByDevice(deviceID, id, chatJID string) error- StoreSentMessageWithContext(ctx context.Context, messageID string, senderJID string, recipientJID string, content string, timestamp time.Time) error+ StoreSentMessageWithContext(ctx context.Context, messageID string, senderJID string, recipientJID string, content string, timestamp time.Time, msg *waE2E.Message) error// StatisticsGetChatMessageCount(chatJID string) (int64, error)diff --git a/src/infrastructure/chatstorage/device_repository.go b/src/infrastructure/chatstorage/device_repository.goindex 733fe08e..1a58dd05 100644--- a/src/infrastructure/chatstorage/device_repository.go+++ b/src/infrastructure/chatstorage/device_repository.go@@ -5,6 +5,7 @@ import ("time"domainChatStorage "github.com/aldinokemal/go-whatsapp-web-multidevice/domains/chatstorage"+ "go.mau.fi/whatsmeow/proto/waE2E""go.mau.fi/whatsmeow/types""go.mau.fi/whatsmeow/types/events")@@ -100,8 +101,8 @@ func (r *DeviceRepository) DeleteMessageByDevice(deviceID, id, chatJID string) ereturn r.base.DeleteMessageByDevice(deviceID, id, chatJID)}-func (r *DeviceRepository) StoreSentMessageWithContext(ctx context.Context, messageID string, senderJID string, recipientJID string, content string, timestamp time.Time) error {- return r.base.StoreSentMessageWithContext(ctx, messageID, senderJID, recipientJID, content, timestamp)+func (r *DeviceRepository) StoreSentMessageWithContext(ctx context.Context, messageID string, senderJID string, recipientJID string, content string, timestamp time.Time, msg *waE2E.Message) error {+ return r.base.StoreSentMessageWithContext(ctx, messageID, senderJID, recipientJID, content, timestamp, msg)}func (r *DeviceRepository) GetChatMessageCount(chatJID string) (int64, error) {diff --git a/src/infrastructure/chatstorage/sqlite_repository.go b/src/infrastructure/chatstorage/sqlite_repository.goindex 8722eac0..1d925550 100644--- a/src/infrastructure/chatstorage/sqlite_repository.go+++ b/src/infrastructure/chatstorage/sqlite_repository.go@@ -11,6 +11,7 @@ import ("github.com/aldinokemal/go-whatsapp-web-multidevice/infrastructure/whatsapp""github.com/aldinokemal/go-whatsapp-web-multidevice/pkg/utils""github.com/sirupsen/logrus"+ "go.mau.fi/whatsmeow/proto/waE2E""go.mau.fi/whatsmeow/types""go.mau.fi/whatsmeow/types/events")@@ -915,7 +916,7 @@ func (r *SQLiteRepository) TruncateAllDataWithLogging(logPrefix string) error {}// StoreSentMessageWithContext stores a message that was sent by the user with context cancellation support-func (r *SQLiteRepository) StoreSentMessageWithContext(ctx context.Context, messageID string, senderJID string, recipientJID string, content string, timestamp time.Time) error {+func (r *SQLiteRepository) StoreSentMessageWithContext(ctx context.Context, messageID string, senderJID string, recipientJID string, content string, timestamp time.Time, msg *waE2E.Message) error {// Check if context is already cancelled before startingselect {case <-ctx.Done():@@ -986,15 +987,30 @@ func (r *SQLiteRepository) StoreSentMessageWithContext(ctx context.Context, messdefault:}+ // Extract media info from the protobuf message if available+ var mediaType, filename, mediaURL string+ var mediaKey, fileSHA256, fileEncSHA256 []byte+ var fileLength uint64+ if msg != nil {+ mediaType, filename, mediaURL, mediaKey, fileSHA256, fileEncSHA256, fileLength = utils.ExtractMediaInfo(msg)+ }+// Store the sent messagemessage := &domainChatStorage.Message{- ID: messageID,- ChatJID: chatJID,- DeviceID: deviceID,- Sender: senderJID,- Content: content,- Timestamp: timestamp,- IsFromMe: true,+ ID: messageID,+ ChatJID: chatJID,+ DeviceID: deviceID,+ Sender: senderJID,+ Content: content,+ Timestamp: timestamp,+ IsFromMe: true,+ MediaType: mediaType,+ Filename: filename,+ URL: mediaURL,+ MediaKey: mediaKey,+ FileSHA256: fileSHA256,+ FileEncSHA256: fileEncSHA256,+ FileLength: fileLength,}return r.StoreMessage(message)diff --git a/src/infrastructure/whatsapp/auto_reply.go b/src/infrastructure/whatsapp/auto_reply.goindex e7edc6ab..9f8da08e 100644--- a/src/infrastructure/whatsapp/auto_reply.go+++ b/src/infrastructure/whatsapp/auto_reply.go@@ -95,6 +95,7 @@ func handleAutoReply(ctx context.Context, evt *events.Message, chatStorageRepo drecipientJID.String(), // Recipient JIDconfig.WhatsappAutoReplyMessage, // Auto-reply contentresponse.Timestamp, // Timestamp from response+ nil, // text-only message, no media); err != nil {// Log storage error but don't fail the auto-replylog.Errorf("Failed to store auto-reply message in chat storage: %v", err)diff --git a/src/infrastructure/whatsapp/chatstorage_wrapper.go b/src/infrastructure/whatsapp/chatstorage_wrapper.goindex a09662cd..bf169fc2 100644--- a/src/infrastructure/whatsapp/chatstorage_wrapper.go+++ b/src/infrastructure/whatsapp/chatstorage_wrapper.go@@ -5,6 +5,7 @@ import ("time"domainChatStorage "github.com/aldinokemal/go-whatsapp-web-multidevice/domains/chatstorage"+ "go.mau.fi/whatsmeow/proto/waE2E""go.mau.fi/whatsmeow/types""go.mau.fi/whatsmeow/types/events")@@ -102,8 +103,8 @@ func (r *deviceChatStorage) DeleteMessageByDevice(deviceID, id, chatJID string)return r.base.DeleteMessageByDevice(deviceID, id, chatJID)}-func (r *deviceChatStorage) StoreSentMessageWithContext(ctx context.Context, messageID string, senderJID string, recipientJID string, content string, timestamp time.Time) error {- return r.base.StoreSentMessageWithContext(ctx, messageID, senderJID, recipientJID, content, timestamp)+func (r *deviceChatStorage) StoreSentMessageWithContext(ctx context.Context, messageID string, senderJID string, recipientJID string, content string, timestamp time.Time, msg *waE2E.Message) error {+ return r.base.StoreSentMessageWithContext(ctx, messageID, senderJID, recipientJID, content, timestamp, msg)}func (r *deviceChatStorage) GetChatMessageCount(chatJID string) (int64, error) {diff --git a/src/usecase/send.go b/src/usecase/send.goindex cb0d4e56..8dfc058b 100644--- a/src/usecase/send.go+++ b/src/usecase/send.go@@ -69,7 +69,7 @@ func (service serviceSend) wrapSendMessage(ctx context.Context, client *whatsmeostoreCtx, cancel := context.WithTimeout(context.Background(), 2*time.Second)defer cancel()- if err := service.chatStorageRepo.StoreSentMessageWithContext(storeCtx, ts.ID, senderJID, recipient.String(), content, ts.Timestamp); err != nil {+ if err := service.chatStorageRepo.StoreSentMessageWithContext(storeCtx, ts.ID, senderJID, recipient.String(), content, ts.Timestamp, msg); err != nil {if errors.Is(err, context.DeadlineExceeded) {logrus.Warn("Timeout storing sent message")} else {