1 Commits

Author SHA1 Message Date
16eedcd5b2 Add renovate.json 2025-10-22 10:20:32 +00:00
7 changed files with 58 additions and 87 deletions

View File

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

View File

@@ -5,9 +5,6 @@ default: build
build: build:
$(CC) $(CC)
run:
go run .
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
@@ -15,9 +12,5 @@ update:
go get -u go.mau.fi/whatsmeow go get -u go.mau.fi/whatsmeow
go mod tidy go mod tidy
update-all:
go get -u
go mod tidy
clean: clean:
git clean -fX git clean -fX

View File

@@ -7,7 +7,7 @@ CLI Whatsapp Messages (and Polls) using go:
Can be easily scheduled using `crontab` because of its non-interactive operation Can be easily scheduled using `crontab` because of its non-interactive operation
``` ```
NAME: 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. schneller-whatsapp - Run WhatsApp actions from your CLI. User JID has to end with '@s.whatsapp.net', Group ID with '@g.us'
USAGE: USAGE:
schneller-whatsapp [global options] [command [command options]] schneller-whatsapp [global options] [command [command options]]

7
go.mod
View File

@@ -5,8 +5,8 @@ go 1.24.2
require ( require (
github.com/mattn/go-sqlite3 v1.14.32 github.com/mattn/go-sqlite3 v1.14.32
github.com/mdp/qrterminal/v3 v3.2.1 github.com/mdp/qrterminal/v3 v3.2.1
github.com/urfave/cli/v3 v3.5.0 github.com/urfave/cli/v3 v3.4.1
go.mau.fi/whatsmeow v0.0.0-20251023183934-2ced35dd7e8c go.mau.fi/whatsmeow v0.0.0-20251016095441-02c50743e601
google.golang.org/protobuf v1.36.10 google.golang.org/protobuf v1.36.10
) )
@@ -14,7 +14,6 @@ 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/beeper/argo-go v1.1.2 // indirect
github.com/elliotchance/orderedmap/v3 v3.1.0 // 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/google/uuid v1.6.0 // indirect
github.com/gorilla/websocket v1.5.3 // 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
@@ -25,7 +24,7 @@ require (
go.mau.fi/libsignal v0.2.1 // indirect go.mau.fi/libsignal v0.2.1 // indirect
go.mau.fi/util v0.9.2 // indirect go.mau.fi/util v0.9.2 // indirect
golang.org/x/crypto v0.43.0 // indirect golang.org/x/crypto v0.43.0 // indirect
golang.org/x/exp v0.0.0-20251023183803-a4bb9ffd2546 // indirect golang.org/x/exp v0.0.0-20251009144603-d2f985daa21b // indirect
golang.org/x/net v0.46.0 // indirect golang.org/x/net v0.46.0 // indirect
golang.org/x/sys v0.37.0 // indirect golang.org/x/sys v0.37.0 // indirect
golang.org/x/term v0.36.0 // indirect golang.org/x/term v0.36.0 // indirect

14
go.sum
View File

@@ -16,8 +16,6 @@ github.com/elliotchance/orderedmap/v3 v3.1.0/go.mod h1:G+Hc2RwaZvJMcS4JpGCOyViCn
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.7.0 h1:wk8382ETsv4JYUZwIsn6YpYiWiBsYLSJiTsyBybVuN8= github.com/google/go-cmp v0.7.0 h1:wk8382ETsv4JYUZwIsn6YpYiWiBsYLSJiTsyBybVuN8=
github.com/google/go-cmp v0.7.0/go.mod h1:pXiqmnSA92OHEEa9HXL2W4E7lf9JzCmGVUdgjX3N/iU= 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 h1:saDtZ6Pbx/0u+bgYQ3q96pZgCzfhKXGPqt7kZ72aNNg=
@@ -45,20 +43,20 @@ 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/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 h1:7s2iGBzp5EwR7/aIZr8ao5+dra3wiQyKjjFuvgVKu7U=
github.com/stretchr/testify v1.11.1/go.mod h1:wZwfW3scLgRK+23gO65QZefKpKQRnfz6sD981Nm4B6U= 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.4.1 h1:1M9UOCy5bLmGnuu1yn3t3CB4rG79Rtoxuv1sPhnm6qM=
github.com/urfave/cli/v3 v3.5.0/go.mod h1:ysVLtOEmg2tOy6PknnYVhDoouyC/6N42TMeoMzskhso= github.com/urfave/cli/v3 v3.4.1/go.mod h1:FJSKtM/9AiiTOJL4fJ6TbMUkxBXn7GO9guZqoZtpYpo=
github.com/vektah/gqlparser/v2 v2.5.30 h1:EqLwGAFLIzt1wpx1IPpY67DwUujF1OfzgEyDsLrN6kE= 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/vektah/gqlparser/v2 v2.5.30/go.mod h1:D1/VCZtV3LPnQrcPBeR/q5jkSQIPti0uYCP/RI0gIeo=
go.mau.fi/libsignal v0.2.1 h1:vRZG4EzTn70XY6Oh/pVKrQGuMHBkAWlGRC22/85m9L0= 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/libsignal v0.2.1/go.mod h1:iVvjrHyfQqWajOUaMEsIfo3IqgVMrhWcPiiEzk7NgoU=
go.mau.fi/util v0.9.2 h1:+S4Z03iCsGqU2WY8X2gySFsFjaLlUHFRDVCYvVwynKM= go.mau.fi/util v0.9.2 h1:+S4Z03iCsGqU2WY8X2gySFsFjaLlUHFRDVCYvVwynKM=
go.mau.fi/util v0.9.2/go.mod h1:055elBBCJSdhRsmub7ci9hXZPgGr1U6dYg44cSgRgoU= 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-20251016095441-02c50743e601 h1:6tytDOaqizeBVG3OdEojIiJtZXY3DWMvFKNkjbxq4tI=
go.mau.fi/whatsmeow v0.0.0-20251023183934-2ced35dd7e8c/go.mod h1:VJq+D05Fe5EroZxs2StEYD/AsWJO2aQ7Niucz7lCvao= go.mau.fi/whatsmeow v0.0.0-20251016095441-02c50743e601/go.mod h1:VJq+D05Fe5EroZxs2StEYD/AsWJO2aQ7Niucz7lCvao=
golang.org/x/crypto v0.43.0 h1:dduJYIi3A3KOfdGOHX8AVZ/jGiyPa3IbBozJ5kNuE04= golang.org/x/crypto v0.43.0 h1:dduJYIi3A3KOfdGOHX8AVZ/jGiyPa3IbBozJ5kNuE04=
golang.org/x/crypto v0.43.0/go.mod h1:BFbav4mRNlXJL4wNeejLpWxB7wMbc79PdRGhWKncxR0= 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-20251009144603-d2f985daa21b h1:18qgiDvlvH7kk8Ioa8Ov+K6xCi0GMvmGfGW0sgd/SYA=
golang.org/x/exp v0.0.0-20251023183803-a4bb9ffd2546/go.mod h1:j/pmGrbnkbPtQfxEe5D0VQhZC6qKbfKifgD0oM7sR70= golang.org/x/exp v0.0.0-20251009144603-d2f985daa21b/go.mod h1:j/pmGrbnkbPtQfxEe5D0VQhZC6qKbfKifgD0oM7sR70=
golang.org/x/net v0.46.0 h1:giFlY12I07fugqwPuWJi68oOnpfqFnJIJzaIIm2JVV4= golang.org/x/net v0.46.0 h1:giFlY12I07fugqwPuWJi68oOnpfqFnJIJzaIIm2JVV4=
golang.org/x/net v0.46.0/go.mod h1:Q9BGdFy1y4nkUwiLvT5qtyhAnEHgnQ/zd8PfU6nc210= golang.org/x/net v0.46.0/go.mod h1:Q9BGdFy1y4nkUwiLvT5qtyhAnEHgnQ/zd8PfU6nc210=
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=

96
main.go
View File

@@ -2,14 +2,12 @@
package main package main
import ( import (
"bufio"
"context" "context"
"fmt" "fmt"
"log" "log"
"os" "os"
"time" "time"
"github.com/google/shlex"
_ "github.com/mattn/go-sqlite3" _ "github.com/mattn/go-sqlite3"
"github.com/mdp/qrterminal/v3" "github.com/mdp/qrterminal/v3"
"github.com/urfave/cli/v3" "github.com/urfave/cli/v3"
@@ -80,25 +78,6 @@ func initClient() (*whatsmeow.Client, *sqlstore.Container, waLog.Logger) {
return client, container, dbLog return client, container, dbLog
} }
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 {
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)
}
}
}
func main() { func main() {
var jidStr, header, text string var jidStr, header, text string
var message *waE2E.Message var message *waE2E.Message
@@ -106,32 +85,7 @@ func main() {
var container *sqlstore.Container var container *sqlstore.Container
//var dbLog waLog.Logger //var dbLog waLog.Logger
cmd := &cli.Command{ cmd := &cli.Command{
Usage: "Run WhatsApp actions from your CLI. User JID has to end with '@s.whatsapp.net', Group ID with '@g.us'." + 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.",
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 {
fmt.Fprintf(os.Stderr, "Error reading: %v\n", err)
continue
}
args, err := shlex.Split(scanner.Text())
if err != nil || len(args) == 0 {
fmt.Fprintf(os.Stderr, "Error parsing command: %v\n", 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])
}
}
fmt.Println("Stdin closed.")
return nil
},
Commands: []*cli.Command{ Commands: []*cli.Command{
{ {
Name: "message", Name: "message",
@@ -141,8 +95,15 @@ func main() {
&cli.StringArg{Name: "message", Destination: &text}, &cli.StringArg{Name: "message", Destination: &text},
}, },
Action: func(ctx context.Context, cmd *cli.Command) error { 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)} message = &waE2E.Message{Conversation: proto.String(text)}
sendMessage(message, jidStr, client)
return nil return nil
}, },
}, },
@@ -165,18 +126,45 @@ func main() {
Action: func(ctx context.Context, cmd *cli.Command) error { Action: func(ctx context.Context, cmd *cli.Command) error {
// parse JID // parse JID
message = client.BuildPollCreation(header, cmd.StringArgs("options"), 1) message = client.BuildPollCreation(header, cmd.StringArgs("options"), 1)
sendMessage(message, jidStr, client)
return nil return nil
}, },
}, },
}, },
} Before: func(ctx context.Context, cmd *cli.Command) (context.Context, error) {
// before
client, container, _ = initClient() client, container, _ = initClient()
// run return nil, nil
cmd.Run(context.Background(), os.Args) },
// after 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) 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() client.Disconnect()
container.Close() container.Close()
return nil
},
}
if err := cmd.Run(context.Background(), os.Args); err != nil {
log.Fatal(err)
}
} }

3
renovate.json Normal file
View File

@@ -0,0 +1,3 @@
{
"$schema": "https://docs.renovatebot.com/renovate-schema.json"
}