Compare commits
10 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
6f44b9ea7d | ||
|
|
8e4443852f | ||
|
|
381299cd2e | ||
|
|
846e8c0184 | ||
|
|
a979b93121 | ||
|
|
f6eddad980 | ||
|
|
765efd0efb | ||
|
|
64a154e605 | ||
|
|
f4d3dac6ab | ||
|
|
6522fea34c |
9
Makefile
9
Makefile
@@ -1,9 +1,9 @@
|
||||
CC=go build
|
||||
NAME=schneller_whatsapp
|
||||
NAME=schneller-whatsapp
|
||||
default: build
|
||||
|
||||
build:
|
||||
$(CC)
|
||||
$(CC) -o $(NAME)
|
||||
|
||||
run:
|
||||
go run .
|
||||
@@ -19,5 +19,10 @@ update-all:
|
||||
go get -u
|
||||
go mod tidy
|
||||
|
||||
deploy:
|
||||
rsync $(NAME) jojo:$(NAME)
|
||||
|
||||
upgrade: update deploy
|
||||
|
||||
clean:
|
||||
git clean -fX
|
||||
|
||||
@@ -4,7 +4,8 @@ CLI Whatsapp Messages (and Polls) using go:
|
||||
- [urfave/cli](https://github.com/urfave/cli) for the command line
|
||||
|
||||
# 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:
|
||||
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.
|
||||
|
||||
24
go.mod
24
go.mod
@@ -3,32 +3,32 @@ module github.com/eneller/schneller-whatsapp
|
||||
go 1.24.2
|
||||
|
||||
require (
|
||||
github.com/google/shlex v0.0.0-20191202100458-e7afc7fbc510
|
||||
github.com/mattn/go-sqlite3 v1.14.32
|
||||
github.com/mdp/qrterminal/v3 v3.2.1
|
||||
github.com/urfave/cli/v3 v3.5.0
|
||||
go.mau.fi/whatsmeow v0.0.0-20251023183934-2ced35dd7e8c
|
||||
github.com/urfave/cli/v3 v3.6.0
|
||||
go.mau.fi/whatsmeow v0.0.0-20251127132918-b9ac3d51d746
|
||||
google.golang.org/protobuf v1.36.10
|
||||
)
|
||||
|
||||
require (
|
||||
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/shlex v0.0.0-20191202100458-e7afc7fbc510 // 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-isatty v0.0.20 // indirect
|
||||
github.com/petermattis/goid v0.0.0-20250904145737-900bdf8bb490 // indirect
|
||||
github.com/rs/zerolog v1.34.0 // indirect
|
||||
github.com/vektah/gqlparser/v2 v2.5.30 // indirect
|
||||
github.com/vektah/gqlparser/v2 v2.5.31 // indirect
|
||||
go.mau.fi/libsignal v0.2.1 // indirect
|
||||
go.mau.fi/util v0.9.2 // indirect
|
||||
golang.org/x/crypto v0.43.0 // indirect
|
||||
golang.org/x/exp v0.0.0-20251023183803-a4bb9ffd2546 // indirect
|
||||
golang.org/x/net v0.46.0 // indirect
|
||||
golang.org/x/sys v0.37.0 // indirect
|
||||
golang.org/x/term v0.36.0 // indirect
|
||||
golang.org/x/text v0.30.0 // indirect
|
||||
go.mau.fi/util v0.9.3 // indirect
|
||||
golang.org/x/crypto v0.45.0 // indirect
|
||||
golang.org/x/exp v0.0.0-20251113190631-e25ba8c21ef6 // indirect
|
||||
golang.org/x/net v0.47.0 // indirect
|
||||
golang.org/x/sys v0.38.0 // indirect
|
||||
golang.org/x/term v0.37.0 // indirect
|
||||
golang.org/x/text v0.31.0 // indirect
|
||||
rsc.io/qr v0.2.0 // indirect
|
||||
)
|
||||
|
||||
44
go.sum
44
go.sum
@@ -8,6 +8,8 @@ github.com/andreyvit/diff v0.0.0-20170406064948-c7f18ee00883 h1:bvNMNQO63//z+xNg
|
||||
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/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=
|
||||
@@ -20,8 +22,6 @@ github.com/google/shlex v0.0.0-20191202100458-e7afc7fbc510 h1:El6M4kTTCOh6aBiKaU
|
||||
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/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.14 h1:9A9LHSqF/7dyVVX6g0U9cwm9pG3kP9gSzcuIPHPsaIE=
|
||||
github.com/mattn/go-colorable v0.1.14/go.mod h1:6LmQG8QLFO4G5z1gPvYEzlUgJ2wF+stgPZH1UqBm1s8=
|
||||
@@ -45,31 +45,31 @@ github.com/sergi/go-diff v1.3.1 h1:xkr+Oxo4BOQKmkn/B9eMK0g5Kg/983T9DqqPHwYqD+8=
|
||||
github.com/sergi/go-diff v1.3.1/go.mod h1:aMJSSKb2lpPvRNec0+w3fl7LP9IOFzdc9Pa4NFbPK1I=
|
||||
github.com/stretchr/testify v1.11.1 h1:7s2iGBzp5EwR7/aIZr8ao5+dra3wiQyKjjFuvgVKu7U=
|
||||
github.com/stretchr/testify v1.11.1/go.mod h1:wZwfW3scLgRK+23gO65QZefKpKQRnfz6sD981Nm4B6U=
|
||||
github.com/urfave/cli/v3 v3.5.0 h1:qCuFMmdayTF3zmjG8TSsoBzrDqszNrklYg2x3g4MSgw=
|
||||
github.com/urfave/cli/v3 v3.5.0/go.mod h1:ysVLtOEmg2tOy6PknnYVhDoouyC/6N42TMeoMzskhso=
|
||||
github.com/vektah/gqlparser/v2 v2.5.30 h1:EqLwGAFLIzt1wpx1IPpY67DwUujF1OfzgEyDsLrN6kE=
|
||||
github.com/vektah/gqlparser/v2 v2.5.30/go.mod h1:D1/VCZtV3LPnQrcPBeR/q5jkSQIPti0uYCP/RI0gIeo=
|
||||
github.com/urfave/cli/v3 v3.6.0 h1:oIdArVjkdIXHWg3iqxgmqwQGC8NM0JtdgwQAj2sRwFo=
|
||||
github.com/urfave/cli/v3 v3.6.0/go.mod h1:ysVLtOEmg2tOy6PknnYVhDoouyC/6N42TMeoMzskhso=
|
||||
github.com/vektah/gqlparser/v2 v2.5.31 h1:YhWGA1mfTjID7qJhd1+Vxhpk5HTgydrGU9IgkWBTJ7k=
|
||||
github.com/vektah/gqlparser/v2 v2.5.31/go.mod h1:c1I28gSOVNzlfc4WuDlqU7voQnsqI6OG2amkBAFmgts=
|
||||
go.mau.fi/libsignal v0.2.1 h1:vRZG4EzTn70XY6Oh/pVKrQGuMHBkAWlGRC22/85m9L0=
|
||||
go.mau.fi/libsignal v0.2.1/go.mod h1:iVvjrHyfQqWajOUaMEsIfo3IqgVMrhWcPiiEzk7NgoU=
|
||||
go.mau.fi/util v0.9.2 h1:+S4Z03iCsGqU2WY8X2gySFsFjaLlUHFRDVCYvVwynKM=
|
||||
go.mau.fi/util v0.9.2/go.mod h1:055elBBCJSdhRsmub7ci9hXZPgGr1U6dYg44cSgRgoU=
|
||||
go.mau.fi/whatsmeow v0.0.0-20251023183934-2ced35dd7e8c h1:7QLq7oW+q8U5AU7uhGsVOB2qPD3306fr7oVSni77c+A=
|
||||
go.mau.fi/whatsmeow v0.0.0-20251023183934-2ced35dd7e8c/go.mod h1:VJq+D05Fe5EroZxs2StEYD/AsWJO2aQ7Niucz7lCvao=
|
||||
golang.org/x/crypto v0.43.0 h1:dduJYIi3A3KOfdGOHX8AVZ/jGiyPa3IbBozJ5kNuE04=
|
||||
golang.org/x/crypto v0.43.0/go.mod h1:BFbav4mRNlXJL4wNeejLpWxB7wMbc79PdRGhWKncxR0=
|
||||
golang.org/x/exp v0.0.0-20251023183803-a4bb9ffd2546 h1:mgKeJMpvi0yx/sU5GsxQ7p6s2wtOnGAHZWCHUM4KGzY=
|
||||
golang.org/x/exp v0.0.0-20251023183803-a4bb9ffd2546/go.mod h1:j/pmGrbnkbPtQfxEe5D0VQhZC6qKbfKifgD0oM7sR70=
|
||||
golang.org/x/net v0.46.0 h1:giFlY12I07fugqwPuWJi68oOnpfqFnJIJzaIIm2JVV4=
|
||||
golang.org/x/net v0.46.0/go.mod h1:Q9BGdFy1y4nkUwiLvT5qtyhAnEHgnQ/zd8PfU6nc210=
|
||||
go.mau.fi/util v0.9.3 h1:aqNF8KDIN8bFpFbybSk+mEBil7IHeBwlujfyTnvP0uU=
|
||||
go.mau.fi/util v0.9.3/go.mod h1:krWWfBM1jWTb5f8NCa2TLqWMQuM81X7TGQjhMjBeXmQ=
|
||||
go.mau.fi/whatsmeow v0.0.0-20251127132918-b9ac3d51d746 h1:51hAK0a+KA4BD7MgqfVd6dbJd5cJBhotOlhWUybYCn0=
|
||||
go.mau.fi/whatsmeow v0.0.0-20251127132918-b9ac3d51d746/go.mod h1:5aYaEa3FF5e5XWsA8Xa80ttUXZvb6HyaBGgo2SfzUkE=
|
||||
golang.org/x/crypto v0.45.0 h1:jMBrvKuj23MTlT0bQEOBcAE0mjg8mK9RXFhRH6nyF3Q=
|
||||
golang.org/x/crypto v0.45.0/go.mod h1:XTGrrkGJve7CYK7J8PEww4aY7gM3qMCElcJQ8n8JdX4=
|
||||
golang.org/x/exp v0.0.0-20251113190631-e25ba8c21ef6 h1:zfMcR1Cs4KNuomFFgGefv5N0czO2XZpUbxGUy8i8ug0=
|
||||
golang.org/x/exp v0.0.0-20251113190631-e25ba8c21ef6/go.mod h1:46edojNIoXTNOhySWIWdix628clX9ODXwPsQuG6hsK0=
|
||||
golang.org/x/net v0.47.0 h1:Mx+4dIFzqraBXUugkia1OOvlD6LemFo1ALMHjrXDOhY=
|
||||
golang.org/x/net v0.47.0/go.mod h1:/jNxtkgq5yWUGYkaZGqo27cfGZ1c5Nen03aYrrKpVRU=
|
||||
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.12.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||
golang.org/x/sys v0.37.0 h1:fdNQudmxPjkdUTPnLn5mdQv7Zwvbvpaxqs831goi9kQ=
|
||||
golang.org/x/sys v0.37.0/go.mod h1:OgkHotnGiDImocRcuBABYBEXf8A9a87e/uXjp9XT3ks=
|
||||
golang.org/x/term v0.36.0 h1:zMPR+aF8gfksFprF/Nc/rd1wRS1EI6nDBGyWAvDzx2Q=
|
||||
golang.org/x/term v0.36.0/go.mod h1:Qu394IJq6V6dCBRgwqshf3mPF85AqzYEzofzRdZkWss=
|
||||
golang.org/x/text v0.30.0 h1:yznKA/E9zq54KzlzBEAWn1NXSQ8DIp/NYMy88xJjl4k=
|
||||
golang.org/x/text v0.30.0/go.mod h1:yDdHFIX9t+tORqspjENWgzaCVXgk0yYnYuSZ8UzzBVM=
|
||||
golang.org/x/sys v0.38.0 h1:3yZWxaJjBmCWXqhN1qh02AkOnCQ1poK6oF+a7xWL6Gc=
|
||||
golang.org/x/sys v0.38.0/go.mod h1:OgkHotnGiDImocRcuBABYBEXf8A9a87e/uXjp9XT3ks=
|
||||
golang.org/x/term v0.37.0 h1:8EGAD0qCmHYZg6J17DvsMy9/wJ7/D/4pV/wfnld5lTU=
|
||||
golang.org/x/term v0.37.0/go.mod h1:5pB4lxRNYYVZuTLmy8oR2BH8dflOR+IbTYFD8fi3254=
|
||||
golang.org/x/text v0.31.0 h1:aC8ghyu4JhP8VojJ2lEHBnochRno1sgL6nEi9WGFGMM=
|
||||
golang.org/x/text v0.31.0/go.mod h1:tKRAlv61yKIjGGHX/4tP1LTbc13YSec1pxVEWXzfoeM=
|
||||
google.golang.org/protobuf v1.36.10 h1:AYd7cD/uASjIL6Q9LiTjz8JLcrh/88q5UObnmY3aOOE=
|
||||
google.golang.org/protobuf v1.36.10/go.mod h1:HTf+CrKn2C3g5S8VImy6tdcUvCska2kB7j23XfzDpco=
|
||||
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
|
||||
|
||||
2
src/log.go
Normal file
2
src/log.go
Normal file
@@ -0,0 +1,2 @@
|
||||
// https://github.com/tulir/whatsmeow/blob/071293c6b9f03f66d2e50bdd659536611d2e10f3/util/log/log.go
|
||||
package main
|
||||
@@ -5,7 +5,7 @@ import (
|
||||
"bufio"
|
||||
"context"
|
||||
"fmt"
|
||||
"log"
|
||||
"log/slog"
|
||||
"os"
|
||||
"time"
|
||||
|
||||
@@ -17,21 +17,12 @@ import (
|
||||
"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) {
|
||||
//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)
|
||||
@@ -44,13 +35,11 @@ func initClient() (*whatsmeow.Client, *sqlstore.Container, waLog.Logger) {
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
clientLog := waLog.Stdout("Client", "DEBUG", true)
|
||||
client := whatsmeow.NewClient(deviceStore, clientLog)
|
||||
client.AddEventHandler(eventHandler)
|
||||
client := whatsmeow.NewClient(deviceStore, nil)
|
||||
|
||||
// handle login via QR
|
||||
if client.Store.ID == nil {
|
||||
fmt.Println("Client store ID is nil, scanning QR")
|
||||
slog.Info("Client store ID is nil, scanning QR")
|
||||
// No ID stored, new login
|
||||
qrChan, _ := client.GetQRChannel(context.Background())
|
||||
err = client.Connect()
|
||||
@@ -65,12 +54,12 @@ func initClient() (*whatsmeow.Client, *sqlstore.Container, waLog.Logger) {
|
||||
// or just manually `echo 2@... | qrencode -t ansiutf8` in a terminal
|
||||
fmt.Println("QR code: ", evt.Code)
|
||||
} else {
|
||||
fmt.Println("Login event:", evt.Event)
|
||||
slog.Debug("Login event", "event", evt.Event)
|
||||
}
|
||||
}
|
||||
} else {
|
||||
// Already logged in, just connect
|
||||
fmt.Println("Connecting")
|
||||
slog.Info("Connecting")
|
||||
|
||||
err = client.Connect()
|
||||
if err != nil {
|
||||
@@ -85,16 +74,16 @@ func sendMessage(message *waE2E.Message, jidStr string, client *whatsmeow.Client
|
||||
var JID types.JID
|
||||
JID, err := types.ParseJID(jidStr)
|
||||
if err != nil {
|
||||
log.Fatal("Failed to parse JID: ", jidStr)
|
||||
slog.Error("Failed to parse", "JID", jidStr)
|
||||
} else {
|
||||
log.Println("Parsed JID correctly", JID)
|
||||
slog.Info("Parsed correctly", "JID", JID)
|
||||
}
|
||||
_, err = client.SendMessage(context.Background(), JID, message)
|
||||
// FIXME showing error even when successful
|
||||
if err == nil {
|
||||
log.Println("Sent Message successfully")
|
||||
if err != nil {
|
||||
slog.Error("Failed to send message", "error", err)
|
||||
} else {
|
||||
fmt.Println("Failed to Send Message", err)
|
||||
slog.Info("Sent Message successfully")
|
||||
|
||||
}
|
||||
}
|
||||
@@ -113,20 +102,19 @@ func main() {
|
||||
scanner := bufio.NewScanner(os.Stdin)
|
||||
for scanner.Scan() {
|
||||
if err := scanner.Err(); err != nil {
|
||||
fmt.Fprintf(os.Stderr, "Error reading: %v\n", err)
|
||||
slog.Error("Error reading", "error", err)
|
||||
continue
|
||||
}
|
||||
args, err := shlex.Split(scanner.Text())
|
||||
if err != nil {
|
||||
fmt.Fprintf(os.Stderr, "Error parsing command: %v\n", err)
|
||||
if err != nil || len(args) == 0 {
|
||||
slog.Error("Error parsing command", "command", err)
|
||||
continue
|
||||
}
|
||||
fmt.Println(args)
|
||||
subcmd := cmd.Command(args[0])
|
||||
if subcmd != nil {
|
||||
subcmd.Run(ctx, args)
|
||||
} else {
|
||||
fmt.Fprintf(os.Stderr, "Unknown command: %s\n", args[0])
|
||||
slog.Error("Unknown command", "command", args[0])
|
||||
}
|
||||
}
|
||||
fmt.Println("Stdin closed.")
|
||||
@@ -150,7 +138,14 @@ func main() {
|
||||
Name: "getgroups",
|
||||
Usage: "print all available group info",
|
||||
Action: func(ctx context.Context, cmd *cli.Command) error {
|
||||
fmt.Println(client.GetJoinedGroups(ctx))
|
||||
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
|
||||
},
|
||||
},
|
||||
Reference in New Issue
Block a user