Skip to content

GOWA - WhatsApp REST API with support for UI, Multi Account, Webhooks, and MCP, and Chatwoot. Built with Golang for efficient memory use.

feat: Implement user push name change functionality and update API do… (#270)

Aldino Kemal978e3068f41c
diff --git a/docs/openapi.yaml b/docs/openapi.yaml
index 2a9d583d..0ba4426f 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 ab14e6c5..488bad94 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 b04457e5..712a431a 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 fba3b0b6..c0fb6b55 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 0b463092..ef786195 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 10596a51..1dc244b6 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 e1d0c944..b49562d4 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 00000000..467ff4a5
--- /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: `
+ <div class="olive card" @click="openModal()" style="cursor:pointer;">
+ <div class="content">
+ <a class="ui olive right ribbon label">Account</a>
+ <div class="header">Change Push Name</div>
+ <div class="description">
+ Update your WhatsApp display name
+ </div>
+ </div>
+ </div>
+
+ <!-- Modal Change Push Name -->
+ <div class="ui small modal" id="modalChangePushName">
+ <i class="close icon"></i>
+ <div class="header">
+ Change Push Name
+ </div>
+ <div class="content" style="max-height: 70vh; overflow-y: auto;">
+ <div class="ui info message">
+ <i class="info circle icon"></i>
+ Your push name is the display name shown to others in WhatsApp.
+ </div>
+
+ <form class="ui form">
+ <div class="field">
+ <label>New Push Name</label>
+ <input type="text" v-model="push_name" placeholder="Enter your new display name">
+ </div>
+ </form>
+ </div>
+ <div class="actions">
+ <button class="ui approve positive right labeled icon button"
+ :class="{'loading': this.loading, 'disabled': !isValidForm() || loading}"
+ @click.prevent="handleSubmit">
+ Update Push Name
+ <i class="save icon"></i>
+ </button>
+ </div>
+ </div>
+ `
+}
diff --git a/src/views/index.html b/src/views/index.html
index 97a2d6fa..b79dcc4b 100644
--- a/src/views/index.html
+++ b/src/views/index.html
@@ -157,6 +157,7 @@
<div class="ui three column doubling grid cards">
<account-avatar></account-avatar>
<account-change-avatar></account-change-avatar>
+ <account-change-push-name></account-change-push-name>
<account-user-info></account-user-info>
<account-privacy></account-privacy>
<account-contact></account-contact>
@@ -219,6 +220,7 @@
import GroupAddParticipants from "./components/GroupManageParticipants.js";
import AccountAvatar from "./components/AccountAvatar.js";
import AccountChangeAvatar from "./components/AccountChangeAvatar.js";
+ import AccountChangePushName from "./components/AccountChangePushName.js";
import AccountUserInfo from "./components/AccountUserInfo.js";
import AccountPrivacy from "./components/AccountPrivacy.js";
import NewsletterList from "./components/NewsletterList.js";
@@ -261,7 +263,7 @@
MessageDelete, MessageUpdate, MessageReact, MessageRevoke,
GroupList, GroupCreate, GroupJoinWithLink, GroupAddParticipants,
NewsletterList,
- AccountAvatar, AccountUserInfo, AccountPrivacy, AccountChangeAvatar, AccountContact
+ AccountAvatar, AccountUserInfo, AccountPrivacy, AccountChangeAvatar, AccountContact, AccountChangePushName
},
delimiters: ['[[', ']]'],
data() {