28 Commits

Author SHA1 Message Date
eneller
dede950958 wip: try to pin message 2026-01-30 21:19:09 +01:00
eneller
33f4c84d03 add cli pin flag 2026-01-30 21:18:49 +01:00
eneller
9ca17dfe81 chore: update deps 2026-01-21 12:42:42 +01:00
eneller
08be665bdf build: add test to Makefile 2026-01-21 12:42:01 +01:00
eneller
88dd268cf3 chore: update deps 2026-01-12 13:36:46 +01:00
eneller
70ac0e93ea chore: update deps 2026-01-07 21:17:56 +01:00
eneller
3e79d8a3a1 chore: update deps 2025-12-12 19:38:52 +01:00
eneller
b31884d8ab build: adjust Makefile to src/ 2025-12-12 19:26:59 +01:00
eneller
6f44b9ea7d chore: update deps 2025-11-29 17:16:06 +01:00
eneller
8e4443852f chore: src/ structure 2025-11-22 00:55:24 +01:00
eneller
381299cd2e chore: update deps 2025-11-21 17:52:23 +01:00
eneller
846e8c0184 refactor: logging 2025-11-21 17:49:28 +01:00
eneller
a979b93121 refactor: remove unnecessary output 2025-11-21 14:36:49 +01:00
eneller
f6eddad980 chore: update deps 2025-11-16 12:15:16 +01:00
eneller
765efd0efb chore: update deps 2025-11-16 12:07:55 +01:00
eneller
64a154e605 chore: update deps 2025-11-09 22:56:18 +01:00
eneller
f4d3dac6ab chore: update deps 2025-10-26 11:47:47 +01:00
eneller
6522fea34c fix: error on empty input 2025-10-26 10:43:01 +01:00
eneller
a54c005674 refactor: cli for batch mode 2025-10-25 22:36:55 +02:00
eneller
2fdb09d155 chore: update deps 2025-10-23 21:47:50 +02:00
eneller
f8638fde6b build: ci 2025-10-23 00:08:28 +02:00
eneller
45a774c19f chore: update deps 2025-10-22 14:18:04 +02:00
eneller
ea904ffd9e build: Makefile update target 2025-10-22 10:55:21 +02:00
eneller
ee3f788337 chore: update deps 2025-10-22 10:53:15 +02:00
eneller
b701e59331 chore: update deps 2025-10-22 10:48:11 +02:00
eneller
03358b2155 chore: update deps 2025-10-10 11:14:00 +02:00
eneller
e2526fe2ab chore: update deps 2025-07-10 08:16:25 +02:00
eneller
1ee8348c47 chore: update deps 2025-06-18 16:52:48 +02:00
8 changed files with 321 additions and 217 deletions

View File

@@ -0,0 +1,10 @@
name: build
on:
push:
branches:
- main
jobs:
build_x86:
runs-on: [amd64]
steps:
- run: make

View File

@@ -1,12 +1,34 @@
CC=go build CC=go build
NAME=whatsup-poll NAME=schneller-whatsapp
SRCDIR=./src
default: build default: build
build: build:
$(CC) $(CC) -o $(NAME) $(SRCDIR)
run:
go run $(SRCDIR)
arm: arm:
env CGO_ENABLED=1 GOOS=linux GOARCH=arm64 $(CC) -o $(NAME)-arm64 env CGO_ENABLED=1 GOOS=linux GOARCH=arm64 $(CC) -o $(NAME)-arm64
update:
go get -u go.mau.fi/whatsmeow
go mod tidy
update-all:
go get -u
go mod tidy
deploy:
rsync $(NAME) jojo:$(NAME)
test-remote:
ssh jojo 'cd $(NAME) && ./test.sh'
upgrade: update build deploy
cicd: upgrade test-remote
clean: clean:
git clean -fX git clean -fX

View File

@@ -4,10 +4,11 @@ CLI Whatsapp Messages (and Polls) using go:
- [urfave/cli](https://github.com/urfave/cli) for the command line - [urfave/cli](https://github.com/urfave/cli) for the command line
# Usage # Usage
Can be easily scheduled using `crontab` because of its non-interactive operation Can be easily scheduled using `crontab` because of its non-interactive operation.
Avoid quick consecutive logins by using the stdin option to send multiple messages in one session.
``` ```
NAME: NAME:
schneller-whatsapp - Run WhatsApp actions from your CLI. User JID has to end with '@s.whatsapp.net', Group ID with '@g.us' schneller-whatsapp - Run WhatsApp actions from your CLI. User JID has to end with '@s.whatsapp.net', Group ID with '@g.us'. Defaults to listening on stdin for batch processing.
USAGE: USAGE:
schneller-whatsapp [global options] [command [command options]] schneller-whatsapp [global options] [command [command options]]

31
go.mod
View File

@@ -3,27 +3,32 @@ module github.com/eneller/schneller-whatsapp
go 1.24.2 go 1.24.2
require ( require (
github.com/mattn/go-sqlite3 v1.14.28 github.com/google/shlex v0.0.0-20191202100458-e7afc7fbc510
github.com/mattn/go-sqlite3 v1.14.33
github.com/mdp/qrterminal/v3 v3.2.1 github.com/mdp/qrterminal/v3 v3.2.1
github.com/urfave/cli/v3 v3.2.0 github.com/urfave/cli/v3 v3.6.0
go.mau.fi/whatsmeow v0.0.0-20250424100714-086604102f64 go.mau.fi/whatsmeow v0.0.0-20260120190750-84f938d06436
google.golang.org/protobuf v1.36.6 google.golang.org/protobuf v1.36.11
) )
require ( require (
filippo.io/edwards25519 v1.1.0 // indirect filippo.io/edwards25519 v1.1.0 // indirect
github.com/beeper/argo-go v1.1.2 // indirect
github.com/coder/websocket v1.8.14 // indirect
github.com/elliotchance/orderedmap/v3 v3.1.0 // indirect
github.com/google/uuid v1.6.0 // indirect github.com/google/uuid v1.6.0 // indirect
github.com/gorilla/websocket v1.5.3 // indirect
github.com/mattn/go-colorable v0.1.14 // indirect github.com/mattn/go-colorable v0.1.14 // indirect
github.com/mattn/go-isatty v0.0.20 // indirect github.com/mattn/go-isatty v0.0.20 // indirect
github.com/petermattis/goid v0.0.0-20250319124200-ccd6737f222a // indirect github.com/petermattis/goid v0.0.0-20260113132338-7c7de50cc741 // indirect
github.com/rs/zerolog v1.34.0 // indirect github.com/rs/zerolog v1.34.0 // indirect
go.mau.fi/libsignal v0.1.2 // indirect github.com/vektah/gqlparser/v2 v2.5.31 // indirect
go.mau.fi/util v0.8.6 // indirect go.mau.fi/libsignal v0.2.1 // indirect
golang.org/x/crypto v0.37.0 // indirect go.mau.fi/util v0.9.5 // indirect
golang.org/x/exp v0.0.0-20250408133849-7e4ce0ab07d0 // indirect golang.org/x/crypto v0.47.0 // indirect
golang.org/x/net v0.39.0 // indirect golang.org/x/exp v0.0.0-20260112195511-716be5621a96 // indirect
golang.org/x/sys v0.32.0 // indirect golang.org/x/net v0.49.0 // indirect
golang.org/x/term v0.31.0 // indirect golang.org/x/sys v0.40.0 // indirect
golang.org/x/term v0.39.0 // indirect
golang.org/x/text v0.33.0 // indirect
rsc.io/qr v0.2.0 // indirect rsc.io/qr v0.2.0 // indirect
) )

76
go.sum
View File

@@ -2,16 +2,26 @@ filippo.io/edwards25519 v1.1.0 h1:FNf4tywRC1HmFuKW5xopWpigGjJKiJSV0Cqo0cJWDaA=
filippo.io/edwards25519 v1.1.0/go.mod h1:BxyFTGdWcka3PhytdK4V28tE5sGfRvvvRV7EaN4VDT4= filippo.io/edwards25519 v1.1.0/go.mod h1:BxyFTGdWcka3PhytdK4V28tE5sGfRvvvRV7EaN4VDT4=
github.com/DATA-DOG/go-sqlmock v1.5.2 h1:OcvFkGmslmlZibjAjaHm3L//6LiuBgolP7OputlJIzU= github.com/DATA-DOG/go-sqlmock v1.5.2 h1:OcvFkGmslmlZibjAjaHm3L//6LiuBgolP7OputlJIzU=
github.com/DATA-DOG/go-sqlmock v1.5.2/go.mod h1:88MAG/4G7SMwSE3CeA0ZKzrT5CiOU3OJ+JlNzwDqpNU= github.com/DATA-DOG/go-sqlmock v1.5.2/go.mod h1:88MAG/4G7SMwSE3CeA0ZKzrT5CiOU3OJ+JlNzwDqpNU=
github.com/agnivade/levenshtein v1.2.1 h1:EHBY3UOn1gwdy/VbFwgo4cxecRznFk7fKWN1KOX7eoM=
github.com/agnivade/levenshtein v1.2.1/go.mod h1:QVVI16kDrtSuwcpd0p1+xMC6Z/VfhtCyDIjcwga4/DU=
github.com/andreyvit/diff v0.0.0-20170406064948-c7f18ee00883 h1:bvNMNQO63//z+xNgfBlViaCIJKLlCJ6/fmUseuG0wVQ=
github.com/andreyvit/diff v0.0.0-20170406064948-c7f18ee00883/go.mod h1:rCTlJbsFo29Kk6CurOXKm700vrz8f0KW0JNfpkRJY/8=
github.com/beeper/argo-go v1.1.2 h1:UQI2G8F+NLfGTOmTUI0254pGKx/HUU/etbUGTJv91Fs=
github.com/beeper/argo-go v1.1.2/go.mod h1:M+LJAnyowKVQ6Rdj6XYGEn+qcVFkb3R/MUpqkGR0hM4=
github.com/coder/websocket v1.8.14 h1:9L0p0iKiNOibykf283eHkKUHHrpG7f65OE3BhhO7v9g=
github.com/coder/websocket v1.8.14/go.mod h1:NX3SzP+inril6yawo5CQXx8+fk145lPDC6pumgx0mVg=
github.com/coreos/go-systemd/v22 v22.5.0/go.mod h1:Y58oyj3AT4RCenI/lSvhwexgC+NSVTIJ3seZv2GcEnc= github.com/coreos/go-systemd/v22 v22.5.0/go.mod h1:Y58oyj3AT4RCenI/lSvhwexgC+NSVTIJ3seZv2GcEnc=
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c= 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/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/elliotchance/orderedmap/v3 v3.1.0 h1:j4DJ5ObEmMBt/lcwIecKcoRxIQUEnw0L804lXYDt/pg=
github.com/elliotchance/orderedmap/v3 v3.1.0/go.mod h1:G+Hc2RwaZvJMcS4JpGCOyViCnGeKf0bTYCGTO4uhjSo=
github.com/godbus/dbus/v5 v5.0.4/go.mod h1:xhWf0FNVPg57R7Z0UbKHbJfkEywrmjJnf7w5xrFpKfA= github.com/godbus/dbus/v5 v5.0.4/go.mod h1:xhWf0FNVPg57R7Z0UbKHbJfkEywrmjJnf7w5xrFpKfA=
github.com/google/go-cmp v0.6.0 h1:ofyhxvXcZhMsU5ulbFiLKl/XBFqE1GSq7atu8tAmTRI= github.com/google/go-cmp v0.7.0 h1:wk8382ETsv4JYUZwIsn6YpYiWiBsYLSJiTsyBybVuN8=
github.com/google/go-cmp v0.6.0/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY= github.com/google/go-cmp v0.7.0/go.mod h1:pXiqmnSA92OHEEa9HXL2W4E7lf9JzCmGVUdgjX3N/iU=
github.com/google/shlex v0.0.0-20191202100458-e7afc7fbc510 h1:El6M4kTTCOh6aBiKaUGG7oYTSPP8MxqL4YI3kZKwcP4=
github.com/google/shlex v0.0.0-20191202100458-e7afc7fbc510/go.mod h1:pupxD2MaaD3pAXIBCelhxNneeOaAeabZDe5s4K6zSpQ=
github.com/google/uuid v1.6.0 h1:NIvaJDMOsjHA8n1jAhLSgzrAzy1Hgr+hNrb57e+94F0= github.com/google/uuid v1.6.0 h1:NIvaJDMOsjHA8n1jAhLSgzrAzy1Hgr+hNrb57e+94F0=
github.com/google/uuid v1.6.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo= github.com/google/uuid v1.6.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=
github.com/gorilla/websocket v1.5.3 h1:saDtZ6Pbx/0u+bgYQ3q96pZgCzfhKXGPqt7kZ72aNNg=
github.com/gorilla/websocket v1.5.3/go.mod h1:YR8l580nyteQvAITg2hZ9XVh4b55+EU/adAjf1fMHhE=
github.com/mattn/go-colorable v0.1.13/go.mod h1:7S9/ev0klgBDR4GtXTXX8a3vIGJpMovkB8vQcUbaXHg= github.com/mattn/go-colorable v0.1.13/go.mod h1:7S9/ev0klgBDR4GtXTXX8a3vIGJpMovkB8vQcUbaXHg=
github.com/mattn/go-colorable v0.1.14 h1:9A9LHSqF/7dyVVX6g0U9cwm9pG3kP9gSzcuIPHPsaIE= github.com/mattn/go-colorable v0.1.14 h1:9A9LHSqF/7dyVVX6g0U9cwm9pG3kP9gSzcuIPHPsaIE=
github.com/mattn/go-colorable v0.1.14/go.mod h1:6LmQG8QLFO4G5z1gPvYEzlUgJ2wF+stgPZH1UqBm1s8= github.com/mattn/go-colorable v0.1.14/go.mod h1:6LmQG8QLFO4G5z1gPvYEzlUgJ2wF+stgPZH1UqBm1s8=
@@ -19,43 +29,49 @@ github.com/mattn/go-isatty v0.0.16/go.mod h1:kYGgaQfpe5nmfYZH+SKPsOc2e4SrIfOl2e/
github.com/mattn/go-isatty v0.0.19/go.mod h1:W+V8PltTTMOvKvAeJH7IuucS94S2C6jfK/D7dTCTo3Y= github.com/mattn/go-isatty v0.0.19/go.mod h1:W+V8PltTTMOvKvAeJH7IuucS94S2C6jfK/D7dTCTo3Y=
github.com/mattn/go-isatty v0.0.20 h1:xfD0iDuEKnDkl03q4limB+vH+GxLEtL/jb4xVJSWWEY= github.com/mattn/go-isatty v0.0.20 h1:xfD0iDuEKnDkl03q4limB+vH+GxLEtL/jb4xVJSWWEY=
github.com/mattn/go-isatty v0.0.20/go.mod h1:W+V8PltTTMOvKvAeJH7IuucS94S2C6jfK/D7dTCTo3Y= github.com/mattn/go-isatty v0.0.20/go.mod h1:W+V8PltTTMOvKvAeJH7IuucS94S2C6jfK/D7dTCTo3Y=
github.com/mattn/go-sqlite3 v1.14.28 h1:ThEiQrnbtumT+QMknw63Befp/ce/nUPgBPMlRFEum7A= github.com/mattn/go-sqlite3 v1.14.33 h1:A5blZ5ulQo2AtayQ9/limgHEkFreKj1Dv226a1K73s0=
github.com/mattn/go-sqlite3 v1.14.28/go.mod h1:Uh1q+B4BYcTPb+yiD3kU8Ct7aC0hY9fxUwlHK0RXw+Y= github.com/mattn/go-sqlite3 v1.14.33/go.mod h1:Uh1q+B4BYcTPb+yiD3kU8Ct7aC0hY9fxUwlHK0RXw+Y=
github.com/mdp/qrterminal/v3 v3.2.1 h1:6+yQjiiOsSuXT5n9/m60E54vdgFsw0zhADHhHLrFet4= github.com/mdp/qrterminal/v3 v3.2.1 h1:6+yQjiiOsSuXT5n9/m60E54vdgFsw0zhADHhHLrFet4=
github.com/mdp/qrterminal/v3 v3.2.1/go.mod h1:jOTmXvnBsMy5xqLniO0R++Jmjs2sTm9dFSuQ5kpz/SU= github.com/mdp/qrterminal/v3 v3.2.1/go.mod h1:jOTmXvnBsMy5xqLniO0R++Jmjs2sTm9dFSuQ5kpz/SU=
github.com/petermattis/goid v0.0.0-20250319124200-ccd6737f222a h1:S+AGcmAESQ0pXCUNnRH7V+bOUIgkSX5qVt2cNKCrm0Q= github.com/petermattis/goid v0.0.0-20260113132338-7c7de50cc741 h1:KPpdlQLZcHfTMQRi6bFQ7ogNO0ltFT4PmtwTLW4W+14=
github.com/petermattis/goid v0.0.0-20250319124200-ccd6737f222a/go.mod h1:pxMtw7cyUw6B2bRH0ZBANSPg+AoSud1I1iyJHI69jH4= github.com/petermattis/goid v0.0.0-20260113132338-7c7de50cc741/go.mod h1:pxMtw7cyUw6B2bRH0ZBANSPg+AoSud1I1iyJHI69jH4=
github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0= github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= 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/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
github.com/rs/xid v1.6.0/go.mod h1:7XoLgs4eV+QndskICGsho+ADou8ySMSjJKDIan90Nz0= github.com/rs/xid v1.6.0/go.mod h1:7XoLgs4eV+QndskICGsho+ADou8ySMSjJKDIan90Nz0=
github.com/rs/zerolog v1.34.0 h1:k43nTLIwcTVQAncfCw4KZ2VY6ukYoZaBPNOE8txlOeY= github.com/rs/zerolog v1.34.0 h1:k43nTLIwcTVQAncfCw4KZ2VY6ukYoZaBPNOE8txlOeY=
github.com/rs/zerolog v1.34.0/go.mod h1:bJsvje4Z08ROH4Nhs5iH600c3IkWhwp44iRc54W6wYQ= github.com/rs/zerolog v1.34.0/go.mod h1:bJsvje4Z08ROH4Nhs5iH600c3IkWhwp44iRc54W6wYQ=
github.com/stretchr/testify v1.10.0 h1:Xv5erBjTwe/5IxqUQTdXv5kgmIvbHo3QQyRwhJsOfJA= github.com/sergi/go-diff v1.3.1 h1:xkr+Oxo4BOQKmkn/B9eMK0g5Kg/983T9DqqPHwYqD+8=
github.com/stretchr/testify v1.10.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY= github.com/sergi/go-diff v1.3.1/go.mod h1:aMJSSKb2lpPvRNec0+w3fl7LP9IOFzdc9Pa4NFbPK1I=
github.com/urfave/cli/v3 v3.2.0 h1:m8WIXY0U9LCuUl5r+0fqLWDhNYWt6qvlW+GcF4EoXf8= github.com/stretchr/testify v1.11.1 h1:7s2iGBzp5EwR7/aIZr8ao5+dra3wiQyKjjFuvgVKu7U=
github.com/urfave/cli/v3 v3.2.0/go.mod h1:FJSKtM/9AiiTOJL4fJ6TbMUkxBXn7GO9guZqoZtpYpo= github.com/stretchr/testify v1.11.1/go.mod h1:wZwfW3scLgRK+23gO65QZefKpKQRnfz6sD981Nm4B6U=
go.mau.fi/libsignal v0.1.2 h1:Vs16DXWxSKyzVtI+EEXLCSy5pVWzzCzp/2eqFGvLyP0= github.com/urfave/cli/v3 v3.6.0 h1:oIdArVjkdIXHWg3iqxgmqwQGC8NM0JtdgwQAj2sRwFo=
go.mau.fi/libsignal v0.1.2/go.mod h1:JpnLSSJptn/s1sv7I56uEMywvz8x4YzxeF5OzdPb6PE= github.com/urfave/cli/v3 v3.6.0/go.mod h1:ysVLtOEmg2tOy6PknnYVhDoouyC/6N42TMeoMzskhso=
go.mau.fi/util v0.8.6 h1:AEK13rfgtiZJL2YsNK+W4ihhYCuukcRom8WPP/w/L54= github.com/vektah/gqlparser/v2 v2.5.31 h1:YhWGA1mfTjID7qJhd1+Vxhpk5HTgydrGU9IgkWBTJ7k=
go.mau.fi/util v0.8.6/go.mod h1:uNB3UTXFbkpp7xL1M/WvQks90B/L4gvbLpbS0603KOE= github.com/vektah/gqlparser/v2 v2.5.31/go.mod h1:c1I28gSOVNzlfc4WuDlqU7voQnsqI6OG2amkBAFmgts=
go.mau.fi/whatsmeow v0.0.0-20250424100714-086604102f64 h1:4w1P3c8HACMpsFeGvOZxG20i+TWbBK0a8ExwQvI0nYs= go.mau.fi/libsignal v0.2.1 h1:vRZG4EzTn70XY6Oh/pVKrQGuMHBkAWlGRC22/85m9L0=
go.mau.fi/whatsmeow v0.0.0-20250424100714-086604102f64/go.mod h1:NlPtoLdpX3RnltqCTCZQ6kIUfprqLirtSK1gHvwoNx0= go.mau.fi/libsignal v0.2.1/go.mod h1:iVvjrHyfQqWajOUaMEsIfo3IqgVMrhWcPiiEzk7NgoU=
golang.org/x/crypto v0.37.0 h1:kJNSjF/Xp7kU0iB2Z+9viTPMW4EqqsrywMXLJOOsXSE= go.mau.fi/util v0.9.5 h1:7AoWPCIZJGv4jvtFEuCe3GhAbI7uF9ckIooaXvwlIR4=
golang.org/x/crypto v0.37.0/go.mod h1:vg+k43peMZ0pUMhYmVAWysMK35e6ioLh3wB8ZCAfbVc= go.mau.fi/util v0.9.5/go.mod h1:g1uvZ03VQhtTt2BgaRGVytS/Zj67NV0YNIECch0sQCQ=
golang.org/x/exp v0.0.0-20250408133849-7e4ce0ab07d0 h1:R84qjqJb5nVJMxqWYb3np9L5ZsaDtB+a39EqjV0JSUM= go.mau.fi/whatsmeow v0.0.0-20260120190750-84f938d06436 h1:UgyN2x+3ly8IsUxfxXzlKNVchfY7+wYtT+yDCMtYPVQ=
golang.org/x/exp v0.0.0-20250408133849-7e4ce0ab07d0/go.mod h1:S9Xr4PYopiDyqSyp5NjCrhFrqg6A5zA2E/iPHPhqnS8= go.mau.fi/whatsmeow v0.0.0-20260120190750-84f938d06436/go.mod h1:jDLOQLLiYXcm4vMB6vtPcBLU387sRY+P3vOElxX8srA=
golang.org/x/net v0.39.0 h1:ZCu7HMWDxpXpaiKdhzIfaltL9Lp31x/3fCP11bc6/fY= golang.org/x/crypto v0.47.0 h1:V6e3FRj+n4dbpw86FJ8Fv7XVOql7TEwpHapKoMJ/GO8=
golang.org/x/net v0.39.0/go.mod h1:X7NRbYVEA+ewNkCNyJ513WmMdQ3BineSwVtN2zD/d+E= golang.org/x/crypto v0.47.0/go.mod h1:ff3Y9VzzKbwSSEzWqJsJVBnWmRwRSHt/6Op5n9bQc4A=
golang.org/x/exp v0.0.0-20260112195511-716be5621a96 h1:Z/6YuSHTLOHfNFdb8zVZomZr7cqNgTJvA8+Qz75D8gU=
golang.org/x/exp v0.0.0-20260112195511-716be5621a96/go.mod h1:nzimsREAkjBCIEFtHiYkrJyT+2uy9YZJB7H1k68CXZU=
golang.org/x/net v0.49.0 h1:eeHFmOGUTtaaPSGNmjBKpbng9MulQsJURQUAfUwY++o=
golang.org/x/net v0.49.0/go.mod h1:/ysNB2EvaqvesRkuLAyjI1ycPZlQHM3q01F02UY/MV8=
golang.org/x/sys v0.0.0-20220811171246-fbc7d0a398ab/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.0.0-20220811171246-fbc7d0a398ab/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.6.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.6.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.12.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.12.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.32.0 h1:s77OFDvIQeibCmezSnk/q6iAfkdiQaJi4VzroCFrN20= golang.org/x/sys v0.40.0 h1:DBZZqJ2Rkml6QMQsZywtnjnnGvHza6BTfYFWY9kjEWQ=
golang.org/x/sys v0.32.0/go.mod h1:BJP2sWEmIv4KK5OTEluFJCKSidICx8ciO85XgH3Ak8k= golang.org/x/sys v0.40.0/go.mod h1:OgkHotnGiDImocRcuBABYBEXf8A9a87e/uXjp9XT3ks=
golang.org/x/term v0.31.0 h1:erwDkOK1Msy6offm1mOgvspSkslFnIGsFnxOKoufg3o= golang.org/x/term v0.39.0 h1:RclSuaJf32jOqZz74CkPA9qFuVTX7vhLlpfj/IGWlqY=
golang.org/x/term v0.31.0/go.mod h1:R4BeIy7D95HzImkxGkTW1UQTtP54tio2RyHz7PwK0aw= golang.org/x/term v0.39.0/go.mod h1:yxzUCTP/U+FzoxfdKmLaA0RV1WgE0VY7hXBwKtY/4ww=
google.golang.org/protobuf v1.36.6 h1:z1NpPI8ku2WgiWnf+t9wTPsn6eP1L7ksHUlkfLvd9xY= golang.org/x/text v0.33.0 h1:B3njUFyqtHDUI5jMn1YIr5B0IE2U0qck04r6d4KPAxE=
google.golang.org/protobuf v1.36.6/go.mod h1:jduwjTPXsFjZGTmRluh+L6NjiWu7pchiJ2/5YcXBHnY= golang.org/x/text v0.33.0/go.mod h1:LuMebE6+rBincTi9+xWTY8TztLzKHc/9C1uBCG27+q8=
google.golang.org/protobuf v1.36.11 h1:fV6ZwhNocDyBLK0dj+fg8ektcVegBBuEolpbTQyBNVE=
google.golang.org/protobuf v1.36.11/go.mod h1:HTf+CrKn2C3g5S8VImy6tdcUvCska2kB7j23XfzDpco=
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA= gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
rsc.io/qr v0.2.0 h1:6vBLea5/NRMVTz8V66gipeLycZMl/+UlFmk8DvqQ6WY= rsc.io/qr v0.2.0 h1:6vBLea5/NRMVTz8V66gipeLycZMl/+UlFmk8DvqQ6WY=

170
main.go
View File

@@ -1,170 +0,0 @@
// from https://github.com/tulir/whatsmeow/issues/659
package main
import (
"context"
"fmt"
"log"
"os"
"time"
_ "github.com/mattn/go-sqlite3"
"github.com/mdp/qrterminal/v3"
"github.com/urfave/cli/v3"
"go.mau.fi/whatsmeow"
"go.mau.fi/whatsmeow/proto/waE2E"
"go.mau.fi/whatsmeow/store/sqlstore"
"go.mau.fi/whatsmeow/types"
"go.mau.fi/whatsmeow/types/events"
waLog "go.mau.fi/whatsmeow/util/log"
"google.golang.org/protobuf/proto"
)
func eventHandler(evt interface{}) {
switch v := evt.(type) {
case *events.Message:
fmt.Println("Received a message from !", v.Info.Sender)
fmt.Println("Received a message!", v.Message.GetConversation())
}
}
func initClient() (*whatsmeow.Client, *sqlstore.Container, waLog.Logger) {
dbLog := waLog.Stdout("Database", "DEBUG", true)
// Make sure you add appropriate DB connector imports, e.g. github.com/mattn/go-sqlite3 for SQLite
container, err := sqlstore.New("sqlite3", "file:sqlite3.db?_foreign_keys=on", dbLog)
if err != nil {
panic(err)
}
// If you want multiple sessions, remember their JIDs and use .GetDevice(jid) or .GetAllDevices() instead.
deviceStore, err := container.GetFirstDevice()
if err != nil {
panic(err)
}
clientLog := waLog.Stdout("Client", "DEBUG", true)
client := whatsmeow.NewClient(deviceStore, clientLog)
client.AddEventHandler(eventHandler)
// handle login via QR
if client.Store.ID == nil {
fmt.Println("Client store ID is nil, scanning QR")
// No ID stored, new login
qrChan, _ := client.GetQRChannel(context.Background())
err = client.Connect()
if err != nil {
panic(err)
}
for evt := range qrChan {
if evt.Event == "code" {
// Render the QR code here
// e.g. qrterminal.GenerateHalfBlock(evt.Code, qrterminal.L, os.Stdout)
qrterminal.GenerateHalfBlock(evt.Code, qrterminal.L, os.Stdout)
// or just manually `echo 2@... | qrencode -t ansiutf8` in a terminal
fmt.Println("QR code:", evt.Code)
} else {
fmt.Println("Login event:", evt.Event)
}
}
} else {
// Already logged in, just connect
fmt.Println("Connecting")
err = client.Connect()
if err != nil {
panic(err)
}
}
return client, container, dbLog
}
func main() {
var jidStr, header, text string
var message *waE2E.Message
var client *whatsmeow.Client
var container *sqlstore.Container
//var dbLog waLog.Logger
cmd := &cli.Command{
Usage: "Run WhatsApp actions from your CLI. User JID has to end with '@s.whatsapp.net', Group ID with '@g.us'",
Commands: []*cli.Command{
{
Name: "message",
Usage: "send a message using <JID> <MESSAGE>",
Arguments: []cli.Argument{
&cli.StringArg{Name: "jid", Destination: &jidStr},
&cli.StringArg{Name: "message", Destination: &text},
},
Action: func(ctx context.Context, cmd *cli.Command) error {
// parse JID
var JID types.JID
JID, err := types.ParseJID(jidStr)
if err != nil {
log.Fatal("Failed to parse JID: ", jidStr)
} else {
log.Println("Parsed JID correctly", JID)
}
message = &waE2E.Message{Conversation: proto.String(text)}
return nil
},
},
{
Name: "getgroups",
Usage: "print all available group info",
Action: func(ctx context.Context, cmd *cli.Command) error {
fmt.Println(client.GetJoinedGroups())
return nil
},
},
{
Name: "poll",
Usage: "send a poll using <JID> <HEADER> <OPTIONS>",
Arguments: []cli.Argument{
&cli.StringArg{Name: "jid", Destination: &jidStr}, // use id field of group
&cli.StringArg{Name: "header", Destination: &header},
&cli.StringArgs{Name: "options", Min: 2, Max: -1},
},
Action: func(ctx context.Context, cmd *cli.Command) error {
// parse JID
message = client.BuildPollCreation(header, cmd.StringArgs("options"), 1)
return nil
},
},
},
Before: func(ctx context.Context, cmd *cli.Command) (context.Context, error) {
client, container, _ = initClient()
return nil, nil
},
After: func(ctx context.Context, cmd *cli.Command) error {
if message != nil {
var JID types.JID
JID, err := types.ParseJID(jidStr)
if err != nil {
log.Fatal("Failed to parse JID: ", jidStr)
} else {
log.Println("Parsed JID correctly", JID)
}
_, err = client.SendMessage(context.Background(), JID, message)
// FIXME showing error even when successful
if err != nil {
log.Println("Sent Message successfully")
} else {
fmt.Println("Failed to Send Message", err)
}
time.Sleep(5 * time.Second)
}
// Listen to Ctrl+C (you can also do something else that prevents the program from exiting)
// c := make(chan os.Signal, 1)
// signal.Notify(c, os.Interrupt, syscall.SIGTERM)
// <-c
client.Disconnect()
container.Close()
return nil
},
}
if err := cmd.Run(context.Background(), os.Args); err != nil {
log.Fatal(err)
}
}

2
src/log.go Normal file
View File

@@ -0,0 +1,2 @@
// https://github.com/tulir/whatsmeow/blob/071293c6b9f03f66d2e50bdd659536611d2e10f3/util/log/log.go
package main

218
src/main.go Normal file
View File

@@ -0,0 +1,218 @@
// from https://github.com/tulir/whatsmeow/issues/659
package main
import (
"bufio"
"context"
"fmt"
"log/slog"
"os"
"time"
"github.com/google/shlex"
_ "github.com/mattn/go-sqlite3"
"github.com/mdp/qrterminal/v3"
"github.com/urfave/cli/v3"
"go.mau.fi/whatsmeow"
"go.mau.fi/whatsmeow/proto/waCommon"
"go.mau.fi/whatsmeow/proto/waE2E"
"go.mau.fi/whatsmeow/store/sqlstore"
"go.mau.fi/whatsmeow/types"
waLog "go.mau.fi/whatsmeow/util/log"
"google.golang.org/protobuf/proto"
)
func initClient() (*whatsmeow.Client, *sqlstore.Container, waLog.Logger) {
//TODO use stderr here
dbLog := waLog.Stdout("Database", "DEBUG", true)
// Make sure you add appropriate DB connector imports, e.g. github.com/mattn/go-sqlite3 for SQLite
container, err := sqlstore.New(context.Background(), "sqlite3", "file:sqlite3.db?_foreign_keys=on", dbLog)
if err != nil {
panic(err)
}
// If you want multiple sessions, remember their JIDs and use .GetDevice(jid) or .GetAllDevices() instead.
deviceStore, err := container.GetFirstDevice(context.Background())
if err != nil {
panic(err)
}
client := whatsmeow.NewClient(deviceStore, nil)
// handle login via QR
if client.Store.ID == nil {
slog.Info("Client store ID is nil, scanning QR")
// No ID stored, new login
qrChan, _ := client.GetQRChannel(context.Background())
err = client.Connect()
if err != nil {
panic(err)
}
for evt := range qrChan {
if evt.Event == "code" {
// Render the QR code here
// e.g. qrterminal.GenerateHalfBlock(evt.Code, qrterminal.L, os.Stdout)
qrterminal.GenerateHalfBlock(evt.Code, qrterminal.L, os.Stdout)
// or just manually `echo 2@... | qrencode -t ansiutf8` in a terminal
fmt.Println("QR code: ", evt.Code)
} else {
slog.Debug("Login event", "event", evt.Event)
}
}
} else {
// Already logged in, just connect
slog.Info("Connecting")
err = client.Connect()
if err != nil {
panic(err)
}
}
return client, container, dbLog
}
func sendMessage2(message *waE2E.Message, jidStr string, client *whatsmeow.Client) {
if message != nil {
var JID types.JID
JID, err := types.ParseJID(jidStr)
if err != nil {
slog.Error("Failed to parse", "JID", jidStr)
} else {
slog.Info("Parsed correctly", "JID", JID)
}
m, err := client.SendMessage(context.Background(), JID, message)
key := waCommon.MessageKey{ID: proto.String(m.ID), RemoteJID: proto.String(jidStr), FromMe: proto.Bool(true)}
m, err = client.SendMessage(context.Background(), JID, &waE2E.Message{
MessageContextInfo: &waE2E.MessageContextInfo{
MessageAddOnDurationInSecs: proto.Uint32(604800),
},
PinInChatMessage: &waE2E.PinInChatMessage{
Key: &key,
//Key: client.BuildMessageKey(JID, *client.Store.ID, m.ID),
Type: waE2E.PinInChatMessage_PIN_FOR_ALL.Enum(),
SenderTimestampMS: proto.Int64(time.Now().UnixMilli()),
},
EventMessage: &waE2E.EventMessage{},
})
// FIXME showing error even when successful
if err != nil {
slog.Error("Failed to send message", "error", err)
} else {
slog.Info("Sent Message successfully")
}
}
}
func sendMessage(message *waE2E.Message, jidStr string, client *whatsmeow.Client) {
if message != nil {
var JID types.JID
JID, err := types.ParseJID(jidStr)
if err != nil {
slog.Error("Failed to parse", "JID", jidStr)
} else {
slog.Info("Parsed correctly", "JID", JID)
}
_, err = client.SendMessage(context.Background(), JID, message)
// FIXME showing error even when successful
if err != nil {
slog.Error("Failed to send message", "error", err)
} else {
slog.Info("Sent Message successfully")
}
}
}
func main() {
var jidStr, header, text string
var message *waE2E.Message
var client *whatsmeow.Client
var container *sqlstore.Container
//var dbLog waLog.Logger
cmd := &cli.Command{
Usage: "Run WhatsApp actions from your CLI. User JID has to end with '@s.whatsapp.net', Group ID with '@g.us'." +
"Defaults to listening on stdin for batch processing.",
Flags: []cli.Flag{
&cli.BoolFlag{
Name: "pin",
Aliases: []string{"p"},
Usage: "Pin the message in a group chat",
},
},
Action: func(ctx context.Context, cmd *cli.Command) error {
fmt.Println("No command specified. Reading from stdin. Press Ctrl+D to exit or run with --help to get help.")
scanner := bufio.NewScanner(os.Stdin)
for scanner.Scan() {
if err := scanner.Err(); err != nil {
slog.Error("Error reading", "error", err)
continue
}
args, err := shlex.Split(scanner.Text())
if err != nil || len(args) == 0 {
slog.Error("Error parsing command", "command", err)
continue
}
subcmd := cmd.Command(args[0])
if subcmd != nil {
subcmd.Run(ctx, args)
} else {
slog.Error("Unknown command", "command", args[0])
}
}
fmt.Println("Stdin closed.")
return nil
},
Commands: []*cli.Command{
{
Name: "message",
Usage: "send a message using <JID> <MESSAGE>",
Arguments: []cli.Argument{
&cli.StringArg{Name: "jid", Destination: &jidStr},
&cli.StringArg{Name: "message", Destination: &text},
},
Action: func(ctx context.Context, cmd *cli.Command) error {
message = &waE2E.Message{Conversation: proto.String(text)}
sendMessage2(message, jidStr, client)
return nil
},
},
{
Name: "getgroups",
Usage: "print all available group info",
Action: func(ctx context.Context, cmd *cli.Command) error {
groups, err := client.GetJoinedGroups(ctx)
if err != nil {
slog.Error("Failed to fetch group info", "error", err)
} else {
for _, item := range groups {
fmt.Println(*item)
}
}
return nil
},
},
{
Name: "poll",
Usage: "send a poll using <JID> <HEADER> <OPTIONS>",
Arguments: []cli.Argument{
&cli.StringArg{Name: "jid", Destination: &jidStr}, // use id field of group
&cli.StringArg{Name: "header", Destination: &header},
&cli.StringArgs{Name: "options", Min: 2, Max: -1},
},
Action: func(ctx context.Context, cmd *cli.Command) error {
// parse JID
message = client.BuildPollCreation(header, cmd.StringArgs("options"), 1)
sendMessage(message, jidStr, client)
return nil
},
},
},
}
// before
client, container, _ = initClient()
// run
//FIXME running cmd.Run after initclient() makes it impossible to print help without logging in
cmd.Run(context.Background(), os.Args)
// after
time.Sleep(5 * time.Second)
client.Disconnect()
container.Close()
}