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.

Resolve send API duration issue (#316)

Aldino Kemal614dcdb4b840
diff --git a/docs/openapi.yaml b/docs/openapi.yaml
index 46a87d16..479e7ea9 100644
--- a/docs/openapi.yaml
+++ b/docs/openapi.yaml
@@ -1,7 +1,7 @@
openapi: "3.0.0"
info:
title: WhatsApp API MultiDevice
- version: 6.3.0
+ version: 6.4.0
description: This API is used for sending whatsapp via API
servers:
- url: http://localhost:3000
@@ -409,6 +409,10 @@ paths:
type: boolean
example: false
description: Whether this is a forwarded message
+ duration:
+ type: integer
+ example: 3600
+ description: Disappearing message duration in seconds (optional)
responses:
'200':
description: OK
@@ -464,6 +468,10 @@ paths:
type: boolean
example: false
description: Compress image
+ duration:
+ type: integer
+ example: 3600
+ description: Disappearing message duration in seconds (optional)
is_forwarded:
type: boolean
example: false
@@ -515,6 +523,10 @@ paths:
type: boolean
example: false
description: Whether this is a forwarded message
+ duration:
+ type: integer
+ example: 3600
+ description: Disappearing message duration in seconds (optional)
responses:
'200':
description: OK
@@ -562,6 +574,10 @@ paths:
type: boolean
example: false
description: Whether this is a forwarded message
+ duration:
+ type: integer
+ example: 3600
+ description: Disappearing message duration in seconds (optional)
responses:
'200':
description: OK
@@ -617,6 +633,10 @@ paths:
type: boolean
example: false
description: Compress video
+ duration:
+ type: integer
+ example: 3600
+ description: Disappearing message duration in seconds (optional)
is_forwarded:
type: boolean
example: false
@@ -668,6 +688,10 @@ paths:
type: boolean
example: false
description: Whether this is a forwarded message
+ duration:
+ type: integer
+ example: 3600
+ description: Disappearing message duration in seconds (optional)
responses:
'200':
description: OK
@@ -715,6 +739,10 @@ paths:
type: boolean
example: false
description: Whether this is a forwarded message
+ duration:
+ type: integer
+ example: 3600
+ description: Disappearing message duration in seconds (optional)
responses:
'200':
description: OK
@@ -762,6 +790,10 @@ paths:
type: boolean
example: false
description: Whether this is a forwarded message
+ duration:
+ type: integer
+ example: 3600
+ description: Disappearing message duration in seconds (optional)
responses:
'200':
description: OK
@@ -812,6 +844,10 @@ paths:
type: integer
description: The maximum number of answers allowed for the poll.
example: 2
+ duration:
+ type: integer
+ example: 3600
+ description: Disappearing message duration in seconds (optional)
required:
- phone
- question
diff --git a/readme.md b/readme.md
index 980e144e..eadbe7bb 100644
--- a/readme.md
+++ b/readme.md
@@ -4,7 +4,7 @@
<!-- markdownlint-disable-next-line MD033 -->
<img src="src/views/assets/gowa.svg" alt="GoWA Logo" width="200" height="200">
-# WhatsApp API Multi Device Version
+## Golang WhatsApp - Built in Go for efficient memory use
</div>
diff --git a/src/domains/send/audio.go b/src/domains/send/audio.go
index f3467aa5..7d61d410 100644
--- a/src/domains/send/audio.go
+++ b/src/domains/send/audio.go
@@ -3,8 +3,7 @@ package send
import "mime/multipart"
type AudioRequest struct {
- Phone string `json:"phone" form:"phone"`
+ BaseRequest
Audio *multipart.FileHeader `json:"audio" form:"audio"`
AudioURL *string `json:"audio_url" form:"audio_url"`
- IsForwarded bool `json:"is_forwarded" form:"is_forwarded"`
}
diff --git a/src/domains/send/base.go b/src/domains/send/base.go
new file mode 100644
index 00000000..48bb07af
--- /dev/null
+++ b/src/domains/send/base.go
@@ -0,0 +1,7 @@
+package send
+
+type BaseRequest struct {
+ Phone string `json:"phone" form:"phone"`
+ Duration *int `json:"duration,omitempty" form:"duration"`
+ IsForwarded bool `json:"is_forwarded,omitempty" form:"is_forwarded"`
+}
\ No newline at end of file
diff --git a/src/domains/send/contact.go b/src/domains/send/contact.go
index 8840e800..c57dd192 100644
--- a/src/domains/send/contact.go
+++ b/src/domains/send/contact.go
@@ -1,8 +1,7 @@
package send
type ContactRequest struct {
- Phone string `json:"phone" form:"phone"`
+ BaseRequest
ContactName string `json:"contact_name" form:"contact_name"`
ContactPhone string `json:"contact_phone" form:"contact_phone"`
- IsForwarded bool `json:"is_forwarded" form:"is_forwarded"`
}
diff --git a/src/domains/send/file.go b/src/domains/send/file.go
index 663fea2c..5a01320c 100644
--- a/src/domains/send/file.go
+++ b/src/domains/send/file.go
@@ -3,8 +3,7 @@ package send
import "mime/multipart"
type FileRequest struct {
- Phone string `json:"phone" form:"phone"`
+ BaseRequest
File *multipart.FileHeader `json:"file" form:"file"`
Caption string `json:"caption" form:"caption"`
- IsForwarded bool `json:"is_forwarded" form:"is_forwarded"`
}
diff --git a/src/domains/send/image.go b/src/domains/send/image.go
index 18450b27..b47c83cb 100644
--- a/src/domains/send/image.go
+++ b/src/domains/send/image.go
@@ -3,11 +3,10 @@ package send
import "mime/multipart"
type ImageRequest struct {
- Phone string `json:"phone" form:"phone"`
+ BaseRequest
Caption string `json:"caption" form:"caption"`
Image *multipart.FileHeader `json:"image" form:"image"`
ImageURL *string `json:"image_url" form:"image_url"`
ViewOnce bool `json:"view_once" form:"view_once"`
Compress bool `json:"compress"`
- IsForwarded bool `json:"is_forwarded" form:"is_forwarded"`
}
diff --git a/src/domains/send/link.go b/src/domains/send/link.go
index 7979bf1b..2d42e81f 100644
--- a/src/domains/send/link.go
+++ b/src/domains/send/link.go
@@ -1,8 +1,7 @@
package send
type LinkRequest struct {
- Phone string `json:"phone" form:"phone"`
+ BaseRequest
Caption string `json:"caption"`
Link string `json:"link"`
- IsForwarded bool `json:"is_forwarded" form:"is_forwarded"`
}
diff --git a/src/domains/send/location.go b/src/domains/send/location.go
index 3d8a6617..337eba76 100644
--- a/src/domains/send/location.go
+++ b/src/domains/send/location.go
@@ -1,8 +1,7 @@
package send
type LocationRequest struct {
- Phone string `json:"phone" form:"phone"`
- Latitude string `json:"latitude" form:"latitude"`
- Longitude string `json:"longitude" form:"longitude"`
- IsForwarded bool `json:"is_forwarded" form:"is_forwarded"`
+ BaseRequest
+ Latitude string `json:"latitude" form:"latitude"`
+ Longitude string `json:"longitude" form:"longitude"`
}
diff --git a/src/domains/send/poll.go b/src/domains/send/poll.go
index f3f8c32f..a6ff9721 100644
--- a/src/domains/send/poll.go
+++ b/src/domains/send/poll.go
@@ -1,7 +1,7 @@
package send
type PollRequest struct {
- Phone string `json:"phone" form:"phone"`
+ BaseRequest
Question string `json:"question" form:"question"`
Options []string `json:"options" form:"options"`
MaxAnswer int `json:"max_answer" form:"max_answer"`
diff --git a/src/domains/send/text.go b/src/domains/send/text.go
index d5a15c3c..7cfd8b2a 100644
--- a/src/domains/send/text.go
+++ b/src/domains/send/text.go
@@ -1,8 +1,7 @@
package send
type MessageRequest struct {
- Phone string `json:"phone" form:"phone"`
+ BaseRequest
Message string `json:"message" form:"message"`
- IsForwarded bool `json:"is_forwarded" form:"is_forwarded"`
ReplyMessageID *string `json:"reply_message_id" form:"reply_message_id"`
}
diff --git a/src/domains/send/video.go b/src/domains/send/video.go
index 4ce4bb83..362ee8e9 100644
--- a/src/domains/send/video.go
+++ b/src/domains/send/video.go
@@ -3,11 +3,10 @@ package send
import "mime/multipart"
type VideoRequest struct {
- Phone string `json:"phone" form:"phone"`
+ BaseRequest
Caption string `json:"caption" form:"caption"`
Video *multipart.FileHeader `json:"video" form:"video"`
ViewOnce bool `json:"view_once" form:"view_once"`
Compress bool `json:"compress"`
- IsForwarded bool `json:"is_forwarded" form:"is_forwarded"`
VideoURL *string `json:"video_url" form:"video_url"`
}
diff --git a/src/infrastructure/whatsapp/init.go b/src/infrastructure/whatsapp/init.go
index 1eea4bb1..3d605c60 100644
--- a/src/infrastructure/whatsapp/init.go
+++ b/src/infrastructure/whatsapp/init.go
@@ -315,6 +315,6 @@ func handleHistorySync(_ context.Context, evt *events.HistorySync) {
log.Infof("Wrote history sync to %s", fileName)
}
-func handleAppState(ctx context.Context, evt *events.AppState) {
+func handleAppState(_ context.Context, evt *events.AppState) {
log.Debugf("App state event: %+v / %+v", evt.Index, evt.SyncActionValue)
}
diff --git a/src/ui/mcp/send.go b/src/ui/mcp/send.go
index 6f7edfca..e7b6194d 100644
--- a/src/ui/mcp/send.go
+++ b/src/ui/mcp/send.go
@@ -72,9 +72,11 @@ func (s *SendHandler) handleSendText(ctx context.Context, request mcp.CallToolRe
}
res, err := s.sendService.SendText(ctx, domainSend.MessageRequest{
- Phone: phone,
+ BaseRequest: domainSend.BaseRequest{
+ Phone: phone,
+ IsForwarded: isForwarded,
+ },
Message: message,
- IsForwarded: isForwarded,
ReplyMessageID: &replyMessageId,
})
@@ -130,10 +132,12 @@ func (s *SendHandler) handleSendContact(ctx context.Context, request mcp.CallToo
}
res, err := s.sendService.SendContact(ctx, domainSend.ContactRequest{
- Phone: phone,
+ BaseRequest: domainSend.BaseRequest{
+ Phone: phone,
+ IsForwarded: isForwarded,
+ },
ContactName: contactName,
ContactPhone: contactPhone,
- IsForwarded: isForwarded,
})
if err != nil {
@@ -188,10 +192,12 @@ func (s *SendHandler) handleSendLink(ctx context.Context, request mcp.CallToolRe
}
res, err := s.sendService.SendLink(ctx, domainSend.LinkRequest{
- Phone: phone,
- Link: link,
- Caption: caption,
- IsForwarded: isForwarded,
+ BaseRequest: domainSend.BaseRequest{
+ Phone: phone,
+ IsForwarded: isForwarded,
+ },
+ Link: link,
+ Caption: caption,
})
if err != nil {
@@ -246,10 +252,12 @@ func (s *SendHandler) handleSendLocation(ctx context.Context, request mcp.CallTo
}
res, err := s.sendService.SendLocation(ctx, domainSend.LocationRequest{
- Phone: phone,
- Latitude: latitude,
- Longitude: longitude,
- IsForwarded: isForwarded,
+ BaseRequest: domainSend.BaseRequest{
+ Phone: phone,
+ IsForwarded: isForwarded,
+ },
+ Latitude: latitude,
+ Longitude: longitude,
})
if err != nil {
@@ -319,11 +327,13 @@ func (s *SendHandler) handleSendImage(ctx context.Context, request mcp.CallToolR
// Create image request
imageRequest := domainSend.ImageRequest{
- Phone: phone,
- Caption: caption,
- ViewOnce: viewOnce,
- Compress: compress,
- IsForwarded: isForwarded,
+ BaseRequest: domainSend.BaseRequest{
+ Phone: phone,
+ IsForwarded: isForwarded,
+ },
+ Caption: caption,
+ ViewOnce: viewOnce,
+ Compress: compress,
}
if imageURLOk && imageURL != "" {
diff --git a/src/usecase/send.go b/src/usecase/send.go
index e9a945ca..8056e216 100644
--- a/src/usecase/send.go
+++ b/src/usecase/send.go
@@ -54,7 +54,7 @@ func (service serviceSend) SendText(ctx context.Context, request domainSend.Mess
if err != nil {
return response, err
}
- dataWaRecipient, err := whatsapp.ValidateJidWithLogin(service.WaCli, request.Phone)
+ dataWaRecipient, err := whatsapp.ValidateJidWithLogin(service.WaCli, request.BaseRequest.Phone)
if err != nil {
return response, err
}
@@ -68,11 +68,16 @@ func (service serviceSend) SendText(ctx context.Context, request domainSend.Mess
}
// Add forwarding context if IsForwarded is true
- if request.IsForwarded {
+ if request.BaseRequest.IsForwarded {
msg.ExtendedTextMessage.ContextInfo.IsForwarded = proto.Bool(true)
msg.ExtendedTextMessage.ContextInfo.ForwardingScore = proto.Uint32(100)
}
+ // Set disappearing message duration if provided
+ if request.BaseRequest.Duration != nil && *request.BaseRequest.Duration > 0 {
+ msg.ExtendedTextMessage.ContextInfo.Expiration = proto.Uint32(uint32(*request.BaseRequest.Duration))
+ }
+
parsedMentions := service.getMentionFromText(ctx, request.Message)
if len(parsedMentions) > 0 {
msg.ExtendedTextMessage.ContextInfo.MentionedJID = parsedMentions
@@ -82,19 +87,34 @@ func (service serviceSend) SendText(ctx context.Context, request domainSend.Mess
if request.ReplyMessageID != nil && *request.ReplyMessageID != "" {
record, err := utils.FindRecordFromStorage(*request.ReplyMessageID)
if err == nil { // Only set reply context if we found the message ID
- msg.ExtendedTextMessage = &waE2E.ExtendedTextMessage{
- Text: proto.String(request.Message),
- ContextInfo: &waE2E.ContextInfo{
- StanzaID: request.ReplyMessageID,
- Participant: proto.String(record.JID),
- QuotedMessage: &waE2E.Message{
- Conversation: proto.String(record.MessageContent),
- },
+ // Build base ContextInfo with reply details
+ ctxInfo := &waE2E.ContextInfo{
+ StanzaID: request.ReplyMessageID,
+ Participant: proto.String(record.JID),
+ QuotedMessage: &waE2E.Message{
+ Conversation: proto.String(record.MessageContent),
},
}
+ // Preserve forwarding flag if set
+ if request.BaseRequest.IsForwarded {
+ ctxInfo.IsForwarded = proto.Bool(true)
+ ctxInfo.ForwardingScore = proto.Uint32(100)
+ }
+
+ // Preserve disappearing message duration if provided
+ if request.BaseRequest.Duration != nil && *request.BaseRequest.Duration > 0 {
+ ctxInfo.Expiration = proto.Uint32(uint32(*request.BaseRequest.Duration))
+ }
+
+ // Preserve mentions
if len(parsedMentions) > 0 {
- msg.ExtendedTextMessage.ContextInfo.MentionedJID = parsedMentions
+ ctxInfo.MentionedJID = parsedMentions
+ }
+
+ msg.ExtendedTextMessage = &waE2E.ExtendedTextMessage{
+ Text: proto.String(request.Message),
+ ContextInfo: ctxInfo,
}
} else {
logrus.Warnf("Reply message ID %s not found in storage, continuing without reply context", *request.ReplyMessageID)
@@ -212,13 +232,21 @@ func (service serviceSend) SendImage(ctx context.Context, request domainSend.Ima
ViewOnce: proto.Bool(request.ViewOnce),
}}
- if request.IsForwarded {
+ if request.BaseRequest.IsForwarded {
msg.ImageMessage.ContextInfo = &waE2E.ContextInfo{
IsForwarded: proto.Bool(true),
ForwardingScore: proto.Uint32(100),
}
}
+ // Set duration expiration
+ if request.BaseRequest.Duration != nil && *request.BaseRequest.Duration > 0 {
+ if msg.ImageMessage.ContextInfo == nil {
+ msg.ImageMessage.ContextInfo = &waE2E.ContextInfo{}
+ }
+ msg.ImageMessage.ContextInfo.Expiration = proto.Uint32(uint32(*request.BaseRequest.Duration))
+ }
+
caption := "πŸ–ΌοΈ Image"
if request.Caption != "" {
caption = "πŸ–ΌοΈ " + request.Caption
@@ -235,7 +263,7 @@ func (service serviceSend) SendImage(ctx context.Context, request domainSend.Ima
}
response.MessageID = ts.ID
- response.Status = fmt.Sprintf("Message sent to %s (server timestamp: %s)", request.Phone, ts.Timestamp.String())
+ response.Status = fmt.Sprintf("Message sent to %s (server timestamp: %s)", request.BaseRequest.Phone, ts.Timestamp.String())
return response, nil
}
@@ -244,7 +272,7 @@ func (service serviceSend) SendFile(ctx context.Context, request domainSend.File
if err != nil {
return response, err
}
- dataWaRecipient, err := whatsapp.ValidateJidWithLogin(service.WaCli, request.Phone)
+ dataWaRecipient, err := whatsapp.ValidateJidWithLogin(service.WaCli, request.BaseRequest.Phone)
if err != nil {
return response, err
}
@@ -272,13 +300,20 @@ func (service serviceSend) SendFile(ctx context.Context, request domainSend.File
Caption: proto.String(request.Caption),
}}
- if request.IsForwarded {
+ if request.BaseRequest.IsForwarded {
msg.DocumentMessage.ContextInfo = &waE2E.ContextInfo{
IsForwarded: proto.Bool(true),
ForwardingScore: proto.Uint32(100),
}
}
+ if request.BaseRequest.Duration != nil && *request.BaseRequest.Duration > 0 {
+ if msg.DocumentMessage.ContextInfo == nil {
+ msg.DocumentMessage.ContextInfo = &waE2E.ContextInfo{}
+ }
+ msg.DocumentMessage.ContextInfo.Expiration = proto.Uint32(uint32(*request.BaseRequest.Duration))
+ }
+
caption := "πŸ“„ Document"
if request.Caption != "" {
caption = "πŸ“„ " + request.Caption
@@ -289,7 +324,7 @@ func (service serviceSend) SendFile(ctx context.Context, request domainSend.File
}
response.MessageID = ts.ID
- response.Status = fmt.Sprintf("Document sent to %s (server timestamp: %s)", request.Phone, ts.Timestamp.String())
+ response.Status = fmt.Sprintf("Document sent to %s (server timestamp: %s)", request.BaseRequest.Phone, ts.Timestamp.String())
return response, nil
}
@@ -298,7 +333,7 @@ func (service serviceSend) SendVideo(ctx context.Context, request domainSend.Vid
if err != nil {
return response, err
}
- dataWaRecipient, err := whatsapp.ValidateJidWithLogin(service.WaCli, request.Phone)
+ dataWaRecipient, err := whatsapp.ValidateJidWithLogin(service.WaCli, request.BaseRequest.Phone)
if err != nil {
return response, err
}
@@ -440,13 +475,20 @@ func (service serviceSend) SendVideo(ctx context.Context, request domainSend.Vid
ThumbnailDirectPath: proto.String(uploaded.DirectPath),
}}
- if request.IsForwarded {
+ if request.BaseRequest.IsForwarded {
msg.VideoMessage.ContextInfo = &waE2E.ContextInfo{
IsForwarded: proto.Bool(true),
ForwardingScore: proto.Uint32(100),
}
}
+ if request.BaseRequest.Duration != nil && *request.BaseRequest.Duration > 0 {
+ if msg.VideoMessage.ContextInfo == nil {
+ msg.VideoMessage.ContextInfo = &waE2E.ContextInfo{}
+ }
+ msg.VideoMessage.ContextInfo.Expiration = proto.Uint32(uint32(*request.BaseRequest.Duration))
+ }
+
caption := "πŸŽ₯ Video"
if request.Caption != "" {
caption = "πŸŽ₯ " + request.Caption
@@ -457,7 +499,7 @@ func (service serviceSend) SendVideo(ctx context.Context, request domainSend.Vid
}
response.MessageID = ts.ID
- response.Status = fmt.Sprintf("Video sent to %s (server timestamp: %s)", request.Phone, ts.Timestamp.String())
+ response.Status = fmt.Sprintf("Video sent to %s (server timestamp: %s)", request.BaseRequest.Phone, ts.Timestamp.String())
return response, nil
}
@@ -466,7 +508,7 @@ func (service serviceSend) SendContact(ctx context.Context, request domainSend.C
if err != nil {
return response, err
}
- dataWaRecipient, err := whatsapp.ValidateJidWithLogin(service.WaCli, request.Phone)
+ dataWaRecipient, err := whatsapp.ValidateJidWithLogin(service.WaCli, request.BaseRequest.Phone)
if err != nil {
return response, err
}
@@ -478,13 +520,20 @@ func (service serviceSend) SendContact(ctx context.Context, request domainSend.C
Vcard: proto.String(msgVCard),
}}
- if request.IsForwarded {
+ if request.BaseRequest.IsForwarded {
msg.ContactMessage.ContextInfo = &waE2E.ContextInfo{
IsForwarded: proto.Bool(true),
ForwardingScore: proto.Uint32(100),
}
}
+ if request.BaseRequest.Duration != nil && *request.BaseRequest.Duration > 0 {
+ if msg.ContactMessage.ContextInfo == nil {
+ msg.ContactMessage.ContextInfo = &waE2E.ContextInfo{}
+ }
+ msg.ContactMessage.ContextInfo.Expiration = proto.Uint32(uint32(*request.BaseRequest.Duration))
+ }
+
content := "πŸ‘€ " + request.ContactName
ts, err := service.wrapSendMessage(ctx, dataWaRecipient, msg, content)
@@ -493,7 +542,7 @@ func (service serviceSend) SendContact(ctx context.Context, request domainSend.C
}
response.MessageID = ts.ID
- response.Status = fmt.Sprintf("Contact sent to %s (server timestamp: %s)", request.Phone, ts.Timestamp.String())
+ response.Status = fmt.Sprintf("Contact sent to %s (server timestamp: %s)", request.BaseRequest.Phone, ts.Timestamp.String())
return response, nil
}
@@ -502,7 +551,7 @@ func (service serviceSend) SendLink(ctx context.Context, request domainSend.Link
if err != nil {
return response, err
}
- dataWaRecipient, err := whatsapp.ValidateJidWithLogin(service.WaCli, request.Phone)
+ dataWaRecipient, err := whatsapp.ValidateJidWithLogin(service.WaCli, request.BaseRequest.Phone)
if err != nil {
return response, err
}
@@ -528,13 +577,20 @@ func (service serviceSend) SendLink(ctx context.Context, request domainSend.Link
JPEGThumbnail: metadata.ImageThumb,
}}
- if request.IsForwarded {
+ if request.BaseRequest.IsForwarded {
msg.ExtendedTextMessage.ContextInfo = &waE2E.ContextInfo{
IsForwarded: proto.Bool(true),
ForwardingScore: proto.Uint32(100),
}
}
+ if request.BaseRequest.Duration != nil && *request.BaseRequest.Duration > 0 {
+ if msg.ExtendedTextMessage.ContextInfo == nil {
+ msg.ExtendedTextMessage.ContextInfo = &waE2E.ContextInfo{}
+ }
+ msg.ExtendedTextMessage.ContextInfo.Expiration = proto.Uint32(uint32(*request.BaseRequest.Duration))
+ }
+
// If we have a thumbnail image, upload it to WhatsApp's servers
if len(metadata.ImageThumb) > 0 && metadata.Height != nil && metadata.Width != nil {
uploadedThumb, err := service.uploadMedia(ctx, whatsmeow.MediaLinkThumbnail, metadata.ImageThumb, dataWaRecipient)
@@ -561,7 +617,7 @@ func (service serviceSend) SendLink(ctx context.Context, request domainSend.Link
}
response.MessageID = ts.ID
- response.Status = fmt.Sprintf("Link sent to %s (server timestamp: %s)", request.Phone, ts.Timestamp.String())
+ response.Status = fmt.Sprintf("Link sent to %s (server timestamp: %s)", request.BaseRequest.Phone, ts.Timestamp.String())
return response, nil
}
@@ -570,7 +626,7 @@ func (service serviceSend) SendLocation(ctx context.Context, request domainSend.
if err != nil {
return response, err
}
- dataWaRecipient, err := whatsapp.ValidateJidWithLogin(service.WaCli, request.Phone)
+ dataWaRecipient, err := whatsapp.ValidateJidWithLogin(service.WaCli, request.BaseRequest.Phone)
if err != nil {
return response, err
}
@@ -583,13 +639,20 @@ func (service serviceSend) SendLocation(ctx context.Context, request domainSend.
},
}
- if request.IsForwarded {
+ if request.BaseRequest.IsForwarded {
msg.LocationMessage.ContextInfo = &waE2E.ContextInfo{
IsForwarded: proto.Bool(true),
ForwardingScore: proto.Uint32(100),
}
}
+ if request.BaseRequest.Duration != nil && *request.BaseRequest.Duration > 0 {
+ if msg.LocationMessage.ContextInfo == nil {
+ msg.LocationMessage.ContextInfo = &waE2E.ContextInfo{}
+ }
+ msg.LocationMessage.ContextInfo.Expiration = proto.Uint32(uint32(*request.BaseRequest.Duration))
+ }
+
content := "πŸ“ " + request.Latitude + ", " + request.Longitude
// Send WhatsApp Message Proto
@@ -599,7 +662,7 @@ func (service serviceSend) SendLocation(ctx context.Context, request domainSend.
}
response.MessageID = ts.ID
- response.Status = fmt.Sprintf("Send location success %s (server timestamp: %s)", request.Phone, ts.Timestamp.String())
+ response.Status = fmt.Sprintf("Send location success %s (server timestamp: %s)", request.BaseRequest.Phone, ts.Timestamp.String())
return response, nil
}
@@ -610,7 +673,7 @@ func (service serviceSend) SendAudio(ctx context.Context, request domainSend.Aud
return response, err
}
- dataWaRecipient, err := whatsapp.ValidateJidWithLogin(service.WaCli, request.Phone)
+ dataWaRecipient, err := whatsapp.ValidateJidWithLogin(service.WaCli, request.BaseRequest.Phone)
if err != nil {
return response, err
}
@@ -651,13 +714,20 @@ func (service serviceSend) SendAudio(ctx context.Context, request domainSend.Aud
},
}
- if request.IsForwarded {
+ if request.BaseRequest.IsForwarded {
msg.AudioMessage.ContextInfo = &waE2E.ContextInfo{
IsForwarded: proto.Bool(true),
ForwardingScore: proto.Uint32(100),
}
}
+ if request.BaseRequest.Duration != nil && *request.BaseRequest.Duration > 0 {
+ if msg.AudioMessage.ContextInfo == nil {
+ msg.AudioMessage.ContextInfo = &waE2E.ContextInfo{}
+ }
+ msg.AudioMessage.ContextInfo.Expiration = proto.Uint32(uint32(*request.BaseRequest.Duration))
+ }
+
content := "🎡 Audio"
ts, err := service.wrapSendMessage(ctx, dataWaRecipient, msg, content)
@@ -666,7 +736,7 @@ func (service serviceSend) SendAudio(ctx context.Context, request domainSend.Aud
}
response.MessageID = ts.ID
- response.Status = fmt.Sprintf("Send audio success %s (server timestamp: %s)", request.Phone, ts.Timestamp.String())
+ response.Status = fmt.Sprintf("Send audio success %s (server timestamp: %s)", request.BaseRequest.Phone, ts.Timestamp.String())
return response, nil
}
@@ -675,7 +745,7 @@ func (service serviceSend) SendPoll(ctx context.Context, request domainSend.Poll
if err != nil {
return response, err
}
- dataWaRecipient, err := whatsapp.ValidateJidWithLogin(service.WaCli, request.Phone)
+ dataWaRecipient, err := whatsapp.ValidateJidWithLogin(service.WaCli, request.BaseRequest.Phone)
if err != nil {
return response, err
}
@@ -684,13 +754,20 @@ func (service serviceSend) SendPoll(ctx context.Context, request domainSend.Poll
msg := service.WaCli.BuildPollCreation(request.Question, request.Options, request.MaxAnswer)
+ if request.BaseRequest.Duration != nil && *request.BaseRequest.Duration > 0 {
+ if msg.PollCreationMessage.ContextInfo == nil {
+ msg.PollCreationMessage.ContextInfo = &waE2E.ContextInfo{}
+ }
+ msg.PollCreationMessage.ContextInfo.Expiration = proto.Uint32(uint32(*request.BaseRequest.Duration))
+ }
+
ts, err := service.wrapSendMessage(ctx, dataWaRecipient, msg, content)
if err != nil {
return response, err
}
response.MessageID = ts.ID
- response.Status = fmt.Sprintf("Send poll success %s (server timestamp: %s)", request.Phone, ts.Timestamp.String())
+ response.Status = fmt.Sprintf("Send poll success %s (server timestamp: %s)", request.BaseRequest.Phone, ts.Timestamp.String())
return response, nil
}
diff --git a/src/validations/send_validation.go b/src/validations/send_validation.go
index d2d8680a..da284a40 100644
--- a/src/validations/send_validation.go
+++ b/src/validations/send_validation.go
@@ -22,6 +22,11 @@ func ValidateSendMessage(ctx context.Context, request domainSend.MessageRequest)
if err != nil {
return pkgError.ValidationError(err.Error())
}
+
+ // Custom validation for optional Duration
+ if request.Duration != nil && (*request.Duration < 0 || *request.Duration > 4294967295) {
+ return pkgError.ValidationError("duration must be between 0 and 4294967295 seconds (0 means no expiry)")
+ }
return nil
}
@@ -61,6 +66,11 @@ func ValidateSendImage(ctx context.Context, request domainSend.ImageRequest) err
}
}
+ // Validate duration
+ if request.Duration != nil && (*request.Duration < 0 || *request.Duration > 4294967295) {
+ return pkgError.ValidationError("duration must be between 0 and 4294967295 seconds (0 means no expiry)")
+ }
+
return nil
}
@@ -79,6 +89,10 @@ func ValidateSendFile(ctx context.Context, request domainSend.FileRequest) error
return pkgError.ValidationError(fmt.Sprintf("max file upload is %s, please upload in cloud and send via text if your file is higher than %s", maxSizeString, maxSizeString))
}
+ if request.Duration != nil && (*request.Duration < 0 || *request.Duration > 4294967295) {
+ return pkgError.ValidationError("duration must be between 0 and 4294967295 seconds (0 means no expiry)")
+ }
+
return nil
}
@@ -127,6 +141,10 @@ func ValidateSendVideo(ctx context.Context, request domainSend.VideoRequest) err
}
}
+ if request.Duration != nil && (*request.Duration < 0 || *request.Duration > 4294967295) {
+ return pkgError.ValidationError("duration must be between 0 and 4294967295 seconds (0 means no expiry)")
+ }
+
return nil
}
@@ -141,6 +159,10 @@ func ValidateSendContact(ctx context.Context, request domainSend.ContactRequest)
return pkgError.ValidationError(err.Error())
}
+ if request.Duration != nil && (*request.Duration < 0 || *request.Duration > 4294967295) {
+ return pkgError.ValidationError("duration must be between 0 and 4294967295 seconds (0 means no expiry)")
+ }
+
return nil
}
@@ -155,6 +177,10 @@ func ValidateSendLink(ctx context.Context, request domainSend.LinkRequest) error
return pkgError.ValidationError(err.Error())
}
+ if request.Duration != nil && (*request.Duration < 0 || *request.Duration > 4294967295) {
+ return pkgError.ValidationError("duration must be between 0 and 4294967295 seconds (0 means no expiry)")
+ }
+
return nil
}
@@ -169,6 +195,10 @@ func ValidateSendLocation(ctx context.Context, request domainSend.LocationReques
return pkgError.ValidationError(err.Error())
}
+ if request.Duration != nil && (*request.Duration < 0 || *request.Duration > 4294967295) {
+ return pkgError.ValidationError("duration must be between 0 and 4294967295 seconds (0 means no expiry)")
+ }
+
return nil
}
@@ -235,6 +265,10 @@ func ValidateSendAudio(ctx context.Context, request domainSend.AudioRequest) err
}
}
+ if request.Duration != nil && (*request.Duration < 0 || *request.Duration > 4294967295) {
+ return pkgError.ValidationError("duration must be between 0 and 4294967295 seconds (0 means no expiry)")
+ }
+
return nil
}
@@ -259,6 +293,10 @@ func ValidateSendPoll(ctx context.Context, request domainSend.PollRequest) error
return pkgError.ValidationError(err.Error())
}
+ if request.Duration != nil && (*request.Duration < 0 || *request.Duration > 4294967295) {
+ return pkgError.ValidationError("duration must be between 0 and 4294967295 seconds (0 means no expiry)")
+ }
+
// validate options should be unique each other
uniqueOptions := make(map[string]bool)
for _, option := range request.Options {
diff --git a/src/validations/send_validation_test.go b/src/validations/send_validation_test.go
index ef3bf82a..b844689f 100644
--- a/src/validations/send_validation_test.go
+++ b/src/validations/send_validation_test.go
@@ -23,7 +23,9 @@ func TestValidateSendMessage(t *testing.T) {
{
name: "should success with phone and message",
args: args{request: domainSend.MessageRequest{
- Phone: "[email protected]",
+ BaseRequest: domainSend.BaseRequest{
+ Phone: "[email protected]",
+ },
Message: "Hello this is testing",
}},
err: nil,
@@ -31,7 +33,9 @@ func TestValidateSendMessage(t *testing.T) {
{
name: "should error with empty phone",
args: args{request: domainSend.MessageRequest{
- Phone: "",
+ BaseRequest: domainSend.BaseRequest{
+ Phone: "",
+ },
Message: "Hello this is testing",
}},
err: pkgError.ValidationError("phone: cannot be blank."),
@@ -39,7 +43,9 @@ func TestValidateSendMessage(t *testing.T) {
{
name: "should error with empty message",
args: args{request: domainSend.MessageRequest{
- Phone: "[email protected]",
+ BaseRequest: domainSend.BaseRequest{
+ Phone: "[email protected]",
+ },
Message: "",
}},
err: pkgError.ValidationError("message: cannot be blank."),
@@ -72,7 +78,9 @@ func TestValidateSendImage(t *testing.T) {
{
name: "should success with normal condition",
args: args{request: domainSend.ImageRequest{
- Phone: "[email protected]",
+ BaseRequest: domainSend.BaseRequest{
+ Phone: "[email protected]",
+ },
Caption: "Hello this is testing",
Image: image,
}},
@@ -81,7 +89,9 @@ func TestValidateSendImage(t *testing.T) {
{
name: "should error with empty phone",
args: args{request: domainSend.ImageRequest{
- Phone: "",
+ BaseRequest: domainSend.BaseRequest{
+ Phone: "",
+ },
Image: image,
}},
err: pkgError.ValidationError("phone: cannot be blank."),
@@ -89,7 +99,9 @@ func TestValidateSendImage(t *testing.T) {
{
name: "should error with empty image",
args: args{request: domainSend.ImageRequest{
- Phone: "[email protected]",
+ BaseRequest: domainSend.BaseRequest{
+ Phone: "[email protected]",
+ },
Image: nil,
}},
err: pkgError.ValidationError("either Image or ImageURL must be provided"),
@@ -97,7 +109,9 @@ func TestValidateSendImage(t *testing.T) {
{
name: "should error with invalid image type",
args: args{request: domainSend.ImageRequest{
- Phone: "[email protected]",
+ BaseRequest: domainSend.BaseRequest{
+ Phone: "[email protected]",
+ },
Image: &multipart.FileHeader{
Filename: "sample-image.pdf",
Size: 100,
@@ -134,24 +148,30 @@ func TestValidateSendFile(t *testing.T) {
{
name: "should success with normal condition",
args: args{request: domainSend.FileRequest{
- Phone: "[email protected]",
- File: file,
+ BaseRequest: domainSend.BaseRequest{
+ Phone: "[email protected]",
+ },
+ File: file,
}},
err: nil,
},
{
name: "should error with empty phone",
args: args{request: domainSend.FileRequest{
- Phone: "",
- File: file,
+ BaseRequest: domainSend.BaseRequest{
+ Phone: "",
+ },
+ File: file,
}},
err: pkgError.ValidationError("phone: cannot be blank."),
},
{
name: "should error with empty file",
args: args{request: domainSend.FileRequest{
- Phone: "[email protected]",
- File: nil,
+ BaseRequest: domainSend.BaseRequest{
+ Phone: "[email protected]",
+ },
+ File: nil,
}},
err: pkgError.ValidationError("file: cannot be blank."),
},
@@ -183,7 +203,9 @@ func TestValidateSendVideo(t *testing.T) {
{
name: "should success with normal condition",
args: args{request: domainSend.VideoRequest{
- Phone: "[email protected]",
+ BaseRequest: domainSend.BaseRequest{
+ Phone: "[email protected]",
+ },
Caption: "simple caption",
Video: file,
ViewOnce: false,
@@ -194,7 +216,9 @@ func TestValidateSendVideo(t *testing.T) {
{
name: "should error with empty phone",
args: args{request: domainSend.VideoRequest{
- Phone: "",
+ BaseRequest: domainSend.BaseRequest{
+ Phone: "",
+ },
Caption: "simple caption",
Video: file,
ViewOnce: false,
@@ -205,7 +229,9 @@ func TestValidateSendVideo(t *testing.T) {
{
name: "should error with empty video",
args: args{request: domainSend.VideoRequest{
- Phone: "[email protected]",
+ BaseRequest: domainSend.BaseRequest{
+ Phone: "[email protected]",
+ },
Caption: "simple caption",
Video: nil,
ViewOnce: false,
@@ -216,7 +242,9 @@ func TestValidateSendVideo(t *testing.T) {
{
name: "should error with invalid format video",
args: args{request: domainSend.VideoRequest{
- Phone: "[email protected]",
+ BaseRequest: domainSend.BaseRequest{
+ Phone: "[email protected]",
+ },
Caption: "simple caption",
Video: func() *multipart.FileHeader {
return &multipart.FileHeader{
@@ -233,7 +261,9 @@ func TestValidateSendVideo(t *testing.T) {
{
name: "should error with empty video and video_url",
args: args{request: domainSend.VideoRequest{
- Phone: "[email protected]",
+ BaseRequest: domainSend.BaseRequest{
+ Phone: "[email protected]",
+ },
Caption: "simple caption",
Video: nil,
VideoURL: func() *string { s := ""; return &s }(),
@@ -245,7 +275,9 @@ func TestValidateSendVideo(t *testing.T) {
{
name: "should success with video_url provided",
args: args{request: domainSend.VideoRequest{
- Phone: "[email protected]",
+ BaseRequest: domainSend.BaseRequest{
+ Phone: "[email protected]",
+ },
Caption: "simple caption",
Video: nil,
VideoURL: func() *string { s := "https://example.com/sample.mp4"; return &s }(),
@@ -276,7 +308,9 @@ func TestValidateSendLink(t *testing.T) {
{
name: "should success normal condition",
args: args{request: domainSend.LinkRequest{
- Phone: "[email protected]",
+ BaseRequest: domainSend.BaseRequest{
+ Phone: "[email protected]",
+ },
Caption: "description",
Link: "https://google.com",
}},
@@ -285,7 +319,9 @@ func TestValidateSendLink(t *testing.T) {
{
name: "should error with empty phone",
args: args{request: domainSend.LinkRequest{
- Phone: "",
+ BaseRequest: domainSend.BaseRequest{
+ Phone: "",
+ },
Caption: "description",
Link: "https://google.com",
}},
@@ -294,7 +330,9 @@ func TestValidateSendLink(t *testing.T) {
{
name: "should error with empty caption",
args: args{request: domainSend.LinkRequest{
- Phone: "[email protected]",
+ BaseRequest: domainSend.BaseRequest{
+ Phone: "[email protected]",
+ },
Caption: "",
Link: "https://google.com",
}},
@@ -303,7 +341,9 @@ func TestValidateSendLink(t *testing.T) {
{
name: "should error with empty link",
args: args{request: domainSend.LinkRequest{
- Phone: "[email protected]",
+ BaseRequest: domainSend.BaseRequest{
+ Phone: "[email protected]",
+ },
Caption: "description",
Link: "",
}},
@@ -312,7 +352,9 @@ func TestValidateSendLink(t *testing.T) {
{
name: "should error with invalid link",
args: args{request: domainSend.LinkRequest{
- Phone: "[email protected]",
+ BaseRequest: domainSend.BaseRequest{
+ Phone: "[email protected]",
+ },
Caption: "description",
Link: "googlecom",
}},
@@ -438,7 +480,9 @@ func TestValidateSendContact(t *testing.T) {
{
name: "should success normal condition",
args: args{request: domainSend.ContactRequest{
- Phone: "[email protected]",
+ BaseRequest: domainSend.BaseRequest{
+ Phone: "[email protected]",
+ },
ContactName: "Aldino",
ContactPhone: "62788712738123",
}},
@@ -447,7 +491,9 @@ func TestValidateSendContact(t *testing.T) {
{
name: "should error with empty phone",
args: args{request: domainSend.ContactRequest{
- Phone: "",
+ BaseRequest: domainSend.BaseRequest{
+ Phone: "",
+ },
ContactName: "Aldino",
ContactPhone: "62788712738123",
}},
@@ -456,7 +502,9 @@ func TestValidateSendContact(t *testing.T) {
{
name: "should error with empty contact name",
args: args{request: domainSend.ContactRequest{
- Phone: "[email protected]",
+ BaseRequest: domainSend.BaseRequest{
+ Phone: "[email protected]",
+ },
ContactName: "",
ContactPhone: "62788712738123",
}},
@@ -465,7 +513,9 @@ func TestValidateSendContact(t *testing.T) {
{
name: "should error with empty contact phone",
args: args{request: domainSend.ContactRequest{
- Phone: "[email protected]",
+ BaseRequest: domainSend.BaseRequest{
+ Phone: "[email protected]",
+ },
ContactName: "Aldino",
ContactPhone: "",
}},
@@ -493,7 +543,9 @@ func TestValidateSendLocation(t *testing.T) {
{
name: "should success normal condition",
args: args{request: domainSend.LocationRequest{
- Phone: "[email protected]",
+ BaseRequest: domainSend.BaseRequest{
+ Phone: "[email protected]",
+ },
Latitude: "-7.797068",
Longitude: "110.370529",
}},
@@ -502,7 +554,9 @@ func TestValidateSendLocation(t *testing.T) {
{
name: "should error with empty phone",
args: args{request: domainSend.LocationRequest{
- Phone: "",
+ BaseRequest: domainSend.BaseRequest{
+ Phone: "",
+ },
Latitude: "-7.797068",
Longitude: "110.370529",
}},
@@ -511,7 +565,9 @@ func TestValidateSendLocation(t *testing.T) {
{
name: "should error with empty latitude",
args: args{request: domainSend.LocationRequest{
- Phone: "[email protected]",
+ BaseRequest: domainSend.BaseRequest{
+ Phone: "[email protected]",
+ },
Latitude: "",
Longitude: "110.370529",
}},
@@ -520,7 +576,9 @@ func TestValidateSendLocation(t *testing.T) {
{
name: "should error with empty longitude",
args: args{request: domainSend.LocationRequest{
- Phone: "[email protected]",
+ BaseRequest: domainSend.BaseRequest{
+ Phone: "[email protected]",
+ },
Latitude: "-7.797068",
Longitude: "",
}},
@@ -529,7 +587,9 @@ func TestValidateSendLocation(t *testing.T) {
{
name: "should error with invalid latitude",
args: args{request: domainSend.LocationRequest{
- Phone: "[email protected]",
+ BaseRequest: domainSend.BaseRequest{
+ Phone: "[email protected]",
+ },
Latitude: "ABCDEF",
Longitude: "110.370529",
}},
@@ -538,7 +598,9 @@ func TestValidateSendLocation(t *testing.T) {
{
name: "should error with invalid latitude",
args: args{request: domainSend.LocationRequest{
- Phone: "[email protected]",
+ BaseRequest: domainSend.BaseRequest{
+ Phone: "[email protected]",
+ },
Latitude: "-7.797068",
Longitude: "ABCDEF",
}},
@@ -572,7 +634,9 @@ func TestValidateSendAudio(t *testing.T) {
{
name: "should success with normal condition",
args: args{request: domainSend.AudioRequest{
- Phone: "[email protected]",
+ BaseRequest: domainSend.BaseRequest{
+ Phone: "[email protected]",
+ },
Audio: audio,
}},
err: nil,
@@ -580,7 +644,9 @@ func TestValidateSendAudio(t *testing.T) {
{
name: "should error with empty phone",
args: args{request: domainSend.AudioRequest{
- Phone: "",
+ BaseRequest: domainSend.BaseRequest{
+ Phone: "",
+ },
Audio: audio,
}},
err: pkgError.ValidationError("phone: cannot be blank."),
@@ -588,7 +654,9 @@ func TestValidateSendAudio(t *testing.T) {
{
name: "should error with empty audio",
args: args{request: domainSend.AudioRequest{
- Phone: "[email protected]",
+ BaseRequest: domainSend.BaseRequest{
+ Phone: "[email protected]",
+ },
Audio: nil,
}},
err: pkgError.ValidationError("either Audio or AudioURL must be provided"),
@@ -596,7 +664,9 @@ func TestValidateSendAudio(t *testing.T) {
{
name: "should error with invalid audio type",
args: args{request: domainSend.AudioRequest{
- Phone: "[email protected]",
+ BaseRequest: domainSend.BaseRequest{
+ Phone: "[email protected]",
+ },
Audio: &multipart.FileHeader{
Filename: "sample-audio.txt",
Size: 100,
@@ -627,7 +697,9 @@ func TestValidateSendPoll(t *testing.T) {
{
name: "should success with normal condition",
args: args{request: domainSend.PollRequest{
- Phone: "[email protected]",
+ BaseRequest: domainSend.BaseRequest{
+ Phone: "[email protected]",
+ },
Question: "What is your favorite color?",
Options: []string{"Red", "Blue", "Green"},
MaxAnswer: 1,
@@ -637,7 +709,9 @@ func TestValidateSendPoll(t *testing.T) {
{
name: "should error with empty phone",
args: args{request: domainSend.PollRequest{
- Phone: "",
+ BaseRequest: domainSend.BaseRequest{
+ Phone: "",
+ },
Question: "What is your favorite color?",
Options: []string{"Red", "Blue", "Green"},
MaxAnswer: 1,
@@ -647,7 +721,9 @@ func TestValidateSendPoll(t *testing.T) {
{
name: "should error with empty question",
args: args{request: domainSend.PollRequest{
- Phone: "[email protected]",
+ BaseRequest: domainSend.BaseRequest{
+ Phone: "[email protected]",
+ },
Question: "",
Options: []string{"Red", "Blue", "Green"},
MaxAnswer: 1,
@@ -657,7 +733,9 @@ func TestValidateSendPoll(t *testing.T) {
{
name: "should error with empty options",
args: args{request: domainSend.PollRequest{
- Phone: "[email protected]",
+ BaseRequest: domainSend.BaseRequest{
+ Phone: "[email protected]",
+ },
Question: "What is your favorite color?",
Options: []string{},
MaxAnswer: 5,
@@ -667,7 +745,9 @@ func TestValidateSendPoll(t *testing.T) {
{
name: "should error with duplicate options",
args: args{request: domainSend.PollRequest{
- Phone: "[email protected]",
+ BaseRequest: domainSend.BaseRequest{
+ Phone: "[email protected]",
+ },
Question: "What is your favorite color?",
Options: []string{"Red", "Red", "Green"},
MaxAnswer: 1,
@@ -677,7 +757,9 @@ func TestValidateSendPoll(t *testing.T) {
{
name: "should error with max answer greater than options",
args: args{request: domainSend.PollRequest{
- Phone: "[email protected]",
+ BaseRequest: domainSend.BaseRequest{
+ Phone: "[email protected]",
+ },
Question: "What is your favorite color?",
Options: []string{"Red", "Blue", "Green"},
MaxAnswer: 5,
diff --git a/src/views/components/SendAudio.js b/src/views/components/SendAudio.js
index fb64dae6..71f9ec9d 100644
--- a/src/views/components/SendAudio.js
+++ b/src/views/components/SendAudio.js
@@ -13,6 +13,7 @@ export default {
selectedFileName: null,
is_forwarded: false,
audio_url: null,
+ duration: 0,
}
},
computed: {
@@ -58,6 +59,9 @@ export default {
let payload = new FormData();
payload.append("phone", this.phone_id)
payload.append("is_forwarded", this.is_forwarded)
+ if (this.duration && this.duration > 0) {
+ payload.append("duration", this.duration)
+ }
const fileInput = $("#file_audio");
if (fileInput.length > 0 && fileInput[0].files.length > 0) {
@@ -84,6 +88,7 @@ export default {
this.phone = '';
this.type = window.TYPEUSER;
this.is_forwarded = false;
+ this.duration = 0;
$("#file_audio").val('');
this.selectedFileName = null;
this.audio_url = null;
@@ -122,6 +127,10 @@ export default {
<label>Mark audio as forwarded</label>
</div>
</div>
+ <div class="field">
+ <label>Disappearing Duration (seconds)</label>
+ <input v-model.number="duration" type="number" min="0" placeholder="0 (no expiry)" aria-label="duration"/>
+ </div>
<div class="field">
<label>Audio URL</label>
<input type="text" v-model="audio_url" placeholder="https://example.com/audio.mp3"
diff --git a/src/views/components/SendContact.js b/src/views/components/SendContact.js
index 6dce006b..a9a76490 100644
--- a/src/views/components/SendContact.js
+++ b/src/views/components/SendContact.js
@@ -12,7 +12,8 @@ export default {
card_name: '',
card_phone: '',
loading: false,
- is_forwarded: false
+ is_forwarded: false,
+ duration: 0
}
},
computed: {
@@ -66,7 +67,8 @@ export default {
phone: this.phone_id,
contact_name: this.card_name,
contact_phone: this.card_phone,
- is_forwarded: this.is_forwarded
+ is_forwarded: this.is_forwarded,
+ ...(this.duration && this.duration > 0 ? {duration: this.duration} : {})
}
let response = await window.http.post(`/send/contact`, payload)
this.handleReset();
@@ -86,6 +88,7 @@ export default {
this.card_phone = '';
this.type = window.TYPEUSER;
this.is_forwarded = false;
+ this.duration = 0;
},
},
template: `
@@ -126,6 +129,10 @@ export default {
<label>Mark contact as forwarded</label>
</div>
</div>
+ <div class="field">
+ <label>Disappearing Duration (seconds)</label>
+ <input v-model.number="duration" type="number" min="0" placeholder="0 (no expiry)" aria-label="duration"/>
+ </div>
</form>
</div>
<div class="actions">
diff --git a/src/views/components/SendFile.js b/src/views/components/SendFile.js
index 22bbf0bb..64925379 100644
--- a/src/views/components/SendFile.js
+++ b/src/views/components/SendFile.js
@@ -18,7 +18,8 @@ export default {
phone: '',
loading: false,
selectedFileName: null,
- is_forwarded: false
+ is_forwarded: false,
+ duration: 0
}
},
computed: {
@@ -68,6 +69,9 @@ export default {
payload.append("caption", this.caption)
payload.append("phone", this.phone_id)
payload.append("is_forwarded", this.is_forwarded)
+ if (this.duration && this.duration > 0) {
+ payload.append("duration", this.duration)
+ }
payload.append("file", $("#file_file")[0].files[0])
let response = await window.http.post(`/send/file`, payload)
this.handleReset();
@@ -87,6 +91,7 @@ export default {
this.type = window.TYPEUSER;
this.selectedFileName = null;
this.is_forwarded = false;
+ this.duration = 0;
$("#file_file").val('');
},
handleFileChange(event) {
@@ -130,6 +135,10 @@ export default {
<label>Mark file as forwarded</label>
</div>
</div>
+ <div class="field">
+ <label>Disappearing Duration (seconds)</label>
+ <input v-model.number="duration" type="number" min="0" placeholder="0 (no expiry)" aria-label="duration"/>
+ </div>
<div class="field" style="padding-bottom: 30px">
<label>File</label>
<input type="file" style="display: none" id="file_file" @change="handleFileChange">
diff --git a/src/views/components/SendImage.js b/src/views/components/SendImage.js
index 722df8ee..e5322d41 100644
--- a/src/views/components/SendImage.js
+++ b/src/views/components/SendImage.js
@@ -16,7 +16,8 @@ export default {
selected_file: null,
image_url: null,
preview_url: null,
- is_forwarded: false
+ is_forwarded: false,
+ duration: 0
}
},
computed: {
@@ -29,6 +30,7 @@ export default {
// If view_once is set to true, set is_forwarded to false
if (newValue === true) {
this.is_forwarded = false;
+ this.duration = 0;
}
}
},
@@ -76,6 +78,9 @@ export default {
payload.append("compress", this.compress)
payload.append("caption", this.caption)
payload.append("is_forwarded", this.is_forwarded)
+ if (this.duration && this.duration > 0) {
+ payload.append("duration", this.duration)
+ }
const fileInput = $("#file_image");
if (fileInput.length > 0 && fileInput[0].files.length > 0) {
@@ -107,6 +112,7 @@ export default {
this.selected_file = null;
this.image_url = null;
this.is_forwarded = false;
+ this.duration = 0;
$("#file_image").val('');
},
handleImageChange(event) {
@@ -173,6 +179,10 @@ export default {
<label>Mark image as forwarded</label>
</div>
</div>
+ <div class="field">
+ <label>Disappearing Duration (seconds)</label>
+ <input v-model.number="duration" type="number" min="0" placeholder="0 (no expiry)" aria-label="duration"/>
+ </div>
<div class="field">
<label>Image URL</label>
<input type="text" v-model="image_url" placeholder="https://example.com/image.jpg"
diff --git a/src/views/components/SendLink.js b/src/views/components/SendLink.js
index 0c427fbb..2c44c52b 100644
--- a/src/views/components/SendLink.js
+++ b/src/views/components/SendLink.js
@@ -13,7 +13,8 @@ export default {
caption: '',
reply_message_id: '',
loading: false,
- is_forwarded: false
+ is_forwarded: false,
+ duration: 0
}
},
computed: {
@@ -64,7 +65,8 @@ export default {
phone: this.phone_id,
link: this.link.trim(),
caption: this.caption.trim(),
- is_forwarded: this.is_forwarded
+ is_forwarded: this.is_forwarded,
+ ...(this.duration && this.duration > 0 ? {duration: this.duration} : {})
};
if (this.reply_message_id !== '') {
payload.reply_message_id = this.reply_message_id;
@@ -88,6 +90,7 @@ export default {
this.caption = '';
this.reply_message_id = '';
this.is_forwarded = false;
+ this.duration = 0;
},
},
template: `
@@ -133,6 +136,10 @@ export default {
<label>Mark link as forwarded</label>
</div>
</div>
+ <div class="field">
+ <label>Disappearing Duration (seconds)</label>
+ <input v-model.number="duration" type="number" min="0" placeholder="0 (no expiry)" aria-label="duration"/>
+ </div>
</form>
</div>
<div class="actions">
diff --git a/src/views/components/SendLocation.js b/src/views/components/SendLocation.js
index 1021f800..83499a1e 100644
--- a/src/views/components/SendLocation.js
+++ b/src/views/components/SendLocation.js
@@ -12,7 +12,8 @@ export default {
latitude: '',
longitude: '',
loading: false,
- is_forwarded: false
+ is_forwarded: false,
+ duration: 0
}
},
computed: {
@@ -63,7 +64,8 @@ export default {
phone: this.phone_id,
latitude: this.latitude,
longitude: this.longitude,
- is_forwarded: this.is_forwarded
+ is_forwarded: this.is_forwarded,
+ ...(this.duration && this.duration > 0 ? {duration: this.duration} : {})
};
const response = await window.http.post(`/send/location`, payload);
@@ -84,6 +86,7 @@ export default {
this.longitude = '';
this.type = window.TYPEUSER;
this.is_forwarded = false;
+ this.duration = 0;
},
},
template: `
@@ -124,6 +127,10 @@ export default {
<label>Mark location as forwarded</label>
</div>
</div>
+ <div class="field">
+ <label>Disappearing Duration (seconds)</label>
+ <input v-model.number="duration" type="number" min="0" placeholder="0 (no expiry)" aria-label="duration"/>
+ </div>
</form>
</div>
<div class="actions">
diff --git a/src/views/components/SendMessage.js b/src/views/components/SendMessage.js
index e7993b3e..586d2fa4 100644
--- a/src/views/components/SendMessage.js
+++ b/src/views/components/SendMessage.js
@@ -12,6 +12,7 @@ export default {
text: '',
reply_message_id: '',
is_forwarded: false,
+ duration: 0,
loading: false,
}
},
@@ -65,6 +66,10 @@ export default {
payload.reply_message_id = this.reply_message_id;
}
+ if (this.duration && this.duration > 0) {
+ payload.duration = this.duration;
+ }
+
const response = await window.http.post('/send/message', payload);
this.handleReset();
return response.data.message;
@@ -82,6 +87,7 @@ export default {
this.text = '';
this.reply_message_id = '';
this.is_forwarded = false;
+ this.duration = 0;
},
},
template: `
@@ -122,6 +128,10 @@ export default {
<label>Mark message as forwarded</label>
</div>
</div>
+ <div class="field">
+ <label>Disappearing Duration (seconds)</label>
+ <input v-model.number="duration" type="number" min="0" placeholder="0 (no expiry)" aria-label="duration"/>
+ </div>
</form>
</div>
<div class="actions">
diff --git a/src/views/components/SendPoll.js b/src/views/components/SendPoll.js
index eec01bd6..664635cf 100644
--- a/src/views/components/SendPoll.js
+++ b/src/views/components/SendPoll.js
@@ -13,7 +13,8 @@ export default {
loading: false,
question: '',
options: ['', ''],
- max_vote: 1,
+ max_answer: 1,
+ duration: 0,
}
},
computed: {
@@ -42,6 +43,10 @@ export default {
return false;
}
+ if (this.max_answer < 1 || this.max_answer > this.options.length) {
+ return false;
+ }
+
return true;
},
async handleSubmit() {
@@ -63,8 +68,9 @@ export default {
const payload = {
phone: this.phone_id,
question: this.question,
- max_answer: this.max_vote,
- options: this.options
+ options: this.options,
+ max_answer: this.max_answer,
+ ...(this.duration && this.duration > 0 ? {duration: this.duration} : {})
}
const response = await window.http.post(`/send/poll`, payload)
this.handleReset();
@@ -83,7 +89,8 @@ export default {
this.type = window.TYPEUSER;
this.question = '';
this.options = ['', ''];
- this.max_vote = 1;
+ this.max_answer = 1;
+ this.duration = 0;
},
addOption() {
this.options.push('')
@@ -136,9 +143,16 @@ export default {
</div>
</div>
<div class="field">
- <label>Max Vote</label>
- <input v-model="max_vote" type="number" placeholder="Max Vote"
- aria-label="poll max votes" min="0">
+ <label>Max Answers Allowed</label>
+ <input v-model.number="max_answer" type="number" placeholder="Maximum answers per user"
+ aria-label="poll max answers" min="1" max="50">
+ <div class="ui pointing label">
+ How many options each user can select
+ </div>
+ </div>
+ <div class="field">
+ <label>Disappearing Duration (seconds)</label>
+ <input v-model.number="duration" type="number" min="0" placeholder="0 (no expiry)" aria-label="duration"/>
</div>
</form>
</div>
diff --git a/src/views/components/SendVideo.js b/src/views/components/SendVideo.js
index 0211ff9b..b82a33f7 100644
--- a/src/views/components/SendVideo.js
+++ b/src/views/components/SendVideo.js
@@ -21,7 +21,8 @@ export default {
loading: false,
video_url: null,
selectedFileName: null,
- is_forwarded: false
+ is_forwarded: false,
+ duration: 0
}
},
computed: {
@@ -34,6 +35,7 @@ export default {
// If view_once is set to true, set is_forwarded to false
if (newValue === true) {
this.is_forwarded = false;
+ this.duration = 0;
}
}
},
@@ -93,6 +95,9 @@ export default {
payload.append("view_once", this.view_once)
payload.append("compress", this.compress)
payload.append("is_forwarded", this.is_forwarded)
+ if (this.duration && this.duration > 0) {
+ payload.append("duration", this.duration)
+ }
const fileInput = $("#file_video")[0];
if (fileInput && fileInput.files && fileInput.files[0]) {
@@ -122,6 +127,7 @@ export default {
this.selectedFileName = null;
this.video_url = null;
this.is_forwarded = false;
+ this.duration = 0;
$("#file_video").val('');
},
handleFileChange(event) {
@@ -181,6 +187,10 @@ export default {
<label>Mark video as forwarded</label>
</div>
</div>
+ <div class="field">
+ <label>Disappearing Duration (seconds)</label>
+ <input v-model.number="duration" type="number" min="0" placeholder="0 (no expiry)" aria-label="duration"/>
+ </div>
<div class="field">
<label>Video URL</label>
<input type="text" v-model="video_url" placeholder="https://example.com/sample.mp4"