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(send): add chat presence typing indicator functionality

Aldino Kemal8de6fd573863
diff --git a/docs/openapi.yaml b/docs/openapi.yaml
index d902b374..211b261b 100644
--- a/docs/openapi.yaml
+++ b/docs/openapi.yaml
@@ -915,6 +915,51 @@ paths:
application/json:
schema:
$ref: '#/components/schemas/ErrorInternalServer'
+ /send/chat-presence:
+ post:
+ operationId: sendChatPresence
+ tags:
+ - send
+ summary: Send chat presence (typing indicator)
+ description: Send typing indicator to start or stop showing that you are composing a message
+ requestBody:
+ required: true
+ content:
+ application/json:
+ schema:
+ type: object
+ properties:
+ phone:
+ type: string
+ example: '[email protected]'
+ description: Phone number with country code
+ action:
+ type: string
+ enum: [start, stop]
+ example: 'start'
+ description: Action to perform - "start" to begin typing indicator, "stop" to end typing indicator
+ required:
+ - phone
+ - action
+ responses:
+ '200':
+ description: OK
+ content:
+ application/json:
+ schema:
+ $ref: '#/components/schemas/SendResponse'
+ '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'
/message/{message_id}/revoke:
post:
operationId: revokeMessage
diff --git a/readme.md b/readme.md
index 393d3381..8b26a740 100644
--- a/readme.md
+++ b/readme.md
@@ -318,6 +318,7 @@ You can fork or edit this source code !
| ✅ | Send Location | POST | /send/location |
| ✅ | Send Poll / Vote | POST | /send/poll |
| ✅ | Send Presence | POST | /send/presence |
+| ✅ | Send Chat Presence (Typing Indicator) | POST | /send/chat-presence |
| ✅ | Revoke Message | POST | /message/:message_id/revoke |
| ✅ | React Message | POST | /message/:message_id/reaction |
| ✅ | Delete Message | POST | /message/:message_id/delete |
diff --git a/src/domains/send/chat_presence.go b/src/domains/send/chat_presence.go
new file mode 100644
index 00000000..af91e3ef
--- /dev/null
+++ b/src/domains/send/chat_presence.go
@@ -0,0 +1,8 @@
+package send
+
+// ChatPresenceRequest represents a request to send chat presence (typing indicator)
+type ChatPresenceRequest struct {
+ BaseRequest
+ Phone string `json:"phone" validate:"required"`
+ Action string `json:"action" validate:"required"`
+}
diff --git a/src/domains/send/send.go b/src/domains/send/send.go
index 643f9336..0c179843 100644
--- a/src/domains/send/send.go
+++ b/src/domains/send/send.go
@@ -15,6 +15,7 @@ type ISendUsecase interface {
SendAudio(ctx context.Context, request AudioRequest) (response GenericResponse, err error)
SendPoll(ctx context.Context, request PollRequest) (response GenericResponse, err error)
SendPresence(ctx context.Context, request PresenceRequest) (response GenericResponse, err error)
+ SendChatPresence(ctx context.Context, request ChatPresenceRequest) (response GenericResponse, err error)
}
type GenericResponse struct {
diff --git a/src/ui/rest/send.go b/src/ui/rest/send.go
index 64836191..1598d816 100644
--- a/src/ui/rest/send.go
+++ b/src/ui/rest/send.go
@@ -23,6 +23,7 @@ func InitRestSend(app *fiber.App, service domainSend.ISendUsecase) Send {
app.Post("/send/audio", rest.SendAudio)
app.Post("/send/poll", rest.SendPoll)
app.Post("/send/presence", rest.SendPresence)
+ app.Post("/send/chat-presence", rest.SendChatPresence)
return rest
}
@@ -224,3 +225,21 @@ func (controller *Send) SendPresence(c *fiber.Ctx) error {
Results: response,
})
}
+
+func (controller *Send) SendChatPresence(c *fiber.Ctx) error {
+ var request domainSend.ChatPresenceRequest
+ err := c.BodyParser(&request)
+ utils.PanicIfNeeded(err)
+
+ whatsapp.SanitizePhone(&request.Phone)
+
+ response, err := controller.Service.SendChatPresence(c.UserContext(), request)
+ utils.PanicIfNeeded(err)
+
+ return c.JSON(utils.ResponseData{
+ Status: 200,
+ Code: "SUCCESS",
+ Message: response.Status,
+ Results: response,
+ })
+}
diff --git a/src/usecase/send.go b/src/usecase/send.go
index 8056e216..5d704cff 100644
--- a/src/usecase/send.go
+++ b/src/usecase/send.go
@@ -787,6 +787,44 @@ func (service serviceSend) SendPresence(ctx context.Context, request domainSend.
return response, nil
}
+func (service serviceSend) SendChatPresence(ctx context.Context, request domainSend.ChatPresenceRequest) (response domainSend.GenericResponse, err error) {
+ err = validations.ValidateSendChatPresence(ctx, request)
+ if err != nil {
+ return response, err
+ }
+
+ userJid, err := whatsapp.ValidateJidWithLogin(service.WaCli, request.Phone)
+ if err != nil {
+ return response, err
+ }
+
+ var presenceType types.ChatPresence
+ var messageID string
+ var statusMessage string
+
+ switch request.Action {
+ case "start":
+ presenceType = types.ChatPresenceComposing
+ messageID = "chat-presence-start"
+ statusMessage = fmt.Sprintf("Send chat presence start typing success %s", request.Phone)
+ case "stop":
+ presenceType = types.ChatPresencePaused
+ messageID = "chat-presence-stop"
+ statusMessage = fmt.Sprintf("Send chat presence stop typing success %s", request.Phone)
+ default:
+ return response, fmt.Errorf("invalid action: %s. Must be 'start' or 'stop'", request.Action)
+ }
+
+ err = service.WaCli.SendChatPresence(userJid, presenceType, "")
+ if err != nil {
+ return response, err
+ }
+
+ response.MessageID = messageID
+ response.Status = statusMessage
+ return response, nil
+}
+
func (service serviceSend) getMentionFromText(_ context.Context, messages string) (result []string) {
mentions := utils.ContainsMention(messages)
for _, mention := range mentions {
diff --git a/src/validations/send_validation.go b/src/validations/send_validation.go
index 10865cf2..c148d351 100644
--- a/src/validations/send_validation.go
+++ b/src/validations/send_validation.go
@@ -336,3 +336,16 @@ func ValidateSendPresence(ctx context.Context, request domainSend.PresenceReques
return nil
}
+
+func ValidateSendChatPresence(ctx context.Context, request domainSend.ChatPresenceRequest) error {
+ err := validation.ValidateStructWithContext(ctx, &request,
+ validation.Field(&request.Phone, validation.Required),
+ validation.Field(&request.Action, validation.Required, validation.In("start", "stop")),
+ )
+
+ if err != nil {
+ return pkgError.ValidationError(err.Error())
+ }
+
+ return nil
+}
diff --git a/src/views/components/SendChatPresence.js b/src/views/components/SendChatPresence.js
new file mode 100644
index 00000000..7afa17c5
--- /dev/null
+++ b/src/views/components/SendChatPresence.js
@@ -0,0 +1,99 @@
+import FormRecipient from "./generic/FormRecipient.js";
+
+export default {
+ name: 'SendChatPresence',
+ components: {
+ FormRecipient
+ },
+ data() {
+ return {
+ type: window.TYPEUSER,
+ phone: '',
+ action: 'start',
+ loading: false,
+ }
+ },
+ computed: {
+ phone_id() {
+ return this.phone + this.type;
+ },
+ },
+ methods: {
+ openModal() {
+ $('#modalSendChatPresence').modal({
+ onApprove: function () {
+ return false;
+ }
+ }).modal('show');
+ },
+ async handleSubmit() {
+ if (this.loading) {
+ return;
+ }
+
+ try {
+ let response = await this.submitApi()
+ showSuccessInfo(response)
+ } catch (err) {
+ showErrorInfo(err)
+ }
+ },
+ async submitApi() {
+ this.loading = true;
+ try {
+ let payload = {
+ phone: this.phone_id,
+ action: this.action
+ }
+ let response = await window.http.post(`/send/chat-presence`, payload)
+ 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;
+ }
+ }
+ },
+ template: `
+ <div class="blue card" @click="openModal()" style="cursor: pointer">
+ <div class="content">
+ <a class="ui blue right ribbon label">Send</a>
+ <div class="header">Send Chat Presence</div>
+ <div class="description">
+ Send <div class="ui green horizontal label">typing</div> indicators to specific chat
+ </div>
+ </div>
+ </div>
+
+ <!-- Modal SendChatPresence -->
+ <div class="ui small modal" id="modalSendChatPresence">
+ <i class="close icon"></i>
+ <div class="header">
+ Send Chat Presence
+ </div>
+ <div class="content">
+ <form class="ui form">
+ <FormRecipient v-model:type="type" v-model:phone="phone" />
+ <div class="field">
+ <label>Action</label>
+ <select v-model="action" class="ui dropdown">
+ <option value="start">Start Typing</option>
+ <option value="stop">Stop Typing</option>
+ </select>
+ </div>
+ </form>
+ </div>
+ <div class="actions">
+ <button class="ui approve positive right labeled icon button"
+ :class="{'loading': loading, 'disabled': loading}"
+ @click.prevent="handleSubmit">
+ Send
+ <i class="send icon"></i>
+ </button>
+ </div>
+ </div>
+ `
+}
\ No newline at end of file
diff --git a/src/views/index.html b/src/views/index.html
index b846045d..d4ad0bfe 100644
--- a/src/views/index.html
+++ b/src/views/index.html
@@ -80,6 +80,7 @@
<send-poll></send-poll>
<send-presence></send-presence>
+ <send-chat-presence></send-chat-presence>
<send-link></send-link>
</div>
@@ -180,6 +181,7 @@
import SendAudio from "./components/SendAudio.js";
import SendPoll from "./components/SendPoll.js";
import SendPresence from "./components/SendPresence.js";
+ import SendChatPresence from "./components/SendChatPresence.js";
import MessageDelete from "./components/MessageDelete.js";
import MessageUpdate from "./components/MessageUpdate.js";
import MessageReact from "./components/MessageReact.js";
@@ -235,7 +237,7 @@
Vue.createApp({
components: {
AppLogin, AppLoginWithCode, AppLogout, AppReconnect,
- SendMessage, SendImage, SendFile, SendVideo, SendLink, SendContact, SendLocation, SendAudio, SendPoll, SendPresence,
+ SendMessage, SendImage, SendFile, SendVideo, SendLink, SendContact, SendLocation, SendAudio, SendPoll, SendPresence, SendChatPresence,
MessageDelete, MessageUpdate, MessageReact, MessageRevoke,
GroupList, GroupCreate, GroupJoinWithLink, GroupAddParticipants, GroupSetPhoto, GroupSetName, GroupSetLocked, GroupSetAnnounce, GroupSetTopic,
NewsletterList,