Browse Source

feat: add reaction (#60)

* feat: add reaction

* feat: separate message new domain

* feat: update open api

* feat: update UI

* feat: update go modules
pull/61/head
Aldino Kemal 3 years ago
committed by GitHub
parent
commit
11ede11d22
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
  1. 79
      docs/openapi.yaml
  2. 2
      src/cmd/root.go
  3. 2
      src/config/settings.go
  4. 9
      src/domains/message/message.go
  5. 12
      src/domains/message/reaction.go
  6. 11
      src/domains/message/revoke.go
  7. 12
      src/domains/message/update.go
  8. 10
      src/domains/send/message.go
  9. 2
      src/domains/send/send.go
  10. 11
      src/go.mod
  11. 59
      src/go.sum
  12. 78
      src/internal/rest/message.go
  13. 40
      src/internal/rest/send.go
  14. 95
      src/services/message.go
  15. 42
      src/services/send.go
  16. 50
      src/validations/message_validation.go
  17. 27
      src/validations/send_validation.go
  18. 156
      src/views/index.html

79
docs/openapi.yaml

@ -1,7 +1,7 @@
openapi: 3.0.0
info:
title: WhatsApp API MultiDevice
version: 3.3.1
version: 3.4.0
description: This API is used for sending whatsapp via API
servers:
- url: http://localhost:3000
@ -10,8 +10,10 @@ tags:
description: Initial Connection to Whatsapp server
- name: user
description: Getting information
- name: send
description: Send Message (Text/Image/File/Video).
- name: message
description: Send or Manipulate Message (Text/Image/File/Video).
description: Message manipulation (revoke/react/update).
paths:
/app/login:
get:
@ -192,7 +194,7 @@ paths:
post:
operationId: sendMessage
tags:
- message
- send
summary: Send Message
requestBody:
content:
@ -231,7 +233,7 @@ paths:
post:
operationId: sendImage
tags:
- message
- send
summary: Send Image
requestBody:
content:
@ -282,7 +284,7 @@ paths:
post:
operationId: sendFile
tags:
- message
- send
summary: Send File
requestBody:
content:
@ -325,7 +327,7 @@ paths:
post:
operationId: sendVideo
tags:
- message
- send
summary: Send Video
requestBody:
content:
@ -376,7 +378,7 @@ paths:
post:
operationId: sendContact
tags:
- message
- send
summary: Send Contact
requestBody:
content:
@ -419,7 +421,7 @@ paths:
post:
operationId: sendLink
tags:
- message
- send
summary: Send Link
requestBody:
content:
@ -462,7 +464,7 @@ paths:
post:
operationId: sendLocation
tags:
- message
- send
summary: Send Location
requestBody:
content:
@ -501,12 +503,61 @@ paths:
application/json:
schema:
$ref: '#/components/schemas/ErrorInternalServer'
/message/:message_id/revoke:
/message/{message_id}/revoke:
post:
operationId: revokeMessage
tags:
- message
summary: Send Link
summary: Revoke Message
parameters:
- in: path
name: message_id
schema:
type: string
required: true
description: Message ID
requestBody:
content:
multipart/form-data:
schema:
type: object
properties:
phone:
type: string
example: '6289685024051@s.whatsapp.net'
description: Phone number with country code
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}/reaction:
post:
operationId: reactMessage
tags:
- message
summary: Send reaction to message
parameters:
- in: path
name: message_id
schema:
type: string
required: true
description: Message ID
requestBody:
content:
multipart/form-data:
@ -517,10 +568,10 @@ paths:
type: string
example: '6289685024051@s.whatsapp.net'
description: Phone number with country code
message_id:
emoji:
type: string
example: "3EB007D87686670344D7"
description: Message ID
example: "🙏"
description: Emoji to react
responses:
'200':
description: OK

2
src/cmd/root.go

@ -98,11 +98,13 @@ func runRest(_ *cobra.Command, _ []string) {
appService := services.NewAppService(cli, db)
sendService := services.NewSendService(cli)
userService := services.NewUserService(cli)
messageService := services.NewMessageService(cli)
// Rest
rest.InitRestApp(app, appService)
rest.InitRestSend(app, sendService)
rest.InitRestUser(app, userService)
rest.InitRestMessage(app, messageService)
app.Get("/", func(c *fiber.Ctx) error {
return c.Render("index", fiber.Map{

2
src/config/settings.go

@ -6,7 +6,7 @@ import (
)
var (
AppVersion = "v4.4.6"
AppVersion = "v4.5.0"
AppPort = "3000"
AppDebug = false
AppOs = fmt.Sprintf("AldinoKemal")

9
src/domains/message/message.go

@ -0,0 +1,9 @@
package message
import "context"
type IMessageService interface {
ReactMessage(ctx context.Context, request ReactionRequest) (response ReactionResponse, err error)
RevokeMessage(ctx context.Context, request RevokeRequest) (response RevokeResponse, err error)
UpdateMessage(ctx context.Context, request UpdateMessageRequest) (response UpdateMessageResponse, err error)
}

12
src/domains/message/reaction.go

@ -0,0 +1,12 @@
package message
type ReactionRequest struct {
MessageID string `json:"message_id" form:"message_id"`
Phone string `json:"phone" form:"phone"`
Emoji string `json:"emoji" form:"emoji"`
}
type ReactionResponse struct {
MessageID string `json:"message_id"`
Status string `json:"status"`
}

11
src/domains/message/revoke.go

@ -0,0 +1,11 @@
package message
type RevokeRequest struct {
MessageID string `json:"message_id" uri:"message_id"`
Phone string `json:"phone" form:"phone"`
}
type RevokeResponse struct {
MessageID string `json:"message_id"`
Status string `json:"status"`
}

12
src/domains/message/update.go

@ -0,0 +1,12 @@
package message
type UpdateMessageRequest struct {
MessageID string `json:"message_id" uri:"message_id"`
Message string `json:"message" form:"message"`
Phone string `json:"phone" form:"phone"`
}
type UpdateMessageResponse struct {
MessageID string `json:"message_id"`
Status string `json:"status"`
}

10
src/domains/send/message.go

@ -1,15 +1,5 @@
package send
type RevokeRequest struct {
MessageID string `json:"message_id" uri:"message_id"`
Phone string `json:"phone" form:"phone"`
}
type RevokeResponse struct {
MessageID string `json:"message_id"`
Status string `json:"status"`
}
type UpdateMessageRequest struct {
MessageID string `json:"message_id" uri:"message_id"`
Message string `json:"message" form:"message"`

2
src/domains/send/send.go

@ -12,6 +12,4 @@ type ISendService interface {
SendContact(ctx context.Context, request ContactRequest) (response ContactResponse, err error)
SendLink(ctx context.Context, request LinkRequest) (response LinkResponse, err error)
SendLocation(ctx context.Context, request LocationRequest) (response LocationResponse, err error)
Revoke(ctx context.Context, request RevokeRequest) (response RevokeResponse, err error)
UpdateMessage(ctx context.Context, request UpdateMessageRequest) (response UpdateMessageResponse, err error)
}

11
src/go.mod

@ -5,9 +5,9 @@ go 1.19
require (
github.com/dustin/go-humanize v1.0.1
github.com/go-ozzo/ozzo-validation/v4 v4.3.0
github.com/gofiber/fiber/v2 v2.41.0
github.com/gofiber/template v1.7.4
github.com/gofiber/websocket/v2 v2.1.3
github.com/gofiber/fiber/v2 v2.42.0
github.com/gofiber/template v1.7.5
github.com/gofiber/websocket/v2 v2.1.4
github.com/google/uuid v1.3.0
github.com/h2non/bimg v1.1.9
github.com/markbates/pkger v0.17.1
@ -18,7 +18,7 @@ require (
github.com/stretchr/testify v1.8.1
github.com/valyala/fasthttp v1.44.0
go.mau.fi/libsignal v0.1.0
go.mau.fi/whatsmeow v0.0.0-20230128195103-dcbc8dd31a22
go.mau.fi/whatsmeow v0.0.0-20230204181151-b1f00ea99464
google.golang.org/protobuf v1.28.1
)
@ -35,10 +35,13 @@ require (
github.com/mattn/go-colorable v0.1.13 // indirect
github.com/mattn/go-isatty v0.0.17 // indirect
github.com/mattn/go-runewidth v0.0.14 // indirect
github.com/philhofer/fwd v1.1.1 // indirect
github.com/pmezard/go-difflib v1.0.0 // indirect
github.com/rivo/uniseg v0.4.3 // indirect
github.com/savsgio/dictpool v0.0.0-20221023140959-7bf2e61cea94 // indirect
github.com/savsgio/gotils v0.0.0-20220530130905-52f3993e8d6d // indirect
github.com/spf13/pflag v1.0.5 // indirect
github.com/tinylib/msgp v1.1.6 // indirect
github.com/valyala/bytebufferpool v1.0.0 // indirect
github.com/valyala/tcplisten v1.0.0 // indirect
golang.org/x/crypto v0.5.0 // indirect

59
src/go.sum

@ -51,7 +51,6 @@ filippo.io/edwards25519 v1.0.0/go.mod h1:N1IkdkCkiLB6tki+MYJoSx2JTY9NUlxZE7eHn5E
github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU=
github.com/BurntSushi/xgb v0.0.0-20160522181843-27f122750802/go.mod h1:IVnqGOEym/WlBOVXweHU+Q+/VP0lqqI8lqeDx9IjBqo=
github.com/CloudyKit/fastprinter v0.0.0-20200109182630-33d98a066a53/go.mod h1:+3IMCy2vIlbG1XG/0ggNQv0SvxCAIpPM5b1nCz56Xno=
github.com/CloudyKit/jet/v6 v6.1.0/go.mod h1:d3ypHeIRNo2+XyqnGA8s+aphtcVpjP5hPwP/Lzo7Ro4=
github.com/CloudyKit/jet/v6 v6.2.0/go.mod h1:d3ypHeIRNo2+XyqnGA8s+aphtcVpjP5hPwP/Lzo7Ro4=
github.com/DataDog/datadog-go v3.2.0+incompatible/go.mod h1:LButxg5PwREeZtORoXG3tL4fMGNddJ+vMq1mwgfaqoQ=
github.com/Joker/hpp v1.0.0/go.mod h1:8x5n+M1Hp5hC0g8okX3sR3vFQwynaX/UgSOM9MeBKzY=
@ -107,8 +106,6 @@ github.com/creack/pty v1.1.9/go.mod h1:oKZEueFk5CKHvIhNR5MUki03XCEU+Q6VDXinZuGJ3
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/dustin/go-humanize v1.0.0 h1:VSnTsYCnlFHaM2/igO1h6X3HA71jcobQuxemgkq4zYo=
github.com/dustin/go-humanize v1.0.0/go.mod h1:HtrtbFcZ19U5GC7JDqmcUSB87Iq5E25KnS6fMYU6eOk=
github.com/dustin/go-humanize v1.0.1 h1:GzkhY7T5VNhEkwH0PVJgjz+fX1rhBrR7pRT3mDkpeCY=
github.com/dustin/go-humanize v1.0.1/go.mod h1:Mu1zIs6XwVuF/gI1OepvI0qD18qycQx+mFykh5fBlto=
github.com/eknkc/amber v0.0.0-20171010120322-cdade1c07385/go.mod h1:0vRUJqYpeSZifjYj7uP3BG/gKcuzL9xWVV/Y+cK33KM=
@ -123,8 +120,6 @@ github.com/envoyproxy/go-control-plane v0.9.10-0.20210907150352-cf90f659a021/go.
github.com/envoyproxy/go-control-plane v0.10.1/go.mod h1:AY7fTTXNdv/aJ2O5jwpxAPOWUZ7hQAEvzN5Pf27BkQQ=
github.com/envoyproxy/protoc-gen-validate v0.1.0/go.mod h1:iSmxcyjqTsJpI2R4NaDN7+kN2VEUnK/pcBlmesArF7c=
github.com/envoyproxy/protoc-gen-validate v0.6.2/go.mod h1:2t7qjJNvHPx8IjnBOzl9E9/baC+qXE/TeeyBRzgJDws=
github.com/fasthttp/websocket v1.5.0 h1:B4zbe3xXyvIdnqjOZrafVFklCUq5ZLo/TqCt5JA1wLE=
github.com/fasthttp/websocket v1.5.0/go.mod h1:n0BlOQvJdPbTuBkZT0O5+jk/sp/1/VCzquR1BehI2F4=
github.com/fasthttp/websocket v1.5.1 h1:iZsMv5OtZ1E52hhCnlOm/feLCrPhutlrZgvEGcZa1FM=
github.com/fasthttp/websocket v1.5.1/go.mod h1:s+gJkEn38QXLkNfOe/n75Yb8we+VEho1vYqeUYheomw=
github.com/fatih/color v1.7.0/go.mod h1:Zm6kSWBoL9eyXnKyktHP6abPY2pDugNf5KwzbycvMj4=
@ -147,18 +142,12 @@ github.com/gobuffalo/here v0.6.0/go.mod h1:wAG085dHOYqUpf+Ap+WOdrPTp5IYcDAs/x7PL
github.com/gobuffalo/here v0.6.7 h1:hpfhh+kt2y9JLDfhYUxxCRxQol540jsVfKUZzjlbp8o=
github.com/gobuffalo/here v0.6.7/go.mod h1:vuCfanjqckTuRlqAitJz6QC4ABNnS27wLb816UhsPcc=
github.com/godbus/dbus/v5 v5.0.4/go.mod h1:xhWf0FNVPg57R7Z0UbKHbJfkEywrmjJnf7w5xrFpKfA=
github.com/gofiber/fiber/v2 v2.40.1 h1:pc7n9VVpGIqNsvg9IPLQhyFEMJL8gCs1kneH5D1pIl4=
github.com/gofiber/fiber/v2 v2.40.1/go.mod h1:Gko04sLksnHbzLSRBFWPFdzM9Ws9pRxvvIaohJK1dsk=
github.com/gofiber/fiber/v2 v2.41.0 h1:YhNoUS/OTjEz+/WLYuQ01xI7RXgKEFnGBKMagAu5f0M=
github.com/gofiber/fiber/v2 v2.41.0/go.mod h1:RdebcCuCRFp4W6hr3968/XxwJVg0K+jr9/Ae0PFzZ0Q=
github.com/gofiber/template v1.7.3 h1:ddWRgCB7kDdsgH7Qakwmlj6qM3kjggaT0aIhxLGatD0=
github.com/gofiber/template v1.7.3/go.mod h1:MI/DIYL6czowb8KLkkNAojCifLnAVQcN3KGEUDvlFtU=
github.com/gofiber/template v1.7.4 h1:3K86NpBhDOBAhk6keecxNwqSgALqaHlUIhNItR96N2Y=
github.com/gofiber/template v1.7.4/go.mod h1:rePzgcCYbLaUvaaU7XeAOOg3c0Sif4vRVw3TFjLabxY=
github.com/gofiber/websocket/v2 v2.1.2 h1:EulKyLB/fJgui5+6c8irwEnYQ9FRsrLZfkrq9OfTDGc=
github.com/gofiber/websocket/v2 v2.1.2/go.mod h1:S+sKWo0xeC7Wnz5h4/8f6D/NxsrLFIdWDYB3SyVO9pE=
github.com/gofiber/websocket/v2 v2.1.3 h1:F+NSwIZPZ8L5w+cevkv4AqoXs15zAiT+yRpMZudoWbk=
github.com/gofiber/websocket/v2 v2.1.3/go.mod h1:xBRiR0hs+PDqZxE7d/VA96mvK1d1t4EBSRR9Q7KxkBs=
github.com/gofiber/fiber/v2 v2.42.0 h1:Fnp7ybWvS+sjNQsFvkhf4G8OhXswvB6Vee8hM/LyS+8=
github.com/gofiber/fiber/v2 v2.42.0/go.mod h1:3+SGNjqMh5VQH5Vz2Wdi43zTIV16ktlFd3x3R6O1Zlc=
github.com/gofiber/template v1.7.5 h1:6Yk/lot2RudQp9u+bmIJqFg7kOaFPQ7+LgDE9drYSp8=
github.com/gofiber/template v1.7.5/go.mod h1:cBctw0IkZxBrY5NWKZVSa/dOuYzNbu+sJrzX4c7Qxmc=
github.com/gofiber/websocket/v2 v2.1.4 h1:Ki6L7auleAwgi7iRmtUiWKltlbmtkCJ0COtK1nt8L3g=
github.com/gofiber/websocket/v2 v2.1.4/go.mod h1:IC4ZUejlk0kJSaphJ1gjqgKfK9fhw8eoAr3/UdbOzEA=
github.com/gogo/protobuf v1.1.1/go.mod h1:r8qH/GZQm5c6nD/R0oafs1akxWv10x8SbQlK7atdtwQ=
github.com/gogo/protobuf v1.3.2/go.mod h1:P1XiOD3dCwIKUDQYPy72D8LYyHL2YPYrpS2s69NZV8Q=
github.com/golang/glog v0.0.0-20160126235308-23def4e6c14b/go.mod h1:SBH7ygxi8pfUlaOkMMuAQtPIUF8ecWP5IEl/CR7VP2Q=
@ -286,12 +275,7 @@ github.com/jstemmer/go-junit-report v0.9.1/go.mod h1:Brl9GWCQeLvo8nXZwPNNblvFj/X
github.com/julienschmidt/httprouter v1.2.0/go.mod h1:SYymIcj16QtmaHHD7aYtjjsJG7VTCxuUUipMqKk8s4w=
github.com/kisielk/errcheck v1.5.0/go.mod h1:pFxgyoBC7bSaBwPgfKdkLd5X25qrDl4LWUI2bnpBCr8=
github.com/kisielk/gotool v1.0.0/go.mod h1:XhKaO+MFFWcvkIS/tQcRk01m1F5IRFswLeQ+oQHNcck=
github.com/klauspost/compress v1.14.1/go.mod h1:/3/Vjq9QcHkK5uEr5lBEmyoZ1iFhe47etQ6QUkpK6sk=
github.com/klauspost/compress v1.15.9/go.mod h1:PhcZ0MbTNciWF3rruxRgKxI5NkcHHrHUDtV4Yw2GlzU=
github.com/klauspost/compress v1.15.13 h1:NFn1Wr8cfnenSJSA46lLq4wHCcBzKTSjnBIexDMMOV0=
github.com/klauspost/compress v1.15.13/go.mod h1:QPwzmACJjUTFsnSHH934V6woptycfrDDJnH7hvFVbGM=
github.com/klauspost/compress v1.15.14 h1:i7WCKDToww0wA+9qrUZ1xOjp218vfFo3nTU6UHp+gOc=
github.com/klauspost/compress v1.15.14/go.mod h1:QPwzmACJjUTFsnSHH934V6woptycfrDDJnH7hvFVbGM=
github.com/klauspost/compress v1.15.15 h1:EF27CXIuDsYJ6mmvtBRlEuB2UVOqHG1tAXgZ7yIO+lw=
github.com/klauspost/compress v1.15.15/go.mod h1:ZcK2JAFqKOpnBlxcLsJzYfrS9X1akm9fHZNnD9+Vo/4=
github.com/konsorten/go-windows-terminal-sequences v1.0.1/go.mod h1:T0+1ngSBFLxvqU3pZ+m/2kptfBszLMUkC4ZK/EgS/cQ=
@ -320,7 +304,6 @@ github.com/mattn/go-isatty v0.0.10/go.mod h1:qgIWMr58cqv1PHHyhnkY9lrL7etaEgOFcME
github.com/mattn/go-isatty v0.0.11/go.mod h1:PhnuNfih5lzO57/f3n+odYbM4JtupLOxQOAqxQCu2WE=
github.com/mattn/go-isatty v0.0.12/go.mod h1:cbi8OIDigv2wuxKPP5vlRcQ1OAZbq2CE4Kysco4FUpU=
github.com/mattn/go-isatty v0.0.14/go.mod h1:7GGIvUiUoEMVVmxf/4nioHXj79iQHKdU27kJ6hsGG94=
github.com/mattn/go-isatty v0.0.16 h1:bq3VjFmv/sOjHtdEhmkEV4x1AJtvUvOJ2PFAZ5+peKQ=
github.com/mattn/go-isatty v0.0.16/go.mod h1:kYGgaQfpe5nmfYZH+SKPsOc2e4SrIfOl2e/yFXSvRLM=
github.com/mattn/go-isatty v0.0.17 h1:BTarxUcIeDqL27Mc+vyvdWYSL28zpIhv3RoTdsLMPng=
github.com/mattn/go-isatty v0.0.17/go.mod h1:kYGgaQfpe5nmfYZH+SKPsOc2e4SrIfOl2e/yFXSvRLM=
@ -350,6 +333,8 @@ github.com/niemeyer/pretty v0.0.0-20200227124842-a10e7caefd8e/go.mod h1:zD1mROLA
github.com/pascaldekloe/goe v0.0.0-20180627143212-57f6aae5913c/go.mod h1:lzWF7FIEvWOWxwDKqyGYQf6ZUaNfKdP144TG7ZOy1lc=
github.com/pascaldekloe/goe v0.1.0/go.mod h1:lzWF7FIEvWOWxwDKqyGYQf6ZUaNfKdP144TG7ZOy1lc=
github.com/pelletier/go-toml v1.9.4/go.mod h1:u1nR/EPcESfeI/szUZKdtJ0xRNbUoANCkoOuaOx1Y+c=
github.com/philhofer/fwd v1.1.1 h1:GdGcTjf5RNAxwS4QLsiMzJYj5KEvPJD3Abr261yRQXQ=
github.com/philhofer/fwd v1.1.1/go.mod h1:gk3iGcWd9+svBvR0sR+KPcfE+RNWozjowpeBVG3ZVNU=
github.com/pkg/errors v0.8.0/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
github.com/pkg/errors v0.8.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
github.com/pkg/sftp v1.10.1/go.mod h1:lYOWFsE0bwd1+KfKJaKeuokY15vzFx25BLbzYYoAxZI=
@ -377,7 +362,8 @@ github.com/rogpeppe/go-internal v1.3.0/go.mod h1:M8bDsm7K2OlrFYOpmOWEs/qY81heoFR
github.com/russross/blackfriday/v2 v2.1.0/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQDYRxCVz55jmeOWTM=
github.com/ryanuber/columnize v0.0.0-20160712163229-9b3edd62028f/go.mod h1:sm1tb6uqfes/u+d4ooFouqFdy9/2g9QGwK3SQygK0Ts=
github.com/sagikazarmark/crypt v0.3.0/go.mod h1:uD/D+6UF4SrIR1uGEv7bBNkNqLGqUr43MRiaGWX1Nig=
github.com/savsgio/gotils v0.0.0-20211223103454-d0aaa54c5899/go.mod h1:oejLrk1Y/5zOF+c/aHtXqn3TFlzzbAgPWg8zBiAHDas=
github.com/savsgio/dictpool v0.0.0-20221023140959-7bf2e61cea94 h1:rmMl4fXJhKMNWl+K+r/fq4FbbKI+Ia2m9hYBLm2h4G4=
github.com/savsgio/dictpool v0.0.0-20221023140959-7bf2e61cea94/go.mod h1:90zrgN3D/WJsDd1iXHT96alCoN2KJo6/4x1DZC3wZs8=
github.com/savsgio/gotils v0.0.0-20220530130905-52f3993e8d6d h1:Q+gqLBOPkFGHyCJxXMRqtUgUbTjI8/Ze8vu8GGyNFwo=
github.com/savsgio/gotils v0.0.0-20220530130905-52f3993e8d6d/go.mod h1:Gy+0tqhJvgGlqnTF8CVGP0AaGRjwBtXs/a5PA0Y3+A4=
github.com/sean-/seed v0.0.0-20170313163322-e2103e2c3529/go.mod h1:DxrIzT+xaE7yg65j358z/aeFdxmN0P9QXhEzd20vsDc=
@ -409,18 +395,15 @@ github.com/stretchr/testify v1.5.1/go.mod h1:5W2xD1RspED5o8YsWQXVCued0rvSQ+mT+I5
github.com/stretchr/testify v1.6.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
github.com/stretchr/testify v1.7.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
github.com/stretchr/testify v1.8.0 h1:pSgiaMZlXftHpm5L7V1+rVB+AZJydKsMxsQBIJw4PKk=
github.com/stretchr/testify v1.8.0/go.mod h1:yNjHg4UonilssWZ8iaSj1OCr/vHnekPRkoO+kdMU+MU=
github.com/stretchr/testify v1.8.1 h1:w7B6lhMri9wdJUVmEZPGGhZzrYTPvgJArz7wNPgYKsk=
github.com/stretchr/testify v1.8.1/go.mod h1:w2LPCIKwWwSfY2zedu0+kehJoqGctiVI29o6fzry7u4=
github.com/subosito/gotenv v1.2.0/go.mod h1:N0PQaV/YGNqwC0u51sEeR/aUtSLEXKX9iv69rRypqCw=
github.com/tinylib/msgp v1.1.6 h1:i+SbKraHhnrf9M5MYmvQhFnbLhAXSDWF8WWsuyRdocw=
github.com/tinylib/msgp v1.1.6/go.mod h1:75BAfg2hauQhs3qedfdDZmWAPcFMAvJE5b9rGOMufyw=
github.com/tv42/httpunix v0.0.0-20150427012821-b75d8614f926/go.mod h1:9ESjWnEqriFuLhtthL60Sar/7RFoluCcXsuvEwTV5KM=
github.com/valyala/bytebufferpool v1.0.0 h1:GqA5TC/0021Y/b9FG4Oi9Mr3q7XYx6KllzawFIhcdPw=
github.com/valyala/bytebufferpool v1.0.0/go.mod h1:6bBcMArwyJ5K/AmCkWv1jt77kVWyCJ6HpOuEn7z0Csc=
github.com/valyala/fasthttp v1.33.0/go.mod h1:KJRK/MXx0J+yd0c5hlR+s1tIHD72sniU8ZJjl97LIw4=
github.com/valyala/fasthttp v1.41.0/go.mod h1:f6VbjjoI3z1NDOZOv17o6RvtRSWxC77seBFc2uWtgiY=
github.com/valyala/fasthttp v1.43.0 h1:Gy4sb32C98fbzVWZlTM1oTMdLWGyvxR03VhM6cBIU4g=
github.com/valyala/fasthttp v1.43.0/go.mod h1:f6VbjjoI3z1NDOZOv17o6RvtRSWxC77seBFc2uWtgiY=
github.com/valyala/fasthttp v1.44.0 h1:R+gLUhldIsfg1HokMuQjdQ5bh9nuXHPIfvkYUu9eR5Q=
github.com/valyala/fasthttp v1.44.0/go.mod h1:f6VbjjoI3z1NDOZOv17o6RvtRSWxC77seBFc2uWtgiY=
github.com/valyala/tcplisten v1.0.0 h1:rBHj/Xf+E1tRGZyWIWwJDiRY0zc1Js+CV5DqwacVSA8=
@ -435,16 +418,10 @@ github.com/yuin/goldmark v1.4.1/go.mod h1:mwnBkeHKe2W/ZEtQ+71ViKU8L12m81fl3OWwC1
go.etcd.io/etcd/api/v3 v3.5.1/go.mod h1:cbVKeC6lCfl7j/8jBhAK6aIYO9XOjdptoxU/nLQcPvs=
go.etcd.io/etcd/client/pkg/v3 v3.5.1/go.mod h1:IJHfcCEKxYu1Os13ZdwCwIUTUVGYTSAM3YSwc9/Ac1g=
go.etcd.io/etcd/client/v2 v2.305.1/go.mod h1:pMEacxZW7o8pg4CrFE7pquyCJJzZvkvdD2RibOCCCGs=
go.mau.fi/libsignal v0.0.0-20221015105917-d970e7c3c9cf h1:mzPxXBgDPHKDHMVV1tIWh7lwCiRpzCsXC0gNRX+K07c=
go.mau.fi/libsignal v0.0.0-20221015105917-d970e7c3c9cf/go.mod h1:XCjaU93vl71YNRPn059jMrK0xRDwVO5gKbxoPxow9mQ=
go.mau.fi/libsignal v0.1.0 h1:vAKI/nJ5tMhdzke4cTK1fb0idJzz1JuEIpmjprueC+c=
go.mau.fi/libsignal v0.1.0/go.mod h1:R8ovrTezxtUNzCQE5PH30StOQWWeBskBsWE55vMfY9I=
go.mau.fi/whatsmeow v0.0.0-20221213225758-70ef67df3c68 h1:uieThnMYyFDdUNDrHxauuZOW5ip+igWhHwyWFNjA2Sw=
go.mau.fi/whatsmeow v0.0.0-20221213225758-70ef67df3c68/go.mod h1:2yweL8nczvtlIxkrvCb0y8xiO13rveX9lJPambwYV/E=
go.mau.fi/whatsmeow v0.0.0-20230120142431-cd2d1213eff6 h1:/rhe2DT4A9BBoOZVzXtq48kBhHDpBGUhj94e8c9A0e0=
go.mau.fi/whatsmeow v0.0.0-20230120142431-cd2d1213eff6/go.mod h1:TrdC8N6SnPFxWo5FiMnDIDFuVyfOLzy5dWDaUPNjcHY=
go.mau.fi/whatsmeow v0.0.0-20230128195103-dcbc8dd31a22 h1:za/zmM0hcfEKTRcLtr2zcUFE4VpUw8CndXNeV+v676c=
go.mau.fi/whatsmeow v0.0.0-20230128195103-dcbc8dd31a22/go.mod h1:TrdC8N6SnPFxWo5FiMnDIDFuVyfOLzy5dWDaUPNjcHY=
go.mau.fi/whatsmeow v0.0.0-20230204181151-b1f00ea99464 h1:YsOjRyoipukUqaDHt4pQRi9JazNgCTCl40+2mpLYSm8=
go.mau.fi/whatsmeow v0.0.0-20230204181151-b1f00ea99464/go.mod h1:FYaCKtMD7yDQ7zpTSW28o24GODR75wVZ5OKHUfQySbA=
go.opencensus.io v0.21.0/go.mod h1:mSImk1erAIZhrmZN+AvHh14ztQfjbGwt4TtuofqLduU=
go.opencensus.io v0.22.0/go.mod h1:+kGneAE2xo2IficOXnaByMWTGM9T73dGwxeWcUqIpI8=
go.opencensus.io v0.22.2/go.mod h1:yxeiOL68Rb0Xd1ddK5vPZ/oVn4vY4Ynel7k9FzqtOIw=
@ -466,10 +443,7 @@ golang.org/x/crypto v0.0.0-20190923035154-9ee001bba392/go.mod h1:/lpIB1dKB+9EgE3
golang.org/x/crypto v0.0.0-20191011191535-87dc89f01550/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI=
golang.org/x/crypto v0.0.0-20200622213623-75b288015ac9/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto=
golang.org/x/crypto v0.0.0-20210817164053-32db794688a5/go.mod h1:GvvjBRRGRdwPK5ydBHafDWAxML/pGHZbMvKqRZ5+Abc=
golang.org/x/crypto v0.0.0-20220112180741-5e0467b6c7ce/go.mod h1:IxCIyHEi3zRg3s0A5j5BB6A9Jmi73HwBIUl50j+osU4=
golang.org/x/crypto v0.0.0-20220214200702-86341886e292/go.mod h1:IxCIyHEi3zRg3s0A5j5BB6A9Jmi73HwBIUl50j+osU4=
golang.org/x/crypto v0.4.0 h1:UVQgzMY87xqpKNgb+kDsll2Igd33HszWHFLmpaRMq/8=
golang.org/x/crypto v0.4.0/go.mod h1:3quD/ATkf6oY+rnes5c3ExXTbLc8mueNue5/DoinL80=
golang.org/x/crypto v0.5.0 h1:U/0M97KRkSFvyD/3FSmdP5W5swImpNgle/EHFhOsQPE=
golang.org/x/crypto v0.5.0/go.mod h1:NK/OQwhpMQP3MwtdjgLlYHnH9ebylxKWv3e0fK+mkQU=
golang.org/x/exp v0.0.0-20190121172915-509febef88a4/go.mod h1:CJ0aWSM057203Lf6IL+f9T1iT9GByDxfZKAQTCR3kQA=
@ -553,7 +527,6 @@ golang.org/x/net v0.0.0-20210503060351-7fd8e65b6420/go.mod h1:9nx3DQGgdP8bBQD5qx
golang.org/x/net v0.0.0-20210813160813-60bc85c4be6d/go.mod h1:9nx3DQGgdP8bBQD5qxJ1jj9UTztislL4KSBs9R2vV5Y=
golang.org/x/net v0.0.0-20211015210444-4f30a5c0130f/go.mod h1:9nx3DQGgdP8bBQD5qxJ1jj9UTztislL4KSBs9R2vV5Y=
golang.org/x/net v0.0.0-20211112202133-69e39bad7dc2/go.mod h1:9nx3DQGgdP8bBQD5qxJ1jj9UTztislL4KSBs9R2vV5Y=
golang.org/x/net v0.0.0-20220111093109-d55c255bac03/go.mod h1:9nx3DQGgdP8bBQD5qxJ1jj9UTztislL4KSBs9R2vV5Y=
golang.org/x/net v0.0.0-20220906165146-f3363e06e74c/go.mod h1:YDH+HFinaLZZlnHAfSS6ZXJJ9M9t4Dl22yv3iI2vPwk=
golang.org/x/oauth2 v0.0.0-20180821212333-d2e6202438be/go.mod h1:N/0e6XlmueqKjAGxoOufVs8QHGRruUQn6yWY3a++T0U=
golang.org/x/oauth2 v0.0.0-20190226205417-e64efc72b421/go.mod h1:gOpvHmFTYa4IltrdGE7lF6nIHvwfUNPOp7c8zoXwtLw=
@ -649,12 +622,9 @@ golang.org/x/sys v0.0.0-20211007075335-d3039528d8ac/go.mod h1:oPkhp1MJrh7nUepCBc
golang.org/x/sys v0.0.0-20211019181941-9d821ace8654/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.0.0-20211124211545-fe61309f8881/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.0.0-20211205182925-97ca703d548d/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.0.0-20220111092808-5a964db01320/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.0.0-20220715151400-c0bba94af5f8/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.0.0-20220728004956-3c1f35247d10/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.0.0-20220811171246-fbc7d0a398ab/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.3.0 h1:w8ZOecv6NaNa/zC8944JTU3vz4u6Lagfk4RPQxv92NQ=
golang.org/x/sys v0.3.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.4.0 h1:Zr2JFtRQNX3BCZ8YtxRE9hNJYC8J6I1MVbMg6owUp18=
golang.org/x/sys v0.4.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo=
@ -714,6 +684,7 @@ golang.org/x/tools v0.0.0-20200729194436-6467de6f59a7/go.mod h1:njjCfa9FT2d7l9Bc
golang.org/x/tools v0.0.0-20200804011535-6c149bb5ef0d/go.mod h1:njjCfa9FT2d7l9Bc6FUM5FLjQPp3cFF28FI3qnDFljA=
golang.org/x/tools v0.0.0-20200825202427-b303f430e36d/go.mod h1:njjCfa9FT2d7l9Bc6FUM5FLjQPp3cFF28FI3qnDFljA=
golang.org/x/tools v0.0.0-20200904185747-39188db58858/go.mod h1:Cj7w3i3Rnn0Xh82ur9kSqwfTHTeVxaDqrfMjpcNT6bE=
golang.org/x/tools v0.0.0-20201022035929-9cf592e881e9/go.mod h1:emZCQorbCU4vsT4fOWvOPXz4eW1wZW4PmDk9uLelYpA=
golang.org/x/tools v0.0.0-20201110124207-079ba7bd75cd/go.mod h1:emZCQorbCU4vsT4fOWvOPXz4eW1wZW4PmDk9uLelYpA=
golang.org/x/tools v0.0.0-20201201161351-ac6f37ff4c2a/go.mod h1:emZCQorbCU4vsT4fOWvOPXz4eW1wZW4PmDk9uLelYpA=
golang.org/x/tools v0.0.0-20201208233053-a543418bbed2/go.mod h1:emZCQorbCU4vsT4fOWvOPXz4eW1wZW4PmDk9uLelYpA=

78
src/internal/rest/message.go

@ -0,0 +1,78 @@
package rest
import (
"github.com/aldinokemal/go-whatsapp-web-multidevice/domains/message"
domainMessage "github.com/aldinokemal/go-whatsapp-web-multidevice/domains/message"
"github.com/aldinokemal/go-whatsapp-web-multidevice/pkg/utils"
"github.com/aldinokemal/go-whatsapp-web-multidevice/pkg/whatsapp"
"github.com/gofiber/fiber/v2"
)
type Message struct {
Service domainMessage.IMessageService
}
func InitRestMessage(app *fiber.App, service domainMessage.IMessageService) Message {
rest := Message{Service: service}
app.Post("/message/:message_id/reaction", rest.ReactMessage)
app.Post("/message/:message_id/revoke", rest.RevokeMessage)
app.Post("/message/:message_id/update", rest.UpdateMessage)
return rest
}
func (controller *Message) RevokeMessage(c *fiber.Ctx) error {
var request domainMessage.RevokeRequest
err := c.BodyParser(&request)
utils.PanicIfNeeded(err)
request.MessageID = c.Params("message_id")
whatsapp.SanitizePhone(&request.Phone)
response, err := controller.Service.RevokeMessage(c.UserContext(), request)
utils.PanicIfNeeded(err)
return c.JSON(utils.ResponseData{
Status: 200,
Code: "SUCCESS",
Message: response.Status,
Results: response,
})
}
func (controller *Message) UpdateMessage(c *fiber.Ctx) error {
var request domainMessage.UpdateMessageRequest
err := c.BodyParser(&request)
utils.PanicIfNeeded(err)
request.MessageID = c.Params("message_id")
whatsapp.SanitizePhone(&request.Phone)
response, err := controller.Service.UpdateMessage(c.UserContext(), request)
utils.PanicIfNeeded(err)
return c.JSON(utils.ResponseData{
Status: 200,
Code: "SUCCESS",
Message: response.Status,
Results: response,
})
}
func (controller *Message) ReactMessage(c *fiber.Ctx) error {
var request message.ReactionRequest
err := c.BodyParser(&request)
utils.PanicIfNeeded(err)
request.MessageID = c.Params("message_id")
whatsapp.SanitizePhone(&request.Phone)
response, err := controller.Service.ReactMessage(c.UserContext(), request)
utils.PanicIfNeeded(err)
return c.JSON(utils.ResponseData{
Status: 200,
Code: "SUCCESS",
Message: response.Status,
Results: response,
})
}

40
src/internal/rest/send.go

@ -20,8 +20,6 @@ func InitRestSend(app *fiber.App, service domainSend.ISendService) Send {
app.Post("/send/contact", rest.SendContact)
app.Post("/send/link", rest.SendLink)
app.Post("/send/location", rest.SendLocation)
app.Post("/message/:message_id/revoke", rest.RevokeMessage)
app.Post("/message/:message_id/update", rest.UpdateMessage)
return rest
}
@ -164,41 +162,3 @@ func (controller *Send) SendLocation(c *fiber.Ctx) error {
Results: response,
})
}
func (controller *Send) RevokeMessage(c *fiber.Ctx) error {
var request domainSend.RevokeRequest
err := c.BodyParser(&request)
utils.PanicIfNeeded(err)
request.MessageID = c.Params("message_id")
whatsapp.SanitizePhone(&request.Phone)
response, err := controller.Service.Revoke(c.UserContext(), request)
utils.PanicIfNeeded(err)
return c.JSON(utils.ResponseData{
Status: 200,
Code: "SUCCESS",
Message: response.Status,
Results: response,
})
}
func (controller *Send) UpdateMessage(c *fiber.Ctx) error {
var request domainSend.UpdateMessageRequest
err := c.BodyParser(&request)
utils.PanicIfNeeded(err)
request.MessageID = c.Params("message_id")
whatsapp.SanitizePhone(&request.Phone)
response, err := controller.Service.UpdateMessage(c.UserContext(), request)
utils.PanicIfNeeded(err)
return c.JSON(utils.ResponseData{
Status: 200,
Code: "SUCCESS",
Message: response.Status,
Results: response,
})
}

95
src/services/message.go

@ -0,0 +1,95 @@
package services
import (
"context"
"fmt"
"github.com/aldinokemal/go-whatsapp-web-multidevice/domains/message"
domainMessage "github.com/aldinokemal/go-whatsapp-web-multidevice/domains/message"
"github.com/aldinokemal/go-whatsapp-web-multidevice/pkg/whatsapp"
"github.com/aldinokemal/go-whatsapp-web-multidevice/validations"
"go.mau.fi/whatsmeow"
waProto "go.mau.fi/whatsmeow/binary/proto"
"go.mau.fi/whatsmeow/types"
"google.golang.org/protobuf/proto"
"time"
)
type serviceMessage struct {
WaCli *whatsmeow.Client
}
func NewMessageService(waCli *whatsmeow.Client) domainMessage.IMessageService {
return &serviceMessage{
WaCli: waCli,
}
}
func (service serviceMessage) ReactMessage(ctx context.Context, request message.ReactionRequest) (response message.ReactionResponse, err error) {
if err = validations.ValidateReactMessage(ctx, request); err != nil {
return response, err
}
dataWaRecipient, err := whatsapp.ValidateJidWithLogin(service.WaCli, request.Phone)
if err != nil {
return response, err
}
msg := &waProto.Message{
ReactionMessage: &waProto.ReactionMessage{
Key: &waProto.MessageKey{
FromMe: proto.Bool(true),
Id: proto.String(request.MessageID),
RemoteJid: proto.String(dataWaRecipient.String()),
},
Text: proto.String(request.Emoji),
SenderTimestampMs: proto.Int64(time.Now().UnixMilli()),
},
}
ts, err := service.WaCli.SendMessage(ctx, dataWaRecipient, msg)
if err != nil {
return response, err
}
response.MessageID = ts.ID
response.Status = fmt.Sprintf("Reaction sent to %s (server timestamp: %s)", request.Phone, ts)
return response, nil
}
func (service serviceMessage) RevokeMessage(ctx context.Context, request domainMessage.RevokeRequest) (response domainMessage.RevokeResponse, err error) {
if err = validations.ValidateRevokeMessage(ctx, request); err != nil {
return response, err
}
dataWaRecipient, err := whatsapp.ValidateJidWithLogin(service.WaCli, request.Phone)
if err != nil {
return response, err
}
ts, err := service.WaCli.SendMessage(context.Background(), dataWaRecipient, service.WaCli.BuildRevoke(dataWaRecipient, types.EmptyJID, request.MessageID))
if err != nil {
return response, err
}
response.MessageID = ts.ID
response.Status = fmt.Sprintf("Revoke success %s (server timestamp: %s)", request.Phone, ts)
return response, nil
}
func (service serviceMessage) UpdateMessage(ctx context.Context, request domainMessage.UpdateMessageRequest) (response domainMessage.UpdateMessageResponse, err error) {
if err = validations.ValidateUpdateMessage(ctx, request); err != nil {
return response, err
}
dataWaRecipient, err := whatsapp.ValidateJidWithLogin(service.WaCli, request.Phone)
if err != nil {
return response, err
}
msg := &waProto.Message{Conversation: proto.String(request.Message)}
ts, err := service.WaCli.SendMessage(context.Background(), dataWaRecipient, service.WaCli.BuildEdit(dataWaRecipient, request.MessageID, msg))
if err != nil {
return response, err
}
response.MessageID = ts.ID
response.Status = fmt.Sprintf("Update message success %s (server timestamp: %s)", request.Phone, ts)
return response, nil
}

42
src/services/send.go

@ -14,7 +14,6 @@ import (
"github.com/valyala/fasthttp"
"go.mau.fi/whatsmeow"
waProto "go.mau.fi/whatsmeow/binary/proto"
"go.mau.fi/whatsmeow/types"
"google.golang.org/protobuf/proto"
"net/http"
"os"
@ -398,44 +397,3 @@ func (service serviceSend) SendLocation(ctx context.Context, request domainSend.
response.Status = fmt.Sprintf("Send location success %s (server timestamp: %s)", request.Phone, ts)
return response, nil
}
func (service serviceSend) Revoke(ctx context.Context, request domainSend.RevokeRequest) (response domainSend.RevokeResponse, err error) {
err = validations.ValidateRevokeMessage(ctx, request)
if err != nil {
return response, err
}
dataWaRecipient, err := whatsapp.ValidateJidWithLogin(service.WaCli, request.Phone)
if err != nil {
return response, err
}
ts, err := service.WaCli.SendMessage(context.Background(), dataWaRecipient, service.WaCli.BuildRevoke(dataWaRecipient, types.EmptyJID, request.MessageID))
if err != nil {
return response, err
}
response.MessageID = ts.ID
response.Status = fmt.Sprintf("Revoke success %s (server timestamp: %s)", request.Phone, ts)
return response, nil
}
func (service serviceSend) UpdateMessage(ctx context.Context, request domainSend.UpdateMessageRequest) (response domainSend.UpdateMessageResponse, err error) {
err = validations.ValidateUpdateMessage(ctx, request)
if err != nil {
return response, err
}
dataWaRecipient, err := whatsapp.ValidateJidWithLogin(service.WaCli, request.Phone)
if err != nil {
return response, err
}
msg := &waProto.Message{Conversation: proto.String(request.Message)}
ts, err := service.WaCli.SendMessage(context.Background(), dataWaRecipient, service.WaCli.BuildEdit(dataWaRecipient, request.MessageID, msg))
if err != nil {
return response, err
}
response.MessageID = ts.ID
response.Status = fmt.Sprintf("Update message success %s (server timestamp: %s)", request.Phone, ts)
return response, nil
}

50
src/validations/message_validation.go

@ -0,0 +1,50 @@
package validations
import (
"context"
"github.com/aldinokemal/go-whatsapp-web-multidevice/domains/message"
domainMessage "github.com/aldinokemal/go-whatsapp-web-multidevice/domains/message"
pkgError "github.com/aldinokemal/go-whatsapp-web-multidevice/pkg/error"
validation "github.com/go-ozzo/ozzo-validation/v4"
)
func ValidateRevokeMessage(ctx context.Context, request domainMessage.RevokeRequest) error {
err := validation.ValidateStructWithContext(ctx, &request,
validation.Field(&request.Phone, validation.Required),
validation.Field(&request.MessageID, validation.Required),
)
if err != nil {
return pkgError.ValidationError(err.Error())
}
return nil
}
func ValidateUpdateMessage(ctx context.Context, request domainMessage.UpdateMessageRequest) error {
err := validation.ValidateStructWithContext(ctx, &request,
validation.Field(&request.Phone, validation.Required),
validation.Field(&request.MessageID, validation.Required),
validation.Field(&request.Message, validation.Required),
)
if err != nil {
return pkgError.ValidationError(err.Error())
}
return nil
}
func ValidateReactMessage(ctx context.Context, request message.ReactionRequest) error {
err := validation.ValidateStructWithContext(ctx, &request,
validation.Field(&request.Phone, validation.Required),
validation.Field(&request.MessageID, validation.Required),
validation.Field(&request.Emoji, validation.Required),
)
if err != nil {
return pkgError.ValidationError(err.Error())
}
return nil
}

27
src/validations/send_validation.go

@ -133,30 +133,3 @@ func ValidateSendLocation(ctx context.Context, request domainSend.LocationReques
return nil
}
func ValidateRevokeMessage(ctx context.Context, request domainSend.RevokeRequest) error {
err := validation.ValidateStructWithContext(ctx, &request,
validation.Field(&request.Phone, validation.Required),
validation.Field(&request.MessageID, validation.Required),
)
if err != nil {
return pkgError.ValidationError(err.Error())
}
return nil
}
func ValidateUpdateMessage(ctx context.Context, request domainSend.UpdateMessageRequest) error {
err := validation.ValidateStructWithContext(ctx, &request,
validation.Field(&request.Phone, validation.Required),
validation.Field(&request.MessageID, validation.Required),
validation.Field(&request.Message, validation.Required),
)
if err != nil {
return pkgError.ValidationError(err.Error())
}
return nil
}

156
src/views/index.html

@ -69,7 +69,7 @@
</div>
<div class="ui horizontal divider">
Message
Send
</div>
<div class="ui three column doubling grid cards">
@ -133,15 +133,32 @@
</div>
</div>
</div>
<div class="red card" @click="sendRevokeModal()" style="cursor: pointer">
</div>
<div class="ui horizontal divider">
Message
</div>
<div class="ui three column doubling grid cards">
<div class="red card" @click="messageRevokeModal()" style="cursor: pointer">
<div class="content">
<a class="ui red right ribbon label">Revoke</a>
<a class="ui red right ribbon label">Message</a>
<div class="header">Revoke Message</div>
<div class="description">
Revoke any message in private or group chat
</div>
</div>
</div>
<div class="red card" @click="messageReactModal()" style="cursor: pointer">
<div class="content">
<a class="ui red right ribbon label">Message</a>
<div class="header">React Message</div>
<div class="description">
React any message in private or group chat
</div>
</div>
</div>
</div>
<div class="ui horizontal divider">
@ -495,11 +512,11 @@
</div>
</div>
<!-- Modal SendRevoke -->
<div class="ui small modal" id="modalSendRevoke">
<!-- Modal MessageRevoke -->
<div class="ui small modal" id="modalMessageRevoke">
<i class="close icon"></i>
<div class="header">
Send Revoke
Revoke Message
</div>
<div class="content">
<form class="ui form">
@ -525,7 +542,49 @@
</div>
<div class="actions">
<div class="ui approve positive right labeled icon button" :class="{'loading': this.revoke_loading}"
@click="sendRevokeProcess">
@click="messageRevokeProcess">
Send
<i class="send icon"></i>
</div>
</div>
</div>
<!-- Modal MessageReaction -->
<div class="ui small modal" id="modalMessageReaction">
<i class="close icon"></i>
<div class="header">
React Message
</div>
<div class="content">
<form class="ui form">
<div class="field">
<label>Type</label>
<select name="react_type" v-model="react_type" aria-label="type">
<option value="group">Group Message</option>
<option value="user">Private Message</option>
</select>
</div>
<div class="field">
<label>Phone / Group ID</label>
<input v-model="react_phone" type="text" placeholder="6289..."
aria-label="phone">
<input :value="react_phone_id" disabled aria-label="whatsapp_id">
</div>
<div class="field">
<label>Message ID</label>
<input v-model="react_message_id" type="text" placeholder="Please enter your message id"
aria-label="message id">
</div>
<div class="field">
<label>Emoji</label>
<input v-model="react_emoji" type="text" placeholder="Please enter emoji"
aria-label="message id">
</div>
</form>
</div>
<div class="actions">
<div class="ui approve positive right labeled icon button" :class="{'loading': this.react_loading}"
@click="messageReactProcess">
Send
<i class="send icon"></i>
</div>
@ -1120,7 +1179,7 @@
}
}
const sendRevoke = {
const messageRevoke = {
data() {
return {
revoke_type: 'user',
@ -1135,30 +1194,30 @@
}
},
methods: {
sendRevokeModal() {
$('#modalSendRevoke').modal({
messageRevokeModal() {
$('#modalMessageRevoke').modal({
onApprove: function () {
return false;
}
}).modal('show');
},
async sendRevokeProcess() {
async messageRevokeProcess() {
try {
let response = await this.sendRevokeApi()
let response = await this.messageRevokeApi()
showSuccessInfo(response)
$('#modalSendRevoke').modal('hide');
$('#modalMessageRevoke').modal('hide');
} catch (err) {
showErrorInfo(err)
}
},
sendRevokeApi() {
messageRevokeApi() {
return new Promise(async (resolve, reject) => {
try {
this.revoke_loading = true;
let payload = new FormData();
payload.append("phone", this.revoke_phone_id)
let response = await http.post(`/message/${this.revoke_message_id}/revoke`, payload)
this.sendRevokeReset();
this.messageRevokeReset();
resolve(response.data.message)
} catch (error) {
if (error.response) {
@ -1171,7 +1230,7 @@
}
})
},
sendRevokeReset() {
messageRevokeReset() {
this.revoke_phone = '';
this.revoke_message_id = '';
this.revoke_type = 'user';
@ -1179,6 +1238,68 @@
}
}
const messageReact = {
data() {
return {
react_type: 'user',
react_phone: '',
react_message_id: '',
react_emoji: '',
react_loading: false,
}
},
computed: {
react_phone_id() {
return this.react_type === 'user' ? `${this.react_phone}@${this.type_user}` : `${this.react_phone}@${this.type_group}`
}
},
methods: {
messageReactModal() {
$('#modalMessageReaction').modal({
onApprove: function () {
return false;
}
}).modal('show');
},
async messageReactProcess() {
try {
let response = await this.messageReactApi()
showSuccessInfo(response)
$('#modalMessageReaction').modal('hide');
} catch (err) {
showErrorInfo(err)
}
},
messageReactApi() {
return new Promise(async (resolve, reject) => {
try {
this.react_loading = true;
let payload = new FormData();
payload.append("phone", this.react_phone_id)
payload.append("emoji", this.react_emoji)
let response = await http.post(`/message/${this.react_message_id}/reaction`, payload)
this.messageReactReset();
resolve(response.data.message)
} catch (error) {
if (error.response) {
reject(error.response.data.message)
} else {
reject(error.message)
}
} finally {
this.react_loading = false;
}
})
},
messageReactReset() {
this.react_phone = '';
this.react_message_id = '';
this.react_emoji = '';
this.react_type = 'user';
},
}
}
const sendLocation = {
data() {
return {
@ -1486,7 +1607,8 @@
},
mixins: [
login, logout, reconnect,
sendMessage, sendImage, sendFile, sendVideo, sendContact, sendRevoke, sendLocation,
sendMessage, sendImage, sendFile, sendVideo, sendContact, sendLocation,
messageRevoke, messageReact,
userGroups, userPrivacy, userAvatar, userInfo
]
}).mount('#app')

Loading…
Cancel
Save