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(chat): add pin/unpin functionality with UI component (#341)
Aldino Kemal2dd44d2822e3
diff --git a/docs/openapi.yaml b/docs/openapi.yamlindex c2e2408d..29b20bea 100644--- a/docs/openapi.yaml+++ b/docs/openapi.yaml@@ -1,7 +1,7 @@openapi: "3.0.0"info:title: WhatsApp API MultiDevice- version: 6.7.0+ version: 6.8.0description: This API is used for sending whatsapp via APIservers:- url: http://localhost:3000@@ -1452,6 +1452,132 @@ paths:application/json:schema:$ref: '#/components/schemas/ErrorInternalServer'+ /chat/{chat_jid}/label:+ post:+ operationId: labelChat+ tags:+ - chat+ summary: Label or unlabel a chat+ description: Apply or remove a label from a chat conversation+ parameters:+ - 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:+ label_id:+ type: string+ example: 'label_123'+ description: Unique identifier for the label+ label_name:+ type: string+ example: 'Important'+ description: Display name for the label+ labeled:+ type: boolean+ example: true+ description: Whether to apply (true) or remove (false) the label+ required:+ - label_id+ - label_name+ - labeled+ responses:+ '200':+ description: OK+ content:+ application/json:+ schema:+ $ref: '#/components/schemas/LabelChatResponse'+ '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'+ /chat/{chat_jid}/pin:+ post:+ operationId: pinChat+ tags:+ - chat+ summary: Pin or unpin a chat+ description: Pin or unpin a chat conversation to the top of the chat list+ parameters:+ - 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:+ pinned:+ type: boolean+ example: true+ description: Whether to pin (true) or unpin (false) the chat+ required:+ - pinned+ responses:+ '200':+ description: OK+ content:+ application/json:+ schema:+ $ref: '#/components/schemas/PinChatResponse'+ '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:post:@@ -2930,4 +3056,57 @@ components:type: stringformat: date-timeexample: '2024-01-15T10:30:00Z'- description: Record last update timestamp\ No newline at end of file+ description: Record last update timestamp++ LabelChatResponse:+ type: object+ properties:+ code:+ type: string+ example: SUCCESS+ message:+ type: string+ example: Chat labeled successfully with label 'Important'+ results:+ type: object+ properties:+ status:+ type: string+ example: success+ message:+ type: string+ example: Chat labeled successfully with label 'Important'+ chat_jid:+ type: string+ example: '[email protected]'+ label_id:+ type: string+ example: 'label_123'+ labeled:+ type: boolean+ example: true++ PinChatResponse:+ type: object+ properties:+ code:+ type: string+ example: SUCCESS+ message:+ type: string+ example: Chat pinned successfully+ results:+ type: object+ properties:+ status:+ type: string+ example: success+ message:+ type: string+ example: Chat pinned successfully+ chat_jid:+ type: string+ example: '[email protected]'+ pinned:+ type: boolean+ example: true\ No newline at end of filediff --git a/readme.md b/readme.mdindex 6f14a169..565c893f 100644--- a/readme.md+++ b/readme.md@@ -343,6 +343,10 @@ You can fork or edit this source code !| ✅ | Set Group Announce | POST | /group/announce || ✅ | Set Group Topic | POST | /group/topic || ✅ | Unfollow Newsletter | POST | /newsletter/unfollow |+| ✅ | Get Chat List | GET | /chats |+| ✅ | Get Chat Messages | GET | /chat/:chat_jid/messages |+| ✅ | Label Chat | POST | /chat/:chat_jid/label |+| ✅ | Pin Chat | POST | /chat/:chat_jid/pin |```txt✅ = Availablediff --git a/src/domains/chat/chat.go b/src/domains/chat/chat.goindex 659d44c5..669ae3ea 100644--- a/src/domains/chat/chat.go+++ b/src/domains/chat/chat.go@@ -31,6 +31,19 @@ type GetChatMessagesResponse struct {ChatInfo ChatInfo `json:"chat_info"`}+// Pin Chat operations+type PinChatRequest struct {+ ChatJID string `json:"chat_jid" uri:"chat_jid"`+ Pinned bool `json:"pinned"`+}++type PinChatResponse struct {+ Status string `json:"status"`+ Message string `json:"message"`+ ChatJID string `json:"chat_jid"`+ Pinned bool `json:"pinned"`+}+type ChatInfo struct {JID string `json:"jid"`Name string `json:"name"`diff --git a/src/domains/chat/interfaces.go b/src/domains/chat/interfaces.goindex eedeb492..83679393 100644--- a/src/domains/chat/interfaces.go+++ b/src/domains/chat/interfaces.go@@ -8,4 +8,5 @@ import (type IChatUsecase interface {ListChats(ctx context.Context, request ListChatsRequest) (response ListChatsResponse, err error)GetChatMessages(ctx context.Context, request GetChatMessagesRequest) (response GetChatMessagesResponse, err error)-}\ No newline at end of file+ PinChat(ctx context.Context, request PinChatRequest) (response PinChatResponse, err error)+}diff --git a/src/go.mod b/src/go.modindex a56d3aa8..f3b6809f 100644--- a/src/go.mod+++ b/src/go.mod@@ -2,8 +2,6 @@ module github.com/aldinokemal/go-whatsapp-web-multidevicego 1.24.0-replace go.mau.fi/whatsmeow => github.com/aldinokemal/whatsmeow v0.0.0-20250708124515-f4ddac1a8e75-require (github.com/PuerkitoBio/goquery v1.10.3github.com/disintegration/imaging v1.6.2@@ -23,8 +21,8 @@ require (github.com/stretchr/testify v1.10.0github.com/valyala/fasthttp v1.63.0go.mau.fi/libsignal v0.2.0- go.mau.fi/whatsmeow v0.0.0-20250708101704-8534cb4f629f- golang.org/x/image v0.28.0+ go.mau.fi/whatsmeow v0.0.0-20250709212552-0b8557ee0860+ golang.org/x/image v0.29.0google.golang.org/protobuf v1.36.6)@@ -61,10 +59,10 @@ require (github.com/yosida95/uritemplate/v3 v3.0.2 // indirectgo.mau.fi/util v0.8.8 // indirectgo.uber.org/multierr v1.11.0 // indirect- golang.org/x/crypto v0.39.0 // indirect- golang.org/x/exp v0.0.0-20250620022241-b7579e27df2b // indirect- golang.org/x/net v0.41.0 // indirect- golang.org/x/sys v0.33.0 // indirect- golang.org/x/text v0.26.0 // indirect+ golang.org/x/crypto v0.40.0 // indirect+ golang.org/x/exp v0.0.0-20250711185948-6ae5c78190dc // indirect+ golang.org/x/net v0.42.0 // indirect+ golang.org/x/sys v0.34.0 // indirect+ golang.org/x/text v0.27.0 // indirectgopkg.in/yaml.v3 v3.0.1 // indirect)diff --git a/src/go.sum b/src/go.sumindex bd62c46a..b8510f86 100644--- a/src/go.sum+++ b/src/go.sum@@ -130,6 +130,8 @@ go.mau.fi/libsignal v0.2.0 h1:oRXj3OHhEJq51BFEM8/50UZblmWiTYH93hsNTPcbk90=go.mau.fi/libsignal v0.2.0/go.mod h1:tvjoDsMejgT38CXTXwqaYu8itBiY8O2Mb6biWvZBb9k=go.mau.fi/util v0.8.8 h1:OnuEEc/sIJFhnq4kFggiImUpcmnmL/xpvQMRu5Fiy5c=go.mau.fi/util v0.8.8/go.mod h1:Y/kS3loxTEhy8Vill513EtPXr+CRDdae+Xj2BXXMy/c=+go.mau.fi/whatsmeow v0.0.0-20250709212552-0b8557ee0860 h1:0AdAzM/QtzgUKiJ2oyVfiSiZq/fIjxadUtepPy2lZwk=+go.mau.fi/whatsmeow v0.0.0-20250709212552-0b8557ee0860/go.mod h1:bEyyFvXlwr/18B2pOkdX1vWAx1+y1NJX+sCXVyw01UA=go.uber.org/multierr v1.11.0 h1:blXXJkSxSSfBVBlC76pxqeO+LN3aDfLQo+309xJstO0=go.uber.org/multierr v1.11.0/go.mod h1:20+QtiLqy0Nd6FdQB9TLXag12DsQkrbs3htMFfDN80Y=golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=@@ -140,11 +142,17 @@ golang.org/x/crypto v0.23.0/go.mod h1:CKFgDieR+mRhux2Lsu27y0fO304Db0wZe70UKqHu0vgolang.org/x/crypto v0.31.0/go.mod h1:kDsLvtWBEx7MV9tJOj9bnXsPbxwJQ6csT/x4KIN4Ssk=golang.org/x/crypto v0.39.0 h1:SHs+kF4LP+f+p14esP5jAoDpHU8Gu/v9lFRK6IT5imM=golang.org/x/crypto v0.39.0/go.mod h1:L+Xg3Wf6HoL4Bn4238Z6ft6KfEpN0tJGo53AAPC632U=+golang.org/x/crypto v0.40.0 h1:r4x+VvoG5Fm+eJcxMaY8CQM7Lb0l1lsmjGBQ6s8BfKM=+golang.org/x/crypto v0.40.0/go.mod h1:Qr1vMER5WyS2dfPHAlsOj01wgLbsyWtFn/aY+5+ZdxY=golang.org/x/exp v0.0.0-20250620022241-b7579e27df2b h1:M2rDM6z3Fhozi9O7NWsxAkg/yqS/lQJ6PmkyIV3YP+o=golang.org/x/exp v0.0.0-20250620022241-b7579e27df2b/go.mod h1:3//PLf8L/X+8b4vuAfHzxeRUl04Adcb341+IGKfnqS8=+golang.org/x/exp v0.0.0-20250711185948-6ae5c78190dc h1:TS73t7x3KarrNd5qAipmspBDS1rkMcgVG/fS1aRb4Rc=+golang.org/x/exp v0.0.0-20250711185948-6ae5c78190dc/go.mod h1:A+z0yzpGtvnG90cToK5n2tu8UJVP2XUATh+r+sfOOOc=golang.org/x/image v0.0.0-20191009234506-e7c1f5e7dbb8/go.mod h1:FeLwcggjj3mMvU+oOTbSwawSJRM1uh48EjtB4UJZlP0=golang.org/x/image v0.28.0 h1:gdem5JW1OLS4FbkWgLO+7ZeFzYtL3xClb97GaUzYMFE=golang.org/x/image v0.28.0/go.mod h1:GUJYXtnGKEUgggyzh+Vxt+AviiCcyiwpsl8iQ8MvwGY=+golang.org/x/image v0.29.0 h1:HcdsyR4Gsuys/Axh0rDEmlBmB68rW1U9BUdB3UVHsas=+golang.org/x/image v0.29.0/go.mod h1:RVJROnf3SLK8d26OW91j4FrIHGbsJ8QnbEocVTOWQDA=golang.org/x/mod v0.6.0-dev.0.20220419223038-86c51ed26bb4/go.mod h1:jJ57K6gSWd91VN4djpZkiMVwK6gcyfeH4XE8wZrZaV4=golang.org/x/mod v0.8.0/go.mod h1:iBbtSCu2XBx23ZKBPSOrRkjjQPZFPuis4dIYUhu/chs=golang.org/x/mod v0.12.0/go.mod h1:iBbtSCu2XBx23ZKBPSOrRkjjQPZFPuis4dIYUhu/chs=@@ -161,6 +169,8 @@ golang.org/x/net v0.25.0/go.mod h1:JkAGAh7GEvH74S6FOH42FLoXpXbE/aqXSrIQjXgsiwM=golang.org/x/net v0.33.0/go.mod h1:HXLR5J+9DxmrqMwG9qjGCxZ+zKXxBru04zlTvWlWuN4=golang.org/x/net v0.41.0 h1:vBTly1HeNPEn3wtREYfy4GZ/NECgw2Cnl+nK6Nz3uvw=golang.org/x/net v0.41.0/go.mod h1:B/K4NNqkfmg07DQYrbwvSluqCJOOXwUjeb/5lOisjbA=+golang.org/x/net v0.42.0 h1:jzkYrhi3YQWD6MLBJcsklgQsoAcw89EcZbJw8Z614hs=+golang.org/x/net v0.42.0/go.mod h1:FF1RA5d3u7nAYA4z2TkclSCKh68eSXtiFwcWQpPXdt8=golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=golang.org/x/sync v0.0.0-20220722155255-886fb9371eb4/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=golang.org/x/sync v0.1.0/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=@@ -184,6 +194,8 @@ golang.org/x/sys v0.20.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=golang.org/x/sys v0.28.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=golang.org/x/sys v0.33.0 h1:q3i8TbbEz+JRD9ywIRlyRAQbM0qF7hu24q3teo2hbuw=golang.org/x/sys v0.33.0/go.mod h1:BJP2sWEmIv4KK5OTEluFJCKSidICx8ciO85XgH3Ak8k=+golang.org/x/sys v0.34.0 h1:H5Y5sJ2L2JRdyv7ROF1he/lPdvFsd0mJHFw2ThKHxLA=+golang.org/x/sys v0.34.0/go.mod h1:BJP2sWEmIv4KK5OTEluFJCKSidICx8ciO85XgH3Ak8k=golang.org/x/telemetry v0.0.0-20240228155512-f48c80bd79b2/go.mod h1:TeRTkGYfJXctD9OcfyVLyj2J3IxLnKwHJR8f4D8a3YE=golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo=golang.org/x/term v0.0.0-20210927222741-03fcf44c2211/go.mod h1:jbD1KX2456YbFQfuXm/mYQcufACuNUgVhRMnK/tPxf8=@@ -204,6 +216,8 @@ golang.org/x/text v0.15.0/go.mod h1:18ZOQIKpY8NJVqYksKHtTdi31H5itFRjB5/qKTNYzSU=golang.org/x/text v0.21.0/go.mod h1:4IBbMaMmOPCJ8SecivzSH54+73PCFmPWxNTLm+vZkEQ=golang.org/x/text v0.26.0 h1:P42AVeLghgTYr4+xUnTRKDMqpar+PtX7KWuNQL21L8M=golang.org/x/text v0.26.0/go.mod h1:QK15LZJUUQVJxhz7wXgxSy/CJaTFjd0G+YLonydOVQA=+golang.org/x/text v0.27.0 h1:4fGWRpyh641NLlecmyl4LOe6yDdfaYNrGb2zdfo4JV4=+golang.org/x/text v0.27.0/go.mod h1:1D28KMCvyooCX9hBiosv5Tz/+YLxj0j7XhWjpSUF7CU=golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=golang.org/x/tools v0.0.0-20191119224855-298f0cb1881e/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo=golang.org/x/tools v0.1.12/go.mod h1:hNGJHUnrk76NpqgfD5Aqm5Crs+Hm0VOH/i9J2+nxYbc=diff --git a/src/ui/rest/chat.go b/src/ui/rest/chat.goindex 9513655b..88686ad0 100644--- a/src/ui/rest/chat.go+++ b/src/ui/rest/chat.go@@ -16,6 +16,7 @@ func InitRestChat(app *fiber.App, service domainChat.IChatUsecase) Chat {// Chat endpointsapp.Get("/chats", rest.ListChats)app.Get("/chat/:chat_jid/messages", rest.GetChatMessages)+ app.Post("/chat/:chat_jid/pin", rest.PinChat)return rest}@@ -76,3 +77,30 @@ func (controller *Chat) GetChatMessages(c *fiber.Ctx) error {Results: response,})}++func (controller *Chat) PinChat(c *fiber.Ctx) error {+ var request domainChat.PinChatRequest++ // 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.PinChat(c.UserContext(), 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 be3422a7..882b8278 100644--- a/src/usecase/chat.go+++ b/src/usecase/chat.go@@ -7,8 +7,11 @@ import (domainChat "github.com/aldinokemal/go-whatsapp-web-multidevice/domains/chat""github.com/aldinokemal/go-whatsapp-web-multidevice/infrastructure/chatstorage"+ "github.com/aldinokemal/go-whatsapp-web-multidevice/infrastructure/whatsapp"+ "github.com/aldinokemal/go-whatsapp-web-multidevice/pkg/utils""github.com/aldinokemal/go-whatsapp-web-multidevice/validations""github.com/sirupsen/logrus"+ "go.mau.fi/whatsmeow/appstate")type serviceChat struct {@@ -199,3 +202,45 @@ func (service serviceChat) GetChatMessages(ctx context.Context, request domainChreturn response, nil}++func (service serviceChat) PinChat(ctx context.Context, request domainChat.PinChatRequest) (response domainChat.PinChatResponse, err error) {+ if err = validations.ValidatePinChat(ctx, &request); err != nil {+ return response, err+ }++ // Validate JID and ensure connection+ targetJID, err := utils.ValidateJidWithLogin(whatsapp.GetClient(), request.ChatJID)+ if err != nil {+ return response, err+ }++ // Build pin patch using whatsmeow's BuildPin+ patchInfo := appstate.BuildPin(targetJID, request.Pinned)++ // Send app state update+ if err = whatsapp.GetClient().SendAppState(ctx, patchInfo); err != nil {+ logrus.WithError(err).WithFields(logrus.Fields{+ "chat_jid": request.ChatJID,+ "pinned": request.Pinned,+ }).Error("Failed to send pin chat app state")+ return response, err+ }++ // Build response+ response.Status = "success"+ response.ChatJID = request.ChatJID+ response.Pinned = request.Pinned++ if request.Pinned {+ response.Message = "Chat pinned successfully"+ } else {+ response.Message = "Chat unpinned successfully"+ }++ logrus.WithFields(logrus.Fields{+ "chat_jid": request.ChatJID,+ "pinned": request.Pinned,+ }).Info("Chat pin operation completed successfully")++ return response, nil+}diff --git a/src/usecase/message.go b/src/usecase/message.goindex 921fa3bc..d4ad4a9d 100644--- a/src/usecase/message.go+++ b/src/usecase/message.go@@ -182,4 +182,3 @@ func (service serviceMessage) StarMessage(ctx context.Context, request domainMes}return nil}-diff --git a/src/validations/chat_validation.go b/src/validations/chat_validation.goindex ae60ee80..9953fee4 100644--- a/src/validations/chat_validation.go+++ b/src/validations/chat_validation.go@@ -44,3 +44,15 @@ func ValidateGetChatMessages(ctx context.Context, request *domainChat.GetChatMesreturn nil}++func ValidatePinChat(ctx context.Context, request *domainChat.PinChatRequest) error {+ err := validation.ValidateStructWithContext(ctx, request,+ validation.Field(&request.ChatJID, validation.Required),+ )++ if err != nil {+ return pkgError.ValidationError(err.Error())+ }++ return nil+}diff --git a/src/validations/chat_validation_test.go b/src/validations/chat_validation_test.gonew file mode 100644index 00000000..009ed40b--- /dev/null+++ b/src/validations/chat_validation_test.go@@ -0,0 +1,53 @@+package validations++import (+ "context"+ "testing"++ domainChat "github.com/aldinokemal/go-whatsapp-web-multidevice/domains/chat"+ pkgError "github.com/aldinokemal/go-whatsapp-web-multidevice/pkg/error"+ "github.com/stretchr/testify/assert"+)++func TestValidatePinChat(t *testing.T) {+ type args struct {+ request domainChat.PinChatRequest+ }+ tests := []struct {+ name string+ args args+ err any+ }{+ {+ name: "should success with valid request",+ args: args{request: domainChat.PinChatRequest{+ ChatJID: "[email protected]",+ Pinned: true,+ }},+ err: nil,+ },+ {+ name: "should success with unpin request",+ args: args{request: domainChat.PinChatRequest{+ ChatJID: "[email protected]",+ Pinned: false,+ }},+ err: nil,+ },+ {+ name: "should error with empty chat_jid",+ args: args{request: domainChat.PinChatRequest{+ ChatJID: "",+ Pinned: true,+ }},+ err: pkgError.ValidationError("chat_jid: cannot be blank."),+ },+ }++ for _, tt := range tests {+ t.Run(tt.name, func(t *testing.T) {+ err := ValidatePinChat(context.Background(), &tt.args.request)+ assert.Equal(t, tt.err, err)+ })+ }+}diff --git a/src/views/components/ChatPinManager.js b/src/views/components/ChatPinManager.jsnew file mode 100644index 00000000..e20394e5--- /dev/null+++ b/src/views/components/ChatPinManager.js@@ -0,0 +1,108 @@+import FormRecipient from "./generic/FormRecipient.js";++export default {+ name: 'ChatPinManager',+ components: {+ FormRecipient+ },+ data() {+ return {+ type: window.TYPEUSER,+ phone: '',+ pinned: true,+ loading: false,+ }+ },+ computed: {+ phone_id() {+ return this.phone + this.type;+ },+ },+ methods: {+ isValidForm() {+ const isPhoneValid = this.phone.trim().length > 0;+ return isPhoneValid;+ },+ openModal() {+ $('#modalChatPin').modal({+ onApprove: function () {+ return false;+ }+ }).modal('show');+ },+ async handleSubmit() {+ if (!this.isValidForm() || this.loading) {+ return;+ }+ try {+ const response = await this.submitApi();+ showSuccessInfo(response);+ $('#modalChatPin').modal('hide');+ } catch (err) {+ showErrorInfo(err);+ }+ },+ async submitApi() {+ this.loading = true;+ try {+ const payload = {+ pinned: this.pinned+ };++ const response = await window.http.post(`/chat/${this.phone_id}/pin`, payload);+ this.handleReset();+ return response.data.message;+ } catch (error) {+ if (error.response?.data?.message) {+ throw new Error(error.response.data.message);+ }+ throw error;+ } finally {+ this.loading = false;+ }+ },+ handleReset() {+ this.phone = '';+ this.pinned = true;+ },+ },+ template: `+ <div class="purple card" @click="openModal()" style="cursor: pointer">+ <div class="content">+ <a class="ui purple right ribbon label">Chat</a>+ <div class="header">Pin Chat</div>+ <div class="description">+ Pin or unpin chats to the top of the list+ </div>+ </div>+ </div>++ <!-- Modal ChatPin -->+ <div class="ui small modal" id="modalChatPin">+ <i class="close icon"></i>+ <div class="header">+ Pin Chat+ </div>+ <div class="content">+ <form class="ui form">+ <FormRecipient v-model:type="type" v-model:phone="phone" :show-status="false"/>+ <div class="field">+ <label>Action</label>+ <div class="ui toggle checkbox">+ <input type="checkbox" aria-label="pinned" v-model="pinned">+ <label>Pin chat (uncheck to unpin)</label>+ </div>+ </div>+ </form>+ </div>+ <div class="actions">+ <button class="ui approve positive right labeled icon button"+ :class="{'disabled': !isValidForm() || loading}"+ @click.prevent="handleSubmit">+ {{ pinned ? 'Pin Chat' : 'Unpin Chat' }}+ <i class="pin icon"></i>+ </button>+ </div>+ </div>+ `+}\ No newline at end of filediff --git a/src/views/index.html b/src/views/index.htmlindex fd8e2f14..22acbab6 100644--- a/src/views/index.html+++ b/src/views/index.html@@ -135,6 +135,14 @@<account-user-check></account-user-check></div>+ <div class="ui horizontal divider">+ Chat Management+ </div>++ <div class="ui three column doubling grid cards">+ <chat-pin-manager></chat-pin-manager>+ </div>+</div><script>window.TYPEGROUP = "@g.us";@@ -165,7 +173,7 @@baseURL: `${window.location.protocol}//${window.location.hostname}${window.location.port ? ':' + window.location.port : ''}`});{{ if isEnableBasicAuth .BasicAuthToken }}- window.http.defaults.headers.common['Authorization'] = {{ .BasicAuthToken }};+ window.http.defaults.headers.common['Authorization'] = "{{ .BasicAuthToken }}";{{ end }}</script><script type="module">@@ -207,6 +215,7 @@import AccountContact from "./components/AccountContact.js";import AccountUserCheck from "./components/AccountUserCheck.js";import AccountBusinessProfile from "./components/AccountBusinessProfile.js";+ import ChatPinManager from "./components/ChatPinManager.js";const showErrorInfo = (message) => {$('body').toast({@@ -245,7 +254,8 @@MessageDelete, MessageUpdate, MessageReact, MessageRevoke, MessageRead,GroupList, GroupCreate, GroupJoinWithLink, GroupAddParticipants, GroupSetPhoto, GroupSetName, GroupSetLocked, GroupSetAnnounce, GroupSetTopic,NewsletterList,- AccountAvatar, AccountUserInfo, AccountPrivacy, AccountChangeAvatar, AccountContact, AccountChangePushName, AccountUserCheck, AccountBusinessProfile+ AccountAvatar, AccountUserInfo, AccountPrivacy, AccountChangeAvatar, AccountContact, AccountChangePushName, AccountUserCheck, AccountBusinessProfile,+ ChatPinManager},delimiters: ['[[', ']]'],data() {