Browse Source

add license, update vendor packages, update logic validate number before sending message

pull/48/head v1.4.1
Dimas Restu H 3 years ago
parent
commit
dc84b677f3
  1. 44
      .env.development
  2. 12
      .env.example
  3. 44
      .env.production
  4. 4
      .goreleaser.yml
  5. 2
      Dockerfile
  6. 7
      LICENSE
  7. 10
      README.md
  8. 8
      go.mod
  9. 16
      go.sum
  10. 48
      pkg/whatsapp/whatsapp.go

44
.env.development

@ -1,44 +0,0 @@
# -----------------------------------
# Server Configuration
# -----------------------------------
SERVER_ADDRESS=127.0.0.1
SERVER_PORT=3000
# -----------------------------------
# HTTP Configuration
# -----------------------------------
HTTP_BASE_URL=/api/v1/whatsapp
# HTTP_CORS_ORIGIN=*
# HTTP_BODY_LIMIT_SIZE=8m
# HTTP_GZIP_LEVEL=1
# HTTP_CACHE_CAPACITY=100
# HTTP_CACHE_TTL_SECONDS=5
# -----------------------------------
# Authentication Configuration
# -----------------------------------
AUTH_BASIC_USERNAME=admin
AUTH_BASIC_PASSWORD=83e4060e-78e1-4fe5-9977-aeeccd46a2b8
AUTH_JWT_SECRET=9e4eb4cf-be25-4a29-bba3-fefb5a30f6ab
AUTH_JWT_EXPIRED_HOUR=24
# -----------------------------------
# WhatsApp Configuration
# -----------------------------------
WHATSAPP_DATASTORE_TYPE=sqlite
WHATSAPP_DATASTORE_URI=file:dbs/WhatsApp.db?_foreign_keys=on
WHATSAPP_MEDIA_IMAGE_COMPRESSION=true
WHATSAPP_MEDIA_IMAGE_CONVERT_WEBP=true
# WHATSAPP_VERSION_MAJOR=2
# WHATSAPP_VERSION_MINOR=2220
# WHATSAPP_VERSION_PATCH=8
# -----------------------------------
# 3rd Party Configuration
# -----------------------------------
LIBWEBP_VERSION=0.6.1

12
.env.default → .env.example

@ -19,11 +19,11 @@ HTTP_BASE_URL=/api/v1/whatsapp
# -----------------------------------
# Authentication Configuration
# -----------------------------------
AUTH_BASIC_USERNAME=admin
AUTH_BASIC_PASSWORD=password
# AUTH_BASIC_USERNAME=ThisIsUsername
AUTH_BASIC_PASSWORD=ThisIsPassword
AUTH_JWT_SECRET=secret
AUTH_JWT_EXPIRED_HOUR=24
AUTH_JWT_SECRET=ThisIsJWTSecret
AUTH_JWT_EXPIRED_HOUR=0
# -----------------------------------
# WhatsApp Configuration
@ -35,8 +35,8 @@ WHATSAPP_MEDIA_IMAGE_COMPRESSION=true
WHATSAPP_MEDIA_IMAGE_CONVERT_WEBP=true
# WHATSAPP_VERSION_MAJOR=2
# WHATSAPP_VERSION_MINOR=2220
# WHATSAPP_VERSION_PATCH=8
# WHATSAPP_VERSION_MINOR=2245
# WHATSAPP_VERSION_PATCH=9
# -----------------------------------
# 3rd Party Configuration

44
.env.production

@ -1,44 +0,0 @@
# -----------------------------------
# Server Configuration
# -----------------------------------
SERVER_ADDRESS=0.0.0.0
SERVER_PORT=3000
# -----------------------------------
# HTTP Configuration
# -----------------------------------
HTTP_BASE_URL=/api/v1/whatsapp
# HTTP_CORS_ORIGIN=*
# HTTP_BODY_LIMIT_SIZE=8m
# HTTP_GZIP_LEVEL=1
# HTTP_CACHE_CAPACITY=100
# HTTP_CACHE_TTL_SECONDS=5
# -----------------------------------
# Authentication Configuration
# -----------------------------------
AUTH_BASIC_USERNAME=admin
AUTH_BASIC_PASSWORD=83e4060e-78e1-4fe5-9977-aeeccd46a2b8
AUTH_JWT_SECRET=9e4eb4cf-be25-4a29-bba3-fefb5a30f6ab
AUTH_JWT_EXPIRED_HOUR=24
# -----------------------------------
# WhatsApp Configuration
# -----------------------------------
WHATSAPP_DATASTORE_TYPE=sqlite
WHATSAPP_DATASTORE_URI=file:dbs/WhatsApp.db?_foreign_keys=on
WHATSAPP_MEDIA_IMAGE_COMPRESSION=true
WHATSAPP_MEDIA_IMAGE_CONVERT_WEBP=true
# WHATSAPP_VERSION_MAJOR=2
# WHATSAPP_VERSION_MINOR=2220
# WHATSAPP_VERSION_PATCH=8
# -----------------------------------
# 3rd Party Configuration
# -----------------------------------
LIBWEBP_VERSION=0.6.1

4
.goreleaser.yml

@ -24,7 +24,9 @@ archives:
amd64: 64-bit
format: zip
files:
- .env.default
- LICENSE
- README.md
- .env.example
- dbs/.gitkeep
checksum:
name_template: 'checksums.txt'

2
Dockerfile

@ -23,7 +23,7 @@ WORKDIR /usr/app/${SERVICE_NAME}
RUN mkdir -p {.bin/webp,dbs} \
&& chmod 775 {.bin/webp,dbs}
COPY --from=go-builder /usr/src/app/.env.default ./.env
COPY --from=go-builder /usr/src/app/.env.example ./.env
COPY --from=go-builder /usr/src/app/main ./main
EXPOSE 3000

7
LICENSE

@ -0,0 +1,7 @@
Copyright (C) 2022 Dimas Restu Hidayanto
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

10
README.md

@ -150,3 +150,13 @@ See also the list of [contributors](https://github.com/dimaskiddo/go-whatsapp-mu
## Annotation
You can seek more information for the make command parameters in the [Makefile](https://github.com/dimaskiddo/go-whatsapp-multidevice-rest/-/raw/master/Makefile)
## License
Copyright (C) 2022 Dimas Restu Hidayanto
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

8
go.mod

@ -16,8 +16,8 @@ require (
github.com/sunshineplan/imgconv v1.0.5
github.com/swaggo/echo-swagger v1.3.2
github.com/swaggo/swag v1.8.1
go.mau.fi/whatsmeow v0.0.0-20220811191500-f650c10b0068
google.golang.org/protobuf v1.28.0
go.mau.fi/whatsmeow v0.0.0-20221122081206-059049466d44
google.golang.org/protobuf v1.28.1
modernc.org/sqlite v1.17.0
)
@ -60,8 +60,8 @@ require (
github.com/valyala/bytebufferpool v1.0.0 // indirect
github.com/valyala/fasttemplate v1.2.1 // indirect
github.com/xi2/xz v0.0.0-20171230120015-48954b6210f8 // indirect
go.mau.fi/libsignal v0.0.0-20220628090436-4d18b66b087e // indirect
golang.org/x/crypto v0.0.0-20220622213112-05595931fe9d // indirect
go.mau.fi/libsignal v0.0.0-20221015105917-d970e7c3c9cf // indirect
golang.org/x/crypto v0.0.0-20221012134737-56aed061732a // indirect
golang.org/x/image v0.0.0-20211028202545-6944b10bf410 // indirect
golang.org/x/mod v0.6.0-dev.0.20220106191415-9b9b3d81d5e3 // indirect
golang.org/x/net v0.0.0-20220425223048-2871e0cb64e4 // indirect

16
go.sum

@ -222,10 +222,10 @@ github.com/yuin/goldmark v1.1.27/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9de
github.com/yuin/goldmark v1.2.1/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74=
github.com/yuin/goldmark v1.4.0/go.mod h1:mwnBkeHKe2W/ZEtQ+71ViKU8L12m81fl3OWwC1Zlc8k=
github.com/yuin/goldmark v1.4.1/go.mod h1:mwnBkeHKe2W/ZEtQ+71ViKU8L12m81fl3OWwC1Zlc8k=
go.mau.fi/libsignal v0.0.0-20220628090436-4d18b66b087e h1:ByHDg+D+dMIGuBA2n+1xOUf4xr3FJFYg8yxl06s1YBE=
go.mau.fi/libsignal v0.0.0-20220628090436-4d18b66b087e/go.mod h1:RCdzkTWSJv0AKGqurzPXJsEGIVMuQps3E/h7CMUPous=
go.mau.fi/whatsmeow v0.0.0-20220811191500-f650c10b0068 h1:DgSTWZ1LHSBxJFa3dvTvtMJGzqfYjinUFGLR3DujEts=
go.mau.fi/whatsmeow v0.0.0-20220811191500-f650c10b0068/go.mod h1:hsjqq2xLuoFew8vbsDCJcGf5EbXCRcR/yoQ+87w6m3k=
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/whatsmeow v0.0.0-20221122081206-059049466d44 h1:2VmJLzAZh/yQIt0hmbwBeciHQpC1tyfX9l1gOUGhhTI=
go.mau.fi/whatsmeow v0.0.0-20221122081206-059049466d44/go.mod h1:2yweL8nczvtlIxkrvCb0y8xiO13rveX9lJPambwYV/E=
go.opentelemetry.io/otel v0.5.0/go.mod h1:jzBIgIzK43Iu1BpDAXwqOd6UPsSAk+ewVZ5ofSXw4Ek=
go.opentelemetry.io/otel v0.6.0/go.mod h1:jzBIgIzK43Iu1BpDAXwqOd6UPsSAk+ewVZ5ofSXw4Ek=
go.opentelemetry.io/otel v0.7.0/go.mod h1:aZMyHG5TqDOXEgH2tyLiXSUKly1jT3yqE9PmrzIeCdo=
@ -237,8 +237,8 @@ golang.org/x/crypto v0.0.0-20200622213623-75b288015ac9/go.mod h1:LzIPMQfyMNhhGPh
golang.org/x/crypto v0.0.0-20210817164053-32db794688a5/go.mod h1:GvvjBRRGRdwPK5ydBHafDWAxML/pGHZbMvKqRZ5+Abc=
golang.org/x/crypto v0.0.0-20210921155107-089bfa567519/go.mod h1:GvvjBRRGRdwPK5ydBHafDWAxML/pGHZbMvKqRZ5+Abc=
golang.org/x/crypto v0.0.0-20220411220226-7b82a4e95df4/go.mod h1:IxCIyHEi3zRg3s0A5j5BB6A9Jmi73HwBIUl50j+osU4=
golang.org/x/crypto v0.0.0-20220622213112-05595931fe9d h1:sK3txAijHtOK88l68nt020reeT1ZdKLIYetKl95FzVY=
golang.org/x/crypto v0.0.0-20220622213112-05595931fe9d/go.mod h1:IxCIyHEi3zRg3s0A5j5BB6A9Jmi73HwBIUl50j+osU4=
golang.org/x/crypto v0.0.0-20221012134737-56aed061732a h1:NmSIgad6KjE6VvHciPZuNRTKxGhlPfD6OA87W/PLkqg=
golang.org/x/crypto v0.0.0-20221012134737-56aed061732a/go.mod h1:IxCIyHEi3zRg3s0A5j5BB6A9Jmi73HwBIUl50j+osU4=
golang.org/x/exp v0.0.0-20190121172915-509febef88a4/go.mod h1:CJ0aWSM057203Lf6IL+f9T1iT9GByDxfZKAQTCR3kQA=
golang.org/x/image v0.0.0-20190823064033-3a9bac650e44/go.mod h1:FeLwcggjj3mMvU+oOTbSwawSJRM1uh48EjtB4UJZlP0=
golang.org/x/image v0.0.0-20191009234506-e7c1f5e7dbb8/go.mod h1:FeLwcggjj3mMvU+oOTbSwawSJRM1uh48EjtB4UJZlP0=
@ -363,8 +363,8 @@ google.golang.org/protobuf v1.23.0/go.mod h1:EGpADcykh3NcUnDUJcl1+ZksZNG86OlYog2
google.golang.org/protobuf v1.23.1-0.20200526195155-81db48ad09cc/go.mod h1:EGpADcykh3NcUnDUJcl1+ZksZNG86OlYog2l/sGQquU=
google.golang.org/protobuf v1.25.0/go.mod h1:9JNX74DMeImyA3h4bdi1ymwjUzf21/xIlbajtzgsN7c=
google.golang.org/protobuf v1.26.0-rc.1/go.mod h1:jlhhOSvTdKEhbULTjvd4ARK9grFBp09yW+WbY/TyQbw=
google.golang.org/protobuf v1.28.0 h1:w43yiav+6bVFTBQFZX0r7ipe9JQ1QsbMgHwbBziscLw=
google.golang.org/protobuf v1.28.0/go.mod h1:HV8QOd/L58Z+nl8r43ehVNZIU/HEI6OcFqwMG9pJV4I=
google.golang.org/protobuf v1.28.1 h1:d0NfwRgPtno5B1Wa6L2DAG+KivqkdutMf1UhdNx175w=
google.golang.org/protobuf v1.28.1/go.mod h1:HV8QOd/L58Z+nl8r43ehVNZIU/HEI6OcFqwMG9pJV4I=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/check.v1 v1.0.0-20190902080502-41f04d3bba15/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=

48
pkg/whatsapp/whatsapp.go

@ -310,6 +310,9 @@ func WhatsAppSendText(ctx context.Context, jid string, rjid string, message stri
// Compose New Remote JID
remoteJID := WhatsAppComposeJID(rjid)
if WhatsAppGetJID(jid, remoteJID.String()).IsEmpty() {
return "", errors.New("WhatsApp Personal ID is Not Registered")
}
// Set Chat Presence
WhatsAppComposeStatus(jid, remoteJID, true, false)
@ -346,6 +349,9 @@ func WhatsAppSendLocation(ctx context.Context, jid string, rjid string, latitude
// Compose New Remote JID
remoteJID := WhatsAppComposeJID(rjid)
if WhatsAppGetJID(jid, remoteJID.String()).IsEmpty() {
return "", errors.New("WhatsApp Personal ID is Not Registered")
}
// Set Chat Presence
WhatsAppComposeStatus(jid, remoteJID, true, false)
@ -385,6 +391,9 @@ func WhatsAppSendDocument(ctx context.Context, jid string, rjid string, fileByte
// Compose New Remote JID
remoteJID := WhatsAppComposeJID(rjid)
if WhatsAppGetJID(jid, remoteJID.String()).IsEmpty() {
return "", errors.New("WhatsApp Personal ID is Not Registered")
}
// Set Chat Presence
WhatsAppComposeStatus(jid, remoteJID, true, false)
@ -437,6 +446,9 @@ func WhatsAppSendImage(ctx context.Context, jid string, rjid string, imageBytes
// Compose New Remote JID
remoteJID := WhatsAppComposeJID(rjid)
if WhatsAppGetJID(jid, remoteJID.String()).IsEmpty() {
return "", errors.New("WhatsApp Personal ID is Not Registered")
}
// Set Chat Presence
WhatsAppComposeStatus(jid, remoteJID, true, false)
@ -525,19 +537,19 @@ func WhatsAppSendImage(ctx context.Context, jid string, rjid string, imageBytes
msgId := whatsmeow.GenerateMessageID()
msgContent := &waproto.Message{
ImageMessage: &waproto.ImageMessage{
Url: proto.String(imageUploaded.URL),
DirectPath: proto.String(imageUploaded.DirectPath),
Mimetype: proto.String(imageType),
Caption: proto.String(imageCaption),
FileLength: proto.Uint64(imageUploaded.FileLength),
FileSha256: imageUploaded.FileSHA256,
FileEncSha256: imageUploaded.FileEncSHA256,
MediaKey: imageUploaded.MediaKey,
JpegThumbnail: imgThumbEncode.Bytes(),
Url: proto.String(imageUploaded.URL),
DirectPath: proto.String(imageUploaded.DirectPath),
Mimetype: proto.String(imageType),
Caption: proto.String(imageCaption),
FileLength: proto.Uint64(imageUploaded.FileLength),
FileSha256: imageUploaded.FileSHA256,
FileEncSha256: imageUploaded.FileEncSHA256,
MediaKey: imageUploaded.MediaKey,
JpegThumbnail: imgThumbEncode.Bytes(),
ThumbnailDirectPath: &imageThumbUploaded.DirectPath,
ThumbnailSha256: imageThumbUploaded.FileSHA256,
ThumbnailEncSha256: imageThumbUploaded.FileEncSHA256,
ViewOnce: proto.Bool(isViewOnce),
ViewOnce: proto.Bool(isViewOnce),
},
}
@ -566,6 +578,9 @@ func WhatsAppSendAudio(ctx context.Context, jid string, rjid string, audioBytes
// Compose New Remote JID
remoteJID := WhatsAppComposeJID(rjid)
if WhatsAppGetJID(jid, remoteJID.String()).IsEmpty() {
return "", errors.New("WhatsApp Personal ID is Not Registered")
}
// Set Chat Presence
WhatsAppComposeStatus(jid, remoteJID, true, true)
@ -616,6 +631,9 @@ func WhatsAppSendVideo(ctx context.Context, jid string, rjid string, videoBytes
// Compose New Remote JID
remoteJID := WhatsAppComposeJID(rjid)
if WhatsAppGetJID(jid, remoteJID.String()).IsEmpty() {
return "", errors.New("WhatsApp Personal ID is Not Registered")
}
// Set Chat Presence
WhatsAppComposeStatus(jid, remoteJID, true, false)
@ -668,6 +686,9 @@ func WhatsAppSendContact(ctx context.Context, jid string, rjid string, contactNa
// Compose New Remote JID
remoteJID := WhatsAppComposeJID(rjid)
if WhatsAppGetJID(jid, remoteJID.String()).IsEmpty() {
return "", errors.New("WhatsApp Personal ID is Not Registered")
}
// Set Chat Presence
WhatsAppComposeStatus(jid, remoteJID, true, false)
@ -709,6 +730,9 @@ func WhatsAppSendLink(ctx context.Context, jid string, rjid string, linkCaption
// Compose New Remote JID
remoteJID := WhatsAppComposeJID(rjid)
if WhatsAppGetJID(jid, remoteJID.String()).IsEmpty() {
return "", errors.New("WhatsApp Personal ID is Not Registered")
}
// Set Chat Presence
WhatsAppComposeStatus(jid, remoteJID, true, false)
@ -727,6 +751,7 @@ func WhatsAppSendLink(ctx context.Context, jid string, rjid string, linkCaption
msgContent := &waproto.Message{
ExtendedTextMessage: &waproto.ExtendedTextMessage{
Text: proto.String(msgText),
MatchedText: proto.String(msgCaption),
CanonicalUrl: proto.String(linkURL),
ContextInfo: &waproto.ContextInfo{
ActionLink: &waproto.ActionLink{
@ -762,6 +787,9 @@ func WhatsAppSendSticker(ctx context.Context, jid string, rjid string, stickerBy
// Compose New Remote JID
remoteJID := WhatsAppComposeJID(rjid)
if WhatsAppGetJID(jid, remoteJID.String()).IsEmpty() {
return "", errors.New("WhatsApp Personal ID is Not Registered")
}
// Set Chat Presence
WhatsAppComposeStatus(jid, remoteJID, true, false)

Loading…
Cancel
Save