Skip to content

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

feat: add send poll message (#118)

Aldino Kemal90634bbf4f7c
diff --git a/.github/workflows/release-linux.yml b/.github/workflows/release-linux.yml
index 8ef5d7c9..cefdec9e 100644
--- a/.github/workflows/release-linux.yml
+++ b/.github/workflows/release-linux.yml
@@ -23,13 +23,9 @@ jobs:
uses: actions/setup-go@v4
with:
go-version: '1.21'
- - name: Golang setup dependency
- run: |
- go version
- go install github.com/markbates/pkger/cmd/pkger@latest
- name: Golang build
run: |
- cd src && pkger && go build -o linux-amd64
+ cd src && go build -o linux-amd64
- name: Deploy artifact to release ${{ github.ref_name }}
uses: AButler/[email protected]
with:
@@ -51,13 +47,9 @@ jobs:
uses: actions/setup-go@v4
with:
go-version: '1.21'
- - name: Golang setup dependency
- run: |
- go version
- go install github.com/markbates/pkger/cmd/pkger@latest
- name: Golang build
run: |
- cd src && pkger && go build -o linux-arm64
+ cd src && go build -o linux-arm64
- name: Deploy artifact to release ${{ github.ref_name }}
uses: AButler/[email protected]
with:
diff --git a/.github/workflows/release-mac.yml b/.github/workflows/release-mac.yml
index 9aa3bb8a..eeeec298 100644
--- a/.github/workflows/release-mac.yml
+++ b/.github/workflows/release-mac.yml
@@ -22,13 +22,9 @@ jobs:
uses: actions/setup-go@v4
with:
go-version: '1.21'
- - name: Golang setup dependency
- run: |
- go version
- go install github.com/markbates/pkger/cmd/pkger@latest
- name: Golang build
run: |
- cd src && pkger && go build -o darwin-amd64
+ cd src && go build -o darwin-amd64
- name: Deploy artifact to release ${{ github.ref_name }}
uses: AButler/[email protected]
with:
diff --git a/.github/workflows/release-windows.yml b/.github/workflows/release-windows.yml
index 4095d34d..45679466 100644
--- a/.github/workflows/release-windows.yml
+++ b/.github/workflows/release-windows.yml
@@ -35,15 +35,11 @@ jobs:
uses: actions/setup-go@v4
with:
go-version: '1.21'
- - name: Golang setup dependency
- run: |
- go version
- go install github.com/markbates/pkger/cmd/pkger@latest
- name: Golang build
run: |
[Environment]::SetEnvironmentVariable("Path", $env:Path + ";${{ github.workspace }}\vips-dev-8.12\bin")
[Environment]::SetEnvironmentVariable("PKG_CONFIG_PATH", "${{ github.workspace }}\vips-dev-8.12\lib\pkgconfig")
- cd src && pkger.exe && go build -o windows-amd64.exe
+ cd src && go build -o windows-amd64.exe
- name: Deploy artifact to release ${{ github.ref_name }}
uses: AButler/[email protected]
with:
diff --git a/docker/golang.Dockerfile b/docker/golang.Dockerfile
index b82a1c0d..d25f9235 100644
--- a/docker/golang.Dockerfile
+++ b/docker/golang.Dockerfile
@@ -8,10 +8,8 @@ COPY ./src .
# Fetch dependencies.
RUN go mod download
-# Install pkger
-RUN go install github.com/markbates/pkger/cmd/pkger@latest
# Build the binary.
-RUN pkger && go build -o /app/whatsapp
+RUN go build -o /app/whatsapp
#############################
## STEP 2 build a smaller image
diff --git a/docs/openapi.yaml b/docs/openapi.yaml
index 42e72510..b485f967 100644
--- a/docs/openapi.yaml
+++ b/docs/openapi.yaml
@@ -1,7 +1,7 @@
openapi: 3.0.0
info:
title: WhatsApp API MultiDevice
- version: 3.7.0
+ version: 3.8.0
description: This API is used for sending whatsapp via API
servers:
- url: http://localhost:3000
@@ -548,6 +548,61 @@ paths:
application/json:
schema:
$ref: '#/components/schemas/ErrorInternalServer'
+ /send/poll:
+ post:
+ operationId: sendPoll
+ tags:
+ - send
+ summary: Send Poll / Vote
+ requestBody:
+ required: true
+ content:
+ application/json:
+ schema:
+ type: object
+ properties:
+ phone:
+ type: string
+ description: The WhatsApp phone number to send the poll to, including the '@s.whatsapp.net' suffix.
+ example: '[email protected]'
+ question:
+ type: string
+ description: The question for the poll.
+ example: 'Siapa Nama Avatar The Last Air Bender?'
+ options:
+ type: array
+ description: The options for the poll.
+ items:
+ type: string
+ example: [ 'Zuko', 'Aang', 'Katara' ]
+ max_answer:
+ type: integer
+ description: The maximum number of answers allowed for the poll.
+ example: 2
+ required:
+ - phone
+ - question
+ - options
+ - max_answer
+ responses:
+ '200':
+ description: OK
+ content:
+ application/json:
+ schema:
+ $ref: '#/components/schemas/SendResponse'
+ '400':
+ description: Bad Request
+ content:
+ application/json:
+ schema:
+ $ref: '#/components/schemas/ErrorBadRequest'
+ '500':
+ description: Internal Server Error
+ content:
+ application/json:
+ schema:
+ $ref: '#/components/schemas/ErrorInternalServer'
/message/{message_id}/revoke:
post:
operationId: revokeMessage
diff --git a/readme.md b/readme.md
index b914abcf..aade8ace 100644
--- a/readme.md
+++ b/readme.md
@@ -8,13 +8,15 @@
![release linux](https://github.com/aldinokemal/go-whatsapp-web-multidevice/actions/workflows/release-linux.yml/badge.svg)
![release macos](https://github.com/aldinokemal/go-whatsapp-web-multidevice/actions/workflows/release-mac.yml/badge.svg)
-### Support `ARM` Architecture
-Now that we support ARM64 for Linux:
-- [Release](https://github.com/aldinokemal/go-whatsapp-web-multidevice/releases/latest) for ARM64
-- [Docker Image](https://hub.docker.com/r/aldinokemal2104/go-whatsapp-web-multidevice/tags) for ARM64.
+### Support `ARM` Architecture
+
+Now that we support ARM64 for Linux:
+- [Release](https://github.com/aldinokemal/go-whatsapp-web-multidevice/releases/latest) for ARM64
+- [Docker Image](https://hub.docker.com/r/aldinokemal2104/go-whatsapp-web-multidevice/tags) for ARM64.
### Feature
+
- Send whatsapp via http API, [docs/openapi.yml](./docs/openapi.yaml) for more details
- Compress image before send
- Compress video before send
@@ -84,6 +86,7 @@ Now that we support ARM64 for Linux:
7. open `http://localhost:3000` in browser
### Production Mode (docker)
+
```
docker run --detach --publish=3000:3000 --name=whatsapp --restart=always --volume=$(docker volume create --name=whatsapp):/app/storages aldinokemal2104/go-whatsapp-web-multidevice --autoreply="Dont't reply this message please"
```
@@ -116,6 +119,7 @@ API using [openapi-generator](https://openapi-generator.tech/#try)
| ✅ | Send Contact | POST | /send/contact |
| ✅ | Send Link | POST | /send/link |
| ✅ | Send Location | POST | /send/location |
+| ✅ | Send Poll / Vote | POST | /send/poll |
| ✅ | Revoke Message | POST | /message/:message_id/revoke |
| ✅ | React Message | POST | /message/:message_id/react |
| ✅ | Join Group With Link | POST | /group/join-with-link |
@@ -128,7 +132,7 @@ API using [openapi-generator](https://openapi-generator.tech/#try)
### App User Interface
-1. Homepage ![Homepage](https://i.ibb.co/PZ38XYR/Homepage.png)
+1. Homepage ![Homepage](https://i.ibb.co/RDBjmz1/homepage.png)
2. Login ![Login](https://i.ibb.co/jkcB15R/login.png)
3. Send Message ![Send Message](https://i.ibb.co/rc3NXMX/send-message.png)
4. Send Image ![Send Image](https://i.ibb.co/BcFL3SD/send-image.png)
@@ -137,14 +141,15 @@ API using [openapi-generator](https://openapi-generator.tech/#try)
7. Send Contact ![Send Contact](https://i.ibb.co/4810H7N/send-contact.png)
8. Send Location ![Send Location](https://i.ibb.co/TWsy09G/send-location.png)
9. Send Audio ![Send Location](https://i.ibb.co/p1wL4wh/Send-Audio.png)
-10. Revoke Message ![Revoke Message](https://i.ibb.co/yswhvQY/revoke.png?)
-11. Reaction Message ![Revoke Message](https://i.ibb.co/BfHgSHG/react-message.png)
-12. User Info ![User Info](https://i.ibb.co/3zjX6Cz/user-info.png)
-13. User Avatar ![User Avatar](https://i.ibb.co/ZmJZ4ZW/search-avatar.png)
-14. My Privacy ![My Privacy](https://i.ibb.co/Cw1sMQz/my-privacy.png)
-15. My Group ![My Group](https://i.ibb.co/WB268Xy/list-group.png)
-16. Auto Reply ![Auto Reply](https://i.ibb.co/D4rTytX/IMG-20220517-162500.jpg)
-17. Basic Auth Prompt ![Basic Auth](https://i.ibb.co/PDjQ92W/Screenshot-2022-11-06-at-14-06-29.png)
+10. Send Poll ![Send Poll](https://i.ibb.co/mq2fGHz/send-poll.png)
+11. Revoke Message ![Revoke Message](https://i.ibb.co/yswhvQY/revoke.png?)
+12. Reaction Message ![Revoke Message](https://i.ibb.co/BfHgSHG/react-message.png)
+13. User Info ![User Info](https://i.ibb.co/3zjX6Cz/user-info.png)
+14. User Avatar ![User Avatar](https://i.ibb.co/ZmJZ4ZW/search-avatar.png)
+15. My Privacy ![My Privacy](https://i.ibb.co/Cw1sMQz/my-privacy.png)
+16. My Group ![My Group](https://i.ibb.co/WB268Xy/list-group.png)
+17. Auto Reply ![Auto Reply](https://i.ibb.co/D4rTytX/IMG-20220517-162500.jpg)
+18. Basic Auth Prompt ![Basic Auth](https://i.ibb.co/PDjQ92W/Screenshot-2022-11-06-at-14-06-29.png)
### Mac OS NOTE
diff --git a/src/cmd/root.go b/src/cmd/root.go
index 2f12f4e5..247a519e 100644
--- a/src/cmd/root.go
+++ b/src/cmd/root.go
@@ -1,6 +1,7 @@
package cmd
import (
+ "embed"
"fmt"
"github.com/aldinokemal/go-whatsapp-web-multidevice/config"
"github.com/aldinokemal/go-whatsapp-web-multidevice/internal/rest"
@@ -14,16 +15,22 @@ import (
"github.com/gofiber/fiber/v2"
"github.com/gofiber/fiber/v2/middleware/basicauth"
"github.com/gofiber/fiber/v2/middleware/cors"
+ "github.com/gofiber/fiber/v2/middleware/filesystem"
"github.com/gofiber/fiber/v2/middleware/logger"
"github.com/gofiber/template/html/v2"
- "github.com/markbates/pkger"
_ "github.com/mattn/go-sqlite3"
"github.com/spf13/cobra"
"log"
+ "net/http"
"os"
"strings"
)
+var (
+ EmbedViews embed.FS
+ EmbedViewsComponent embed.FS
+)
+
// rootCmd represents the base command when called without any subcommands
var rootCmd = &cobra.Command{
Short: "Send free whatsapp API",
@@ -54,7 +61,7 @@ func runRest(_ *cobra.Command, _ []string) {
log.Fatalln(err)
}
- engine := html.NewFileSystem(pkger.Dir("/views"), ".html")
+ engine := html.NewFileSystem(http.FS(EmbedViews), ".html")
engine.AddFunc("isEnableBasicAuth", func(token any) bool {
return token != nil
})
@@ -63,6 +70,11 @@ func runRest(_ *cobra.Command, _ []string) {
BodyLimit: 50 * 1024 * 1024,
})
app.Static("/statics", "./statics")
+ app.Use("/components", filesystem.New(filesystem.Config{
+ Root: http.FS(EmbedViewsComponent),
+ PathPrefix: "views/components",
+ Browse: true,
+ }))
app.Use(middleware.Recovery())
app.Use(middleware.BasicAuth())
if config.AppDebug {
@@ -109,7 +121,7 @@ func runRest(_ *cobra.Command, _ []string) {
rest.InitRestGroup(app, groupService)
app.Get("/", func(c *fiber.Ctx) error {
- return c.Render("index", fiber.Map{
+ return c.Render("views/index", fiber.Map{
"AppHost": fmt.Sprintf("%s://%s", c.Protocol(), c.Hostname()),
"AppVersion": config.AppVersion,
"BasicAuthToken": c.UserContext().Value("token"),
@@ -129,7 +141,9 @@ func runRest(_ *cobra.Command, _ []string) {
}
// Execute adds all child commands to the root command and sets flags appropriately.
-func Execute() {
+func Execute(embedViews embed.FS, embedViewsComponent embed.FS) {
+ EmbedViews = embedViews
+ EmbedViewsComponent = embedViewsComponent
if err := rootCmd.Execute(); err != nil {
os.Exit(1)
}
diff --git a/src/config/settings.go b/src/config/settings.go
index 9005d6c7..2459a219 100644
--- a/src/config/settings.go
+++ b/src/config/settings.go
@@ -6,7 +6,7 @@ import (
)
var (
- AppVersion = "v4.10.0"
+ AppVersion = "v4.11.0"
AppPort = "3000"
AppDebug = false
AppOs = fmt.Sprintf("AldinoKemal")
diff --git a/src/domains/send/poll.go b/src/domains/send/poll.go
new file mode 100644
index 00000000..f3f8c32f
--- /dev/null
+++ b/src/domains/send/poll.go
@@ -0,0 +1,8 @@
+package send
+
+type PollRequest struct {
+ Phone string `json:"phone" form:"phone"`
+ 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/send.go b/src/domains/send/send.go
index c8480506..0e270c22 100644
--- a/src/domains/send/send.go
+++ b/src/domains/send/send.go
@@ -13,6 +13,7 @@ type ISendService interface {
SendLink(ctx context.Context, request LinkRequest) (response GenericResponse, err error)
SendLocation(ctx context.Context, request LocationRequest) (response GenericResponse, err error)
SendAudio(ctx context.Context, request AudioRequest) (response GenericResponse, err error)
+ SendPoll(ctx context.Context, request PollRequest) (response GenericResponse, err error)
}
type GenericResponse struct {
diff --git a/src/go.mod b/src/go.mod
index c76f93cc..5fc71ab8 100644
--- a/src/go.mod
+++ b/src/go.mod
@@ -11,7 +11,6 @@ require (
github.com/gofiber/websocket/v2 v2.2.1
github.com/google/uuid v1.6.0
github.com/h2non/bimg v1.1.9
- github.com/markbates/pkger v0.17.1
github.com/mattn/go-sqlite3 v1.14.22
github.com/sirupsen/logrus v1.9.3
github.com/skip2/go-qrcode v0.0.0-20200617195104-da1b6568686e
@@ -30,12 +29,12 @@ require (
github.com/asaskevich/govalidator v0.0.0-20230301143203-a9d515a09cc2 // indirect
github.com/davecgh/go-spew v1.1.1 // indirect
github.com/fasthttp/websocket v1.5.8 // indirect
- github.com/gobuffalo/here v0.6.7 // indirect
github.com/gofiber/template v1.8.3 // indirect
github.com/gofiber/utils v1.1.0 // indirect
github.com/gorilla/websocket v1.5.1 // indirect
github.com/inconshreveable/mousetrap v1.1.0 // indirect
github.com/klauspost/compress v1.17.7 // indirect
+ github.com/kr/pretty v0.1.0 // indirect
github.com/mattn/go-colorable v0.1.13 // indirect
github.com/mattn/go-isatty v0.0.20 // indirect
github.com/mattn/go-runewidth v0.0.15 // indirect
@@ -51,5 +50,6 @@ require (
golang.org/x/net v0.22.0 // indirect
golang.org/x/sys v0.18.0 // indirect
golang.org/x/xerrors v0.0.0-20220609144429-65e65417b02f // indirect
+ gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
)
diff --git a/src/go.sum b/src/go.sum
index 7d2e98a9..9adba982 100644
--- a/src/go.sum
+++ b/src/go.sum
@@ -1,14 +1,9 @@
filippo.io/edwards25519 v1.1.0 h1:FNf4tywRC1HmFuKW5xopWpigGjJKiJSV0Cqo0cJWDaA=
filippo.io/edwards25519 v1.1.0/go.mod h1:BxyFTGdWcka3PhytdK4V28tE5sGfRvvvRV7EaN4VDT4=
-github.com/PuerkitoBio/goquery v1.8.1 h1:uQxhNlArOIdbrH1tr0UXwdVFgDcZDrZVdcpygAcwmWM=
-github.com/PuerkitoBio/goquery v1.8.1/go.mod h1:Q8ICL1kNUJ2sXGoAhPGUdYDJvgQgHzJsnnd3H7Ho5jQ=
-github.com/PuerkitoBio/goquery v1.9.0 h1:zgjKkdpRY9T97Q5DCtcXwfqkcylSFIVCocZmn2huTp8=
-github.com/PuerkitoBio/goquery v1.9.0/go.mod h1:cW1n6TmIMDoORQU5IU/P1T3tGFunOeXEpGP2WHRwkbY=
github.com/PuerkitoBio/goquery v1.9.1 h1:mTL6XjbJTZdpfL+Gwl5U2h1l9yEkJjhmlTeV9VPW7UI=
github.com/PuerkitoBio/goquery v1.9.1/go.mod h1:cW1n6TmIMDoORQU5IU/P1T3tGFunOeXEpGP2WHRwkbY=
github.com/andybalholm/brotli v1.1.0 h1:eLKJA0d02Lf0mVpIDgYnqXcUn0GqVmEFny3VuID1U3M=
github.com/andybalholm/brotli v1.1.0/go.mod h1:sms7XGricyQI9K10gOSf56VKKWS4oLer58Q+mhRPtnY=
-github.com/andybalholm/cascadia v1.3.1/go.mod h1:R4bJ1UQfqADjvDa4P6HZHLh/3OxWWEqc0Sk8XGwHqvA=
github.com/andybalholm/cascadia v1.3.2 h1:3Xi6Dw5lHF15JtdcmAHD3i1+T8plmv7BQ/nsViSLyss=
github.com/andybalholm/cascadia v1.3.2/go.mod h1:7gtRlve5FxPPgIgX36uWBX58OdBsSS6lUvCFb+h7KvU=
github.com/asaskevich/govalidator v0.0.0-20200108200545-475eaeb16496/go.mod h1:oGkLhpf+kjZl6xBf758TQhh5XrAeiJv/7FRz/2spLIg=
@@ -21,28 +16,15 @@ 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.1 h1:GzkhY7T5VNhEkwH0PVJgjz+fX1rhBrR7pRT3mDkpeCY=
github.com/dustin/go-humanize v1.0.1/go.mod h1:Mu1zIs6XwVuF/gI1OepvI0qD18qycQx+mFykh5fBlto=
-github.com/fasthttp/websocket v1.5.7 h1:0a6o2OfeATvtGgoMKleURhLT6JqWPg7fYfWnH4KHau4=
-github.com/fasthttp/websocket v1.5.7/go.mod h1:bC4fxSono9czeXHQUVKxsC0sNjbm7lPJR04GDFqClfU=
github.com/fasthttp/websocket v1.5.8 h1:k5DpirKkftIF/w1R8ZzjSgARJrs54Je9YJK37DL/Ah8=
github.com/fasthttp/websocket v1.5.8/go.mod h1:d08g8WaT6nnyvg9uMm8K9zMYyDjfKyj3170AtPRuVU0=
github.com/go-ozzo/ozzo-validation/v4 v4.3.0 h1:byhDUpfEwjsVQb1vBunvIjh2BHQ9ead57VkAEY4V+Es=
github.com/go-ozzo/ozzo-validation/v4 v4.3.0/go.mod h1:2NKgrcHl3z6cJs+3Oo940FPRiTzuqKbvfrL2RxCj6Ew=
-github.com/gobuffalo/here v0.6.0/go.mod h1:wAG085dHOYqUpf+Ap+WOdrPTp5IYcDAs/x7PLa8Y5fM=
-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.52.0 h1:S+qXi7y+/Pgvqq4DrSmREGiFwtB7Bu6+QFLuIHYw/UE=
-github.com/gofiber/fiber/v2 v2.52.0/go.mod h1:KEOE+cXMhXG0zHc9d8+E38hoX+ZN7bhOtgeF2oT6jrQ=
-github.com/gofiber/fiber/v2 v2.52.1 h1:1RoU2NS+b98o1L77sdl5mboGPiW+0Ypsi5oLmcYlgHI=
-github.com/gofiber/fiber/v2 v2.52.1/go.mod h1:KEOE+cXMhXG0zHc9d8+E38hoX+ZN7bhOtgeF2oT6jrQ=
github.com/gofiber/fiber/v2 v2.52.2 h1:b0rYH6b06Df+4NyrbdptQL8ifuxw/Tf2DgfkZkDaxEo=
github.com/gofiber/fiber/v2 v2.52.2/go.mod h1:KEOE+cXMhXG0zHc9d8+E38hoX+ZN7bhOtgeF2oT6jrQ=
-github.com/gofiber/template v1.8.2 h1:PIv9s/7Uq6m+Fm2MDNd20pAFFKt5wWs7ZBd8iV9pWwk=
-github.com/gofiber/template v1.8.2/go.mod h1:bs/2n0pSNPOkRa5VJ8zTIvedcI/lEYxzV3+YPXdBvq8=
github.com/gofiber/template v1.8.3 h1:hzHdvMwMo/T2kouz2pPCA0zGiLCeMnoGsQZBTSYgZxc=
github.com/gofiber/template v1.8.3/go.mod h1:bs/2n0pSNPOkRa5VJ8zTIvedcI/lEYxzV3+YPXdBvq8=
-github.com/gofiber/template/html/v2 v2.1.0 h1:FjwzqhhdJpnhyCvav60Z1ytnBqOUr5sGO/aTeob9/ng=
-github.com/gofiber/template/html/v2 v2.1.0/go.mod h1:txXsRQN/G7Fr2cqGfr6zhVHgreCfpsBS+9+DJyrddJc=
github.com/gofiber/template/html/v2 v2.1.1 h1:QEy3O3EBkvwDthy5bXVGUseOyO6ldJoiDxlF4+MJiV8=
github.com/gofiber/template/html/v2 v2.1.1/go.mod h1:2G0GHHOUx70C1LDncoBpe4T6maQbNa4x1CVNFW0wju0=
github.com/gofiber/utils v1.1.0 h1:vdEBpn7AzIUJRhe+CiTOJdUcTg4Q9RK+pEa0KPbLdrM=
@@ -59,8 +41,6 @@ github.com/h2non/bimg v1.1.9 h1:WH20Nxko9l/HFm4kZCA3Phbgu2cbHvYzxwxn9YROEGg=
github.com/h2non/bimg v1.1.9/go.mod h1:R3+UiYwkK4rQl6KVFTOFJHitgLbZXBZNFh2cv3AEbp8=
github.com/inconshreveable/mousetrap v1.1.0 h1:wN+x4NVGpMsO7ErUn/mUI3vEoE6Jt13X2s0bqwp9tc8=
github.com/inconshreveable/mousetrap v1.1.0/go.mod h1:vpF70FUmC8bwa3OWnCshd2FqLfsEA9PFc4w1p2J65bw=
-github.com/klauspost/compress v1.17.5 h1:d4vBd+7CHydUqpFBgUEKkSdtSugf9YFmSkvUYPquI5E=
-github.com/klauspost/compress v1.17.5/go.mod h1:/dCuZOvVtNoHsyb+cuJD3itjs3NbnF6KH9zAO4BDxPM=
github.com/klauspost/compress v1.17.7 h1:ehO88t2UGzQK66LMdE8tibEd1ErmzZjNEqWkjLAKQQg=
github.com/klauspost/compress v1.17.7/go.mod h1:Di0epgTjJY877eYKx5yC51cX2A2Vl2ibi7bDH9ttBbw=
github.com/kr/pretty v0.1.0 h1:L/CwN0zerZDmRFUapSPitk6f+Q3+0za1rQkzVuMiMFI=
@@ -68,8 +48,6 @@ github.com/kr/pretty v0.1.0/go.mod h1:dAy3ld7l9f0ibDNOQOHHMYYIIbhfbHSm3C4ZsoJORN
github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ=
github.com/kr/text v0.1.0 h1:45sCR5RtlFHMR4UwH9sdQ5TC8v0qDQCHnXt+kaKSTVE=
github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI=
-github.com/markbates/pkger v0.17.1 h1:/MKEtWqtc0mZvu9OinB9UzVN9iYCwLWuyUv4Bw+PCno=
-github.com/markbates/pkger v0.17.1/go.mod h1:0JoVlrol20BSywW79rN3kdFFsE5xYM+rSCQDXbLhiuI=
github.com/mattn/go-colorable v0.1.13 h1:fFA4WZxdEF4tXPZVKMLwD8oUnCTTo08duU7wxecdEvA=
github.com/mattn/go-colorable v0.1.13/go.mod h1:7S9/ev0klgBDR4GtXTXX8a3vIGJpMovkB8vQcUbaXHg=
github.com/mattn/go-isatty v0.0.16/go.mod h1:kYGgaQfpe5nmfYZH+SKPsOc2e4SrIfOl2e/yFXSvRLM=
@@ -84,16 +62,12 @@ github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINE
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
github.com/rivo/uniseg v0.2.0/go.mod h1:J6wj4VEh+S6ZtnVlnTBMWIodfgj8LQOQFoIToxlJtxc=
-github.com/rivo/uniseg v0.4.6 h1:Sovz9sDSwbOz9tgUy8JpT+KgCkPYJEN/oYzlJiYTNLg=
-github.com/rivo/uniseg v0.4.6/go.mod h1:FN3SvrM+Zdj16jyLfmOkMNblXMcoc8DfTHruCPUcx88=
github.com/rivo/uniseg v0.4.7 h1:WUdvkW8uEhrYfLC4ZzdpI2ztxP1I582+49Oc5Mq64VQ=
github.com/rivo/uniseg v0.4.7/go.mod h1:FN3SvrM+Zdj16jyLfmOkMNblXMcoc8DfTHruCPUcx88=
github.com/rs/xid v1.5.0/go.mod h1:trrq9SKmegXys3aeAKXMUTdJsYXVwGY3RLcfgqegfbg=
github.com/rs/zerolog v1.32.0 h1:keLypqrlIjaFsbmJOBdB/qvyF8KEtCWHwobLp5l/mQ0=
github.com/rs/zerolog v1.32.0/go.mod h1:/7mN4D5sKwJLZQ2b/znpjC3/GQWY/xaDXUM0kKWRHss=
github.com/russross/blackfriday/v2 v2.1.0/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQDYRxCVz55jmeOWTM=
-github.com/savsgio/gotils v0.0.0-20230208104028-c358bd845dee h1:8Iv5m6xEo1NR1AvpV+7XmhI4r39LGNzwUL4YpMuL5vk=
-github.com/savsgio/gotils v0.0.0-20230208104028-c358bd845dee/go.mod h1:qwtSXrKuJh/zsFQ12yEE89xfCrGKK63Rr7ctU/uCo4g=
github.com/savsgio/gotils v0.0.0-20240303185622-093b76447511 h1:KanIMPX0QdEdB4R3CiimCAbxFrhB3j7h0/OvpYGVQa8=
github.com/savsgio/gotils v0.0.0-20240303185622-093b76447511/go.mod h1:sM7Mt7uEoCeFSCBM+qBrqvEo+/9vdmj19wzp3yzUhmg=
github.com/sirupsen/logrus v1.9.3 h1:dueUQJ1C2q9oE3F7wvmSGAaVtTmUizReu6fjN8uqzbQ=
@@ -105,19 +79,12 @@ github.com/spf13/cobra v1.8.0/go.mod h1:WXLWApfZ71AjXPya3WOlMsY9yMs7YeiHhFVlvLyh
github.com/spf13/pflag v1.0.5 h1:iy+VFUOCP1a+8yFto/drg2CJ5u0yRoB7fZw3DKv/JXA=
github.com/spf13/pflag v1.0.5/go.mod h1:McXfInJRrz4CZXVZOBLb0bTZqETkiAhM9Iw0y3An2Bg=
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
-github.com/stretchr/objx v0.4.0/go.mod h1:YvHI0jy2hoMjB+UWwv71VJQ9isScKT/TqJzVSSt89Yw=
github.com/stretchr/testify v1.4.0/go.mod h1:j7eGeouHqKxXV5pUuKE4zz7dFj8WfuZ+81PSLYec5m4=
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/go.mod h1:yNjHg4UonilssWZ8iaSj1OCr/vHnekPRkoO+kdMU+MU=
-github.com/stretchr/testify v1.8.4 h1:CcVxjf3Q8PM0mHUKJCdn+eZZtm5yQwehR5yeSVQQcUk=
-github.com/stretchr/testify v1.8.4/go.mod h1:sz/lmYIOXD/1dqDmKjjqLyZ2RngseejIcXlSw2iwfAo=
github.com/stretchr/testify v1.9.0 h1:HtqpIVDClZ4nwg75+f6Lvsy/wHu+3BoSGCbBAcpTsTg=
github.com/stretchr/testify v1.9.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY=
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.51.0 h1:8b30A5JlZ6C7AS81RsWjYMQmrZG6feChmgAolCl1SqA=
-github.com/valyala/fasthttp v1.51.0/go.mod h1:oI2XroL+lI7vdXyYoQk03bXBThfFl2cVdIA3Xl7cH8g=
github.com/valyala/fasthttp v1.52.0 h1:wqBQpxH71XW0e2g+Og4dzQM8pk34aFYlA1Ga8db7gU0=
github.com/valyala/fasthttp v1.52.0/go.mod h1:hf5C4QnVMkNXMspnsUlfM3WitlgYflyhHYoKol/szxQ=
github.com/valyala/tcplisten v1.0.0 h1:rBHj/Xf+E1tRGZyWIWwJDiRY0zc1Js+CV5DqwacVSA8=
@@ -125,35 +92,21 @@ github.com/valyala/tcplisten v1.0.0/go.mod h1:T0xQ8SeCZGxckz9qRXTfG43PvQ/mcWh7Fw
github.com/yuin/goldmark v1.4.13/go.mod h1:6yULJ656Px+3vBD8DxQVa3kxgyrAnzto9xy5taEt/CY=
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/util v0.3.1-0.20240208085450-32294da153ab h1:XZ8W5vHWlXSGmHn1U+Fvbh+xZr9wuHTvbY+qV7aybDY=
-go.mau.fi/util v0.3.1-0.20240208085450-32294da153ab/go.mod h1:rRypwgXVEPILomtFPyQcnbOeuRqf+nRN84vh/CICq4w=
go.mau.fi/util v0.4.0 h1:S2X3qU4pUcb/vxBRfAuZjbrR9xVMAXSjQojNBLPBbhs=
go.mau.fi/util v0.4.0/go.mod h1:leeiHtgVBuN+W9aDii3deAXnfC563iN3WK6BF8/AjNw=
-go.mau.fi/whatsmeow v0.0.0-20240209184912-c3e911dd6cfe h1:ZosSMvW46/bX5tEdXXgF+weMIPj+r8QG5ry7JSdDWt8=
-go.mau.fi/whatsmeow v0.0.0-20240209184912-c3e911dd6cfe/go.mod h1:lQHbhaG/fI+6hfGqz5Vzn2OBJBEZ05H0kCP6iJXriN4=
-go.mau.fi/whatsmeow v0.0.0-20240223131828-1bdd11e8ee3e h1:CGFBEsU6p3IHxpl0DTe7jpxXstyIASgjAJHJFZwamFU=
-go.mau.fi/whatsmeow v0.0.0-20240223131828-1bdd11e8ee3e/go.mod h1:lQHbhaG/fI+6hfGqz5Vzn2OBJBEZ05H0kCP6iJXriN4=
go.mau.fi/whatsmeow v0.0.0-20240308162537-79d9175fa09b h1:Jk0/Lu6LdLD4kh0L9Q+06n7EefcS8ZDAKpwGeX7C4YQ=
go.mau.fi/whatsmeow v0.0.0-20240308162537-79d9175fa09b/go.mod h1:lQHbhaG/fI+6hfGqz5Vzn2OBJBEZ05H0kCP6iJXriN4=
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
golang.org/x/crypto v0.0.0-20210921155107-089bfa567519/go.mod h1:GvvjBRRGRdwPK5ydBHafDWAxML/pGHZbMvKqRZ5+Abc=
-golang.org/x/crypto v0.19.0 h1:ENy+Az/9Y1vSrlrvBSyna3PITt4tiZLf7sgCjZBX7Wo=
-golang.org/x/crypto v0.19.0/go.mod h1:Iy9bg/ha4yyC70EfRS8jz+B6ybOBKMaSxLj6P6oBDfU=
golang.org/x/crypto v0.21.0 h1:X31++rzVUdKhX5sWmSOFZxx8UW/ldWx55cbf08iNAMA=
golang.org/x/crypto v0.21.0/go.mod h1:0BP7YvVV9gBbVKyeTG0Gyn+gZm94bibOW5BjDEYAOMs=
golang.org/x/mod v0.6.0-dev.0.20220419223038-86c51ed26bb4/go.mod h1:jJ57K6gSWd91VN4djpZkiMVwK6gcyfeH4XE8wZrZaV4=
golang.org/x/mod v0.8.0/go.mod h1:iBbtSCu2XBx23ZKBPSOrRkjjQPZFPuis4dIYUhu/chs=
golang.org/x/net v0.0.0-20190620200207-3b0461eec859/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
golang.org/x/net v0.0.0-20210226172049-e18ecbb05110/go.mod h1:m0MpNAwzfU5UDzcl9v0D8zg8gWTRqZa9RBIspLL5mdg=
-golang.org/x/net v0.0.0-20210916014120-12bc252f5db8/go.mod h1:9nx3DQGgdP8bBQD5qxJ1jj9UTztislL4KSBs9R2vV5Y=
golang.org/x/net v0.0.0-20220722155237-a158d28d115b/go.mod h1:XRhObCWvk6IyKnWLug+ECip1KBveYUHfp+8e9klMJ9c=
golang.org/x/net v0.6.0/go.mod h1:2Tu9+aMcznHK/AK1HMvgo6xiTLG5rD5rZLDS+rp2Bjs=
-golang.org/x/net v0.7.0/go.mod h1:2Tu9+aMcznHK/AK1HMvgo6xiTLG5rD5rZLDS+rp2Bjs=
golang.org/x/net v0.9.0/go.mod h1:d48xBJpPfHeWQsugry2m+kC02ZBRGRgulfHnEXEuWns=
-golang.org/x/net v0.20.0 h1:aCL9BSgETF1k+blQaYUBx9hJ9LOGP3gAVemcZlf1Kpo=
-golang.org/x/net v0.20.0/go.mod h1:z8BVo6PvndSri0LbOE3hAn0apkU+1YvI6E70E9jsnvY=
-golang.org/x/net v0.21.0 h1:AQyQV4dYCvJ7vGmJyKki9+PBdyvhkSd8EIx/qb0AYv4=
-golang.org/x/net v0.21.0/go.mod h1:bIjVDfnllIU7BJ2DNgfnXvpSvtn8VRwhlsaeUTyUS44=
golang.org/x/net v0.22.0 h1:9sGLhx7iRIHEiX0oAJ3MRZMUCElJgy7Br1nO+AMN3Tc=
golang.org/x/net v0.22.0/go.mod h1:JKghWKKOSdJwpW2GEx0Ja7fmaKnMsbu+MWVZTokSYmg=
golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
@@ -161,7 +114,6 @@ golang.org/x/sync v0.0.0-20220722155255-886fb9371eb4/go.mod h1:RxMgew5VJxzue5/jJ
golang.org/x/sync v0.1.0/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
golang.org/x/sys v0.0.0-20201119102817-f84b799fce68/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
-golang.org/x/sys v0.0.0-20210423082822-04245dca01da/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20210615035016-665e8c7367d1/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.0.0-20220520151302-bc2c85ada10a/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.0.0-20220715151400-c0bba94af5f8/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
@@ -171,8 +123,6 @@ golang.org/x/sys v0.5.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.6.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.7.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.12.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
-golang.org/x/sys v0.17.0 h1:25cE3gD+tdBA7lp7QfhuV+rJiE9YXTcS3VG1SqssI/Y=
-golang.org/x/sys v0.17.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
golang.org/x/sys v0.18.0 h1:DBdB3niSjOA/O0blCZBqDefyWNYveAYMNF1Wum0DYQ4=
golang.org/x/sys v0.18.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo=
@@ -181,7 +131,6 @@ golang.org/x/term v0.5.0/go.mod h1:jMB1sMXY+tzblOD4FWmEbocvup2/aLOaQEp7JmGp78k=
golang.org/x/term v0.7.0/go.mod h1:P32HKFT3hSsZrRxla30E9HqToFYAQPCMs/zFMBUFqPY=
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
-golang.org/x/text v0.3.6/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
golang.org/x/text v0.3.7/go.mod h1:u+2+/6zg+i71rQMx5EYifcz6MCKuco9NR6JIITiCfzQ=
golang.org/x/text v0.7.0/go.mod h1:mrYo+phRRbMaCq/xk9113O4dZlRixOauAjOtrjsXDZ8=
golang.org/x/text v0.9.0/go.mod h1:e1OnstbJyHTd6l/uOt8jFFHp6TRDWZR/bV3emEE/zU8=
@@ -192,15 +141,12 @@ golang.org/x/tools v0.6.0/go.mod h1:Xwgl3UAJ/d3gWutnCtw505GrjyAbvKui8lOU390QaIU=
golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
golang.org/x/xerrors v0.0.0-20220609144429-65e65417b02f h1:uF6paiQQebLeSXkrTqHqz0MXhXXS1KgF41eUdBNvxK0=
golang.org/x/xerrors v0.0.0-20220609144429-65e65417b02f/go.mod h1:K8+ghG5WaK9qNqU5K3HdILfMLy1f3aNYFI/wnl100a8=
-google.golang.org/protobuf v1.32.0 h1:pPC6BG5ex8PDFnkbrGU3EixyhKcQ2aDuBS36lqK/C7I=
-google.golang.org/protobuf v1.32.0/go.mod h1:c6P6GXX6sHbq/GpV6MGZEdwhWPcYBgnhAHhKbcUYpos=
google.golang.org/protobuf v1.33.0 h1:uNO2rsAINq/JlFpSdYEKIZ0uKD/R9cpdv0T+yoGwGmI=
google.golang.org/protobuf v1.33.0/go.mod h1:c6P6GXX6sHbq/GpV6MGZEdwhWPcYBgnhAHhKbcUYpos=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127 h1:qIbj1fsPNlZgppZ+VLlY7N33q108Sa+fhmuc+sWQYwY=
gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
-gopkg.in/yaml.v2 v2.2.7/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
diff --git a/src/internal/rest/send.go b/src/internal/rest/send.go
index a27cfbeb..e0eb827f 100644
--- a/src/internal/rest/send.go
+++ b/src/internal/rest/send.go
@@ -21,6 +21,7 @@ func InitRestSend(app *fiber.App, service domainSend.ISendService) Send {
app.Post("/send/link", rest.SendLink)
app.Post("/send/location", rest.SendLocation)
app.Post("/send/audio", rest.SendAudio)
+ app.Post("/send/poll", rest.SendPoll)
return rest
}
@@ -185,3 +186,21 @@ func (controller *Send) SendAudio(c *fiber.Ctx) error {
Results: response,
})
}
+
+func (controller *Send) SendPoll(c *fiber.Ctx) error {
+ var request domainSend.PollRequest
+ err := c.BodyParser(&request)
+ utils.PanicIfNeeded(err)
+
+ whatsapp.SanitizePhone(&request.Phone)
+
+ response, err := controller.Service.SendPoll(c.UserContext(), request)
+ utils.PanicIfNeeded(err)
+
+ return c.JSON(utils.ResponseData{
+ Status: 200,
+ Code: "SUCCESS",
+ Message: response.Status,
+ Results: response,
+ })
+}
diff --git a/src/main.go b/src/main.go
index 389affa3..80deb90a 100644
--- a/src/main.go
+++ b/src/main.go
@@ -1,7 +1,16 @@
package main
-import "github.com/aldinokemal/go-whatsapp-web-multidevice/cmd"
+import (
+ "embed"
+ "github.com/aldinokemal/go-whatsapp-web-multidevice/cmd"
+)
+
+//go:embed views/index.html
+var embedViews embed.FS
+
+//go:embed views
+var embedViewsComponent embed.FS
func main() {
- cmd.Execute()
+ cmd.Execute(embedViews, embedViewsComponent)
}
diff --git a/src/services/send.go b/src/services/send.go
index 57b04c73..6ad40065 100644
--- a/src/services/send.go
+++ b/src/services/send.go
@@ -457,3 +457,23 @@ func (service serviceSend) SendAudio(ctx context.Context, request domainSend.Aud
response.Status = fmt.Sprintf("Send audio success %s (server timestamp: %s)", request.Phone, ts.Timestamp.String())
return response, nil
}
+
+func (service serviceSend) SendPoll(ctx context.Context, request domainSend.PollRequest) (response domainSend.GenericResponse, err error) {
+ err = validations.ValidateSendPoll(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(ctx, dataWaRecipient, service.WaCli.BuildPollCreation(request.Question, request.Options, request.MaxAnswer))
+ 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())
+ return response, nil
+}
diff --git a/src/validations/send_validation.go b/src/validations/send_validation.go
index 344589c6..137704c5 100644
--- a/src/validations/send_validation.go
+++ b/src/validations/send_validation.go
@@ -175,3 +175,33 @@ func ValidateSendAudio(ctx context.Context, request domainSend.AudioRequest) err
return nil
}
+
+func ValidateSendPoll(ctx context.Context, request domainSend.PollRequest) error {
+ err := validation.ValidateStructWithContext(ctx, &request,
+ validation.Field(&request.Phone, validation.Required),
+ validation.Field(&request.Question, validation.Required),
+
+ validation.Field(&request.Options, validation.Required),
+ validation.Field(&request.Options, validation.Each(validation.Required)),
+
+ validation.Field(&request.MaxAnswer, validation.Required),
+ validation.Field(&request.MaxAnswer, validation.Min(1)),
+ validation.Field(&request.MaxAnswer, validation.Max(len(request.Options))),
+ )
+
+ if err != nil {
+ return pkgError.ValidationError(err.Error())
+ }
+
+ // validate options should be unique each other
+ uniqueOptions := make(map[string]bool)
+ for _, option := range request.Options {
+ if _, ok := uniqueOptions[option]; ok {
+ return pkgError.ValidationError("options should be unique")
+ }
+ uniqueOptions[option] = true
+ }
+
+ return nil
+
+}
diff --git a/src/views/components/SendPoll.js b/src/views/components/SendPoll.js
new file mode 100644
index 00000000..d3fd6837
--- /dev/null
+++ b/src/views/components/SendPoll.js
@@ -0,0 +1,144 @@
+// export Vue Component
+export default {
+ name: 'SendPoll',
+ data() {
+ return {
+ poll_phone: '',
+ poll_type: 'user',
+ poll_loading: false,
+ poll_question: '',
+ poll_options: ['', ''],
+ poll_max_vote: 1,
+ }
+ },
+ computed: {
+ poll_phone_id() {
+ return this.poll_type === 'user' ? `${this.poll_phone}@${window.TYPEUSER}` : `${this.poll_phone}@${window.TYPEGROUP}`
+ }
+ },
+ methods: {
+ sendPollModal() {
+ $('#modalSendPoll').modal({
+ onApprove: function () {
+ return false;
+ }
+ }).modal('show');
+ },
+ async sendPollProcess() {
+ try {
+ let response = await this.sendPollApi()
+ window.showSuccessInfo(response)
+ $('#modalSendPoll').modal('hide');
+ } catch (err) {
+ window.showErrorInfo(err)
+ }
+ },
+ sendPollApi() {
+ return new Promise(async (resolve, reject) => {
+ try {
+ this.poll_loading = true;
+ const payload = {
+ phone: this.poll_phone_id,
+ question: this.poll_question,
+ max_answer: this.poll_max_vote,
+ options: this.poll_options
+ }
+ let response = await window.http.post(`/send/poll`, payload)
+ this.sendPollReset();
+ resolve(response.data.message)
+ } catch (error) {
+ if (error.response) {
+ reject(error.response.data.message)
+ } else {
+ reject(error.message)
+ }
+ } finally {
+ this.poll_loading = false;
+ }
+ })
+ },
+ sendPollReset() {
+ this.poll_phone = '';
+ this.poll_type = 'user';
+ this.poll_question = '';
+ this.poll_options = ['', ''];
+ this.poll_max_vote = 1;
+ },
+ addPollOption() {
+ this.poll_options.push('')
+ },
+ deletePollOption(index) {
+ this.poll_options.splice(index, 1)
+ }
+ },
+ template: `
+ <div class="blue card" @click="sendPollModal()" style="cursor: pointer">
+ <div class="content">
+ <a class="ui blue right ribbon label">Send</a>
+ <div class="header">Send Poll</div>
+ <div class="description">
+ Send a poll/vote with multiple options
+ </div>
+ </div>
+ </div>
+
+ <!-- Modal SendPoll -->
+ <div class="ui small modal" id="modalSendPoll">
+ <i class="close icon"></i>
+ <div class="header">
+ Send Poll
+ </div>
+ <div class="content">
+ <form class="ui form">
+ <div class="field">
+ <label>Type</label>
+ <select name="poll_type" v-model="poll_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="poll_phone" type="text" placeholder="6289..."
+ aria-label="phone">
+ <input :value="poll_phone_id" disabled aria-label="whatsapp_id">
+ </div>
+ <div class="field">
+ <label>Question</label>
+ <input v-model="poll_question" type="text" placeholder="Please enter question"
+ aria-label="poll question">
+ </div>
+ <div class="field">
+ <label>Options</label>
+ <div style="display: flex; flex-direction: column; gap: 5px">
+ <div class="ui action input" :key="index" v-for="(option, index) in poll_options">
+ <input type="text" placeholder="Option..." v-model="poll_options[index]"
+ aria-label="poll option">
+ <button class="ui button" @click="deletePollOption(index)" type="button">
+ <i class="minus circle icon"></i>
+ </button>
+ </div>
+ <div class="field">
+ <button class="mini ui primary button" @click="addPollOption" type="button">
+ <i class="plus icon"></i> Option
+ </button>
+ </div>
+ </div>
+ </div>
+ <div class="field">
+ <label>Max Vote</label>
+ <input v-model="poll_max_vote" type="number" placeholder="Max Vote"
+ aria-label="poll max votes" min="0">
+ </div>
+ </form>
+ </div>
+ <div class="actions">
+ <div class="ui approve positive right labeled icon button" :class="{'loading': this.poll_loading}"
+ @click="sendPollProcess" type="button">
+ Send
+ <i class="send icon"></i>
+ </div>
+ </div>
+ </div>
+`
+}
\ No newline at end of file
diff --git a/src/views/index.html b/src/views/index.html
index d544f967..8bf94f05 100644
--- a/src/views/index.html
+++ b/src/views/index.html
@@ -78,7 +78,7 @@
<a class="ui blue right ribbon label">Send</a>
<div class="header">Send Message</div>
<div class="description">
- Send any message to any whatsapp number
+ Send any message to user or group
</div>
</div>
</div>
@@ -120,7 +120,7 @@
<a class="ui blue right ribbon label">Send</a>
<div class="header">Send Contact</div>
<div class="description">
- Send contact to any whatsapp number
+ Send contact to user or group
</div>
</div>
</div>
@@ -129,7 +129,7 @@
<a class="ui blue right ribbon label">Send</a>
<div class="header">Send Location</div>
<div class="description">
- Send location to any whatsapp number
+ Send location to user or group
</div>
</div>
</div>
@@ -138,11 +138,12 @@
<a class="ui blue right ribbon label">Send</a>
<div class="header">Send Audio</div>
<div class="description">
- Send audio to any whatsapp number
+ Send audio to user or group
</div>
</div>
</div>
+ <send-poll></send-poll>
</div>
<div class="ui horizontal divider">
@@ -259,7 +260,8 @@
</div>
<div class="field">
<label>Reply Message ID</label>
- <input v-model="message_reply_message_id" type="text" placeholder="Optional: 57D29F74B7FC62F57D8AC2C840279B5B/3EB0288F008D32FCD0A424"
+ <input v-model="message_reply_message_id" type="text"
+ placeholder="Optional: 57D29F74B7FC62F57D8AC2C840279B5B/3EB0288F008D32FCD0A424"
aria-label="reply_message_id">
</div>
<div class="field">
@@ -788,14 +790,38 @@
</div>
</div>
</div>
-
<script>
- const http = axios.create({
+ window.TYPEGROUP = "g.us";
+ window.TYPEUSER = "s.whatsapp.net";
+ window.showErrorInfo = (message) => {
+ $('body').toast({
+ position: 'bottom right',
+ title: 'Error',
+ message: message,
+ showProgress: 'bottom',
+ classProgress: 'red'
+ });
+ }
+ window.showSuccessInfo = (message) => {
+ $('body').toast({
+ position: 'bottom right',
+ title: 'Success',
+ message: message,
+ showProgress: 'bottom',
+ classProgress: 'green'
+ });
+ }
+
+ window.http = axios.create({
baseURL: {{ .AppHost }}
});
{{ if isEnableBasicAuth .BasicAuthToken }}
- http.defaults.headers.common['Authorization'] = {{ .BasicAuthToken }};
+ window.http.defaults.headers.common['Authorization'] = {{ .BasicAuthToken }};
{{ end }}
+</script>
+<script type="module">
+ import SendPoll from "./components/SendPoll.js";
+
const showErrorInfo = (message) => {
$('body').toast({
position: 'bottom right',
@@ -1713,6 +1739,9 @@
}
Vue.createApp({
+ components: {
+ SendPoll
+ },
delimiters: ['[[', ']]'],
data() {
return {