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
feat: add chat archive and unarchive functionality
Aldino Kemal935262c2ffc9
diff --git a/docs/openapi.yaml b/docs/openapi.yamlindex 23f5a584..0e470a77 100644--- a/docs/openapi.yaml+++ b/docs/openapi.yaml@@ -1,7 +1,7 @@openapi: "3.0.0"info:title: WhatsApp API MultiDevice- version: 8.0.0+ version: 8.1.0description: |This API is used for sending whatsapp via API.@@ -2178,6 +2178,66 @@ paths:schema:$ref: '#/components/schemas/ErrorInternalServer'+ /chat/{chat_jid}/archive:+ post:+ operationId: archiveChat+ tags:+ - chat+ summary: Archive or unarchive a chat+ description: Archive or unarchive a chat conversation. Archived chats are hidden from the main chat list.+ parameters:+ - $ref: '#/components/parameters/DeviceIdHeader'+ - in: path+ name: chat_jid+ schema:+ type: string+ required: true+ description: Chat JID (e.g., [email protected] for individual or [email protected] for group)+ example: '[email protected]'+ requestBody:+ content:+ application/json:+ schema:+ type: object+ properties:+ archived:+ type: boolean+ example: true+ description: Whether to archive (true) or unarchive (false) the chat+ required:+ - archived+ responses:+ '200':+ description: OK+ content:+ application/json:+ schema:+ $ref: '#/components/schemas/ArchiveChatResponse'+ '400':+ description: Bad Request+ content:+ application/json:+ schema:+ $ref: '#/components/schemas/ErrorBadRequest'+ '401':+ description: Unauthorized+ content:+ application/json:+ schema:+ $ref: '#/components/schemas/ErrorUnauthorized'+ '404':+ description: Chat Not Found+ content:+ application/json:+ schema:+ $ref: '#/components/schemas/ErrorNotFound'+ '500':+ description: Internal Server Error+ content:+ application/json:+ schema:+ $ref: '#/components/schemas/ErrorInternalServer'+/group/info:get:operationId: groupInfo@@ -4157,6 +4217,33 @@ components:timer_seconds:type: integerexample: 86400+ ArchiveChatResponse:+ type: object+ properties:+ status:+ type: integer+ example: 200+ code:+ type: string+ example: SUCCESS+ message:+ type: string+ example: Chat archived successfully+ results:+ type: object+ properties:+ status:+ type: string+ example: success+ message:+ type: string+ example: Chat archived successfully+ chat_jid:+ type: string+ example: '[email protected]'+ archived:+ type: boolean+ example: trueGroupInfoResponse:type: objectproperties:diff --git a/readme.md b/readme.mdindex b58a431c..e563d393 100644--- a/readme.md+++ b/readme.md@@ -267,6 +267,7 @@ The WhatsApp MCP server provides comprehensive tools for AI agents to interact w- `whatsapp_list_chats` - Get recent chats with pagination and search filters- `whatsapp_get_chat_messages` - Fetch messages from specific chats with time/media filtering- `whatsapp_download_message_media` - Download images/videos from messages+- `whatsapp_archive_chat` - Archive or unarchive a chat conversation##### **π₯ Group Management**@@ -511,6 +512,7 @@ You can fork or edit this source code !| β | Get Chat Messages | GET | /chat/:chat_jid/messages || β | Label Chat | POST | /chat/:chat_jid/label || β | Pin Chat | POST | /chat/:chat_jid/pin |+| β | Archive Chat | POST | /chat/:chat_jid/archive || β | Set Disappearing Messages | POST | /chat/:chat_jid/disappearing |```txtdiff --git a/src/config/settings.go b/src/config/settings.goindex b04ce9b4..ee4730bd 100644--- a/src/config/settings.go+++ b/src/config/settings.go@@ -5,7 +5,7 @@ import ()var (- AppVersion = "v8.0.0"+ AppVersion = "v8.1.0"AppPort = "3000"AppHost = "0.0.0.0"AppDebug = falsediff --git a/src/domains/chat/chat.go b/src/domains/chat/chat.goindex 07fef28b..989c5981 100644--- a/src/domains/chat/chat.go+++ b/src/domains/chat/chat.go@@ -86,3 +86,16 @@ type SetDisappearingTimerResponse struct {ChatJID string `json:"chat_jid"`TimerSeconds uint32 `json:"timer_seconds"`}++// Archive Chat operations+type ArchiveChatRequest struct {+ ChatJID string `json:"chat_jid" uri:"chat_jid"`+ Archived bool `json:"archived"`+}++type ArchiveChatResponse struct {+ Status string `json:"status"`+ Message string `json:"message"`+ ChatJID string `json:"chat_jid"`+ Archived bool `json:"archived"`+}diff --git a/src/domains/chat/interfaces.go b/src/domains/chat/interfaces.goindex baf3b2ae..9f5f4e2d 100644--- a/src/domains/chat/interfaces.go+++ b/src/domains/chat/interfaces.go@@ -10,4 +10,5 @@ type IChatUsecase interface {GetChatMessages(ctx context.Context, request GetChatMessagesRequest) (response GetChatMessagesResponse, err error)PinChat(ctx context.Context, request PinChatRequest) (response PinChatResponse, err error)SetDisappearingTimer(ctx context.Context, request SetDisappearingTimerRequest) (response SetDisappearingTimerResponse, err error)+ ArchiveChat(ctx context.Context, request ArchiveChatRequest) (response ArchiveChatResponse, err error)}diff --git a/src/ui/mcp/query.go b/src/ui/mcp/query.goindex 95410a06..d6971c18 100644--- a/src/ui/mcp/query.go+++ b/src/ui/mcp/query.go@@ -33,6 +33,7 @@ func (h *QueryHandler) AddQueryTools(mcpServer *server.MCPServer) {mcpServer.AddTool(h.toolListChats(), h.handleListChats)mcpServer.AddTool(h.toolGetChatMessages(), h.handleGetChatMessages)mcpServer.AddTool(h.toolDownloadMedia(), h.handleDownloadMedia)+ mcpServer.AddTool(h.toolArchiveChat(), h.handleArchiveChat)}func (h *QueryHandler) toolListContacts() mcp.Tool {@@ -285,3 +286,57 @@ func toBool(value any) (bool, error) {return false, fmt.Errorf("unsupported boolean value type %T", value)}}++func (h *QueryHandler) toolArchiveChat() mcp.Tool {+ return mcp.NewTool(+ "whatsapp_archive_chat",+ mcp.WithDescription("Archive or unarchive a WhatsApp chat. Archived chats are hidden from the main chat list."),+ mcp.WithTitleAnnotation("Archive/Unarchive Chat"),+ mcp.WithReadOnlyHintAnnotation(false),+ mcp.WithDestructiveHintAnnotation(false),+ mcp.WithIdempotentHintAnnotation(true),+ mcp.WithString("chat_jid",+ mcp.Description("The chat JID (e.g., [email protected] or [email protected])."),+ mcp.Required(),+ ),+ mcp.WithBoolean("archived",+ mcp.Description("Set to true to archive the chat, false to unarchive it."),+ mcp.Required(),+ ),+ )+}++func (h *QueryHandler) handleArchiveChat(ctx context.Context, request mcp.CallToolRequest) (*mcp.CallToolResult, error) {+ chatJID, err := request.RequireString("chat_jid")+ if err != nil {+ return nil, err+ }++ args := request.GetArguments()+ if args == nil {+ return nil, fmt.Errorf("missing required argument: archived")+ }++ archivedValue, ok := args["archived"]+ if !ok {+ return nil, fmt.Errorf("missing required argument: archived")+ }++ archived, err := toBool(archivedValue)+ if err != nil {+ return nil, err+ }++ req := domainChat.ArchiveChatRequest{+ ChatJID: chatJID,+ Archived: archived,+ }++ resp, err := h.chatService.ArchiveChat(ctx, req)+ if err != nil {+ return nil, err+ }++ fallback := resp.Message+ return mcp.NewToolResultStructured(resp, fallback), nil+}diff --git a/src/ui/rest/chat.go b/src/ui/rest/chat.goindex 3c415b95..1bc32baa 100644--- a/src/ui/rest/chat.go+++ b/src/ui/rest/chat.go@@ -19,6 +19,7 @@ func InitRestChat(app fiber.Router, service domainChat.IChatUsecase) Chat {app.Get("/chat/:chat_jid/messages", rest.GetChatMessages)app.Post("/chat/:chat_jid/pin", rest.PinChat)app.Post("/chat/:chat_jid/disappearing", rest.SetDisappearingTimer)+ app.Post("/chat/:chat_jid/archive", rest.ArchiveChat)return rest}@@ -133,3 +134,30 @@ func (controller *Chat) SetDisappearingTimer(c *fiber.Ctx) error {Results: response,})}++func (controller *Chat) ArchiveChat(c *fiber.Ctx) error {+ var request domainChat.ArchiveChatRequest++ // Parse path parameter+ request.ChatJID = c.Params("chat_jid")++ // Parse JSON body+ if err := c.BodyParser(&request); err != nil {+ return c.Status(400).JSON(utils.ResponseData{+ Status: 400,+ Code: "BAD_REQUEST",+ Message: "Invalid request body",+ Results: nil,+ })+ }++ response, err := controller.Service.ArchiveChat(whatsapp.ContextWithDevice(c.UserContext(), getDeviceFromCtx(c)), request)+ utils.PanicIfNeeded(err)++ return c.JSON(utils.ResponseData{+ Status: 200,+ Code: "SUCCESS",+ Message: response.Message,+ Results: response,+ })+}diff --git a/src/usecase/chat.go b/src/usecase/chat.goindex defc418c..1234da48 100644--- a/src/usecase/chat.go+++ b/src/usecase/chat.go@@ -311,3 +311,50 @@ func (service serviceChat) SetDisappearingTimer(ctx context.Context, request domreturn response, nil}++func (service serviceChat) ArchiveChat(ctx context.Context, request domainChat.ArchiveChatRequest) (response domainChat.ArchiveChatResponse, err error) {+ if err = validations.ValidateArchiveChat(ctx, &request); err != nil {+ return response, err+ }++ client := whatsapp.ClientFromContext(ctx)+ if client == nil {+ return response, pkgError.ErrWaCLI+ }++ // Validate JID and ensure connection+ targetJID, err := utils.ValidateJidWithLogin(client, request.ChatJID)+ if err != nil {+ return response, err+ }++ // Build archive patch using whatsmeow's BuildArchive+ patchInfo := appstate.BuildArchive(targetJID, request.Archived, time.Now(), nil)++ // Send app state update+ if err = client.SendAppState(ctx, patchInfo); err != nil {+ logrus.WithError(err).WithFields(logrus.Fields{+ "chat_jid": request.ChatJID,+ "archived": request.Archived,+ }).Error("Failed to send archive chat app state")+ return response, err+ }++ // Build response+ response.Status = "success"+ response.ChatJID = request.ChatJID+ response.Archived = request.Archived++ if request.Archived {+ response.Message = "Chat archived successfully"+ } else {+ response.Message = "Chat unarchived successfully"+ }++ logrus.WithFields(logrus.Fields{+ "chat_jid": request.ChatJID,+ "archived": request.Archived,+ }).Info("Chat archive operation completed successfully")++ return response, nil+}diff --git a/src/validations/chat_validation.go b/src/validations/chat_validation.goindex f39e04eb..e097c437 100644--- a/src/validations/chat_validation.go+++ b/src/validations/chat_validation.go@@ -90,3 +90,15 @@ func validateTimerValue(value interface{}) error {}return pkgError.ValidationError("timer_seconds must be one of: 0 (off), 86400 (24h), 604800 (7d), 7776000 (90d)")}++func ValidateArchiveChat(ctx context.Context, request *domainChat.ArchiveChatRequest) error {+ err := validation.ValidateStructWithContext(ctx, request,+ validation.Field(&request.ChatJID, validation.Required),+ )++ if err != nil {+ return pkgError.ValidationError(err.Error())+ }++ return nil+}