diff --git a/docs/openapi.yaml b/docs/openapi.yaml index 2a9d583..0ba4426 100644 --- a/docs/openapi.yaml +++ b/docs/openapi.yaml @@ -1,7 +1,7 @@ openapi: "3.0.0" info: title: WhatsApp API MultiDevice - version: 5.2.0 + version: 5.3.0 description: This API is used for sending whatsapp via API servers: - url: http://localhost:3000 @@ -225,6 +225,44 @@ paths: application/json: schema: $ref: '#/components/schemas/ErrorInternalServer' + /user/pushname: + post: + operationId: userChangePushName + tags: + - user + summary: User Change Push Name + description: Update the display name (push name) shown to others in WhatsApp + requestBody: + content: + application/json: + schema: + type: object + properties: + push_name: + type: string + example: 'John Doe' + description: The new display name to set + required: + - push_name + responses: + '200': + description: OK + content: + application/json: + schema: + $ref: '#/components/schemas/GenericResponse' + '400': + description: Bad Request + content: + application/json: + schema: + $ref: '#/components/schemas/ErrorBadRequest' + '500': + description: Internal Server Error + content: + application/json: + schema: + $ref: '#/components/schemas/ErrorInternalServer' /user/my/privacy: get: operationId: userMyPrivacy diff --git a/readme.md b/readme.md index ab14e6c..488bad9 100644 --- a/readme.md +++ b/readme.md @@ -191,6 +191,7 @@ You can fork or edit this source code ! | ✅ | User Info | GET | /user/info | | ✅ | User Avatar | GET | /user/avatar | | ✅ | User Change Avatar | POST | /user/avatar | +| ✅ | User Change PushName | POST | /user/pushname | | ✅ | User My Groups | GET | /user/my/groups | | ✅ | User My Newsletter | GET | /user/my/newsletters | | ✅ | User My Privacy Setting | GET | /user/my/privacy | diff --git a/src/config/settings.go b/src/config/settings.go index b04457e..712a431 100644 --- a/src/config/settings.go +++ b/src/config/settings.go @@ -5,7 +5,7 @@ import ( ) var ( - AppVersion = "v5.4.0" + AppVersion = "v5.5.0" AppPort = "3000" AppDebug = false AppOs = "AldinoKemal" diff --git a/src/domains/user/account.go b/src/domains/user/account.go index fba3b0b..c0fb6b5 100644 --- a/src/domains/user/account.go +++ b/src/domains/user/account.go @@ -69,3 +69,7 @@ type MyListContactsResponseData struct { JID types.JID `json:"jid"` Name string `json:"name"` } + +type ChangePushNameRequest struct { + PushName string `json:"push_name" form:"push_name"` +} diff --git a/src/domains/user/user.go b/src/domains/user/user.go index 0b46309..ef78619 100644 --- a/src/domains/user/user.go +++ b/src/domains/user/user.go @@ -8,6 +8,7 @@ type IUserService interface { Info(ctx context.Context, request InfoRequest) (response InfoResponse, err error) Avatar(ctx context.Context, request AvatarRequest) (response AvatarResponse, err error) ChangeAvatar(ctx context.Context, request ChangeAvatarRequest) (err error) + ChangePushName(ctx context.Context, request ChangePushNameRequest) (err error) MyListGroups(ctx context.Context) (response MyListGroupsResponse, err error) MyListNewsletter(ctx context.Context) (response MyListNewsletterResponse, err error) MyPrivacySetting(ctx context.Context) (response MyPrivacySettingResponse, err error) diff --git a/src/internal/rest/user.go b/src/internal/rest/user.go index 10596a5..1dc244b 100644 --- a/src/internal/rest/user.go +++ b/src/internal/rest/user.go @@ -16,6 +16,7 @@ func InitRestUser(app *fiber.App, service domainUser.IUserService) User { app.Get("/user/info", rest.UserInfo) app.Get("/user/avatar", rest.UserAvatar) app.Post("/user/avatar", rest.UserChangeAvatar) + app.Post("/user/pushname", rest.UserChangePushName) app.Get("/user/my/privacy", rest.UserMyPrivacySetting) app.Get("/user/my/groups", rest.UserMyListGroups) app.Get("/user/my/newsletters", rest.UserMyListNewsletter) @@ -125,3 +126,18 @@ func (controller *User) UserMyListContacts(c *fiber.Ctx) error { Results: response, }) } + +func (controller *User) UserChangePushName(c *fiber.Ctx) error { + var request domainUser.ChangePushNameRequest + err := c.BodyParser(&request) + utils.PanicIfNeeded(err) + + err = controller.Service.ChangePushName(c.UserContext(), request) + utils.PanicIfNeeded(err) + + return c.JSON(utils.ResponseData{ + Status: 200, + Code: "SUCCESS", + Message: "Success change push name", + }) +} diff --git a/src/services/user.go b/src/services/user.go index e1d0c94..b49562d 100644 --- a/src/services/user.go +++ b/src/services/user.go @@ -14,6 +14,7 @@ import ( "github.com/aldinokemal/go-whatsapp-web-multidevice/validations" "github.com/disintegration/imaging" "go.mau.fi/whatsmeow" + "go.mau.fi/whatsmeow/appstate" "go.mau.fi/whatsmeow/types" ) @@ -231,3 +232,14 @@ func (service userService) ChangeAvatar(ctx context.Context, request domainUser. return nil } + +// ChangePushName implements user.IUserService. +func (service *userService) ChangePushName(ctx context.Context, request domainUser.ChangePushNameRequest) (err error) { + whatsapp.MustLogin(service.WaCli) + + err = service.WaCli.SendAppState(appstate.BuildSettingPushName(request.PushName)) + if err != nil { + return err + } + return nil +} diff --git a/src/views/components/AccountChangePushName.js b/src/views/components/AccountChangePushName.js new file mode 100644 index 0000000..467ff4a --- /dev/null +++ b/src/views/components/AccountChangePushName.js @@ -0,0 +1,96 @@ +export default { + name: 'AccountChangePushName', + data() { + return { + loading: false, + push_name: '' + } + }, + methods: { + openModal() { + $('#modalChangePushName').modal({ + onApprove: function () { + return false; + } + }).modal('show'); + }, + isValidForm() { + return this.push_name.trim() !== ''; + }, + async handleSubmit() { + if (!this.isValidForm() || this.loading) { + return; + } + + try { + let response = await this.submitApi() + showSuccessInfo(response) + $('#modalChangePushName').modal('hide'); + } catch (err) { + showErrorInfo(err) + } + }, + async submitApi() { + this.loading = true; + try { + let payload = { + push_name: this.push_name + } + + let response = await window.http.post(`/user/pushname`, payload) + this.handleReset(); + return response.data.message; + } catch (error) { + if (error.response) { + throw new Error(error.response.data.message); + } + throw new Error(error.message); + } finally { + this.loading = false; + } + }, + handleReset() { + this.push_name = ''; + } + }, + template: ` +