-
Notifications
You must be signed in to change notification settings - Fork 0
Whatsmeow #15
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Whatsmeow #15
Changes from all commits
9d25ac3
8c82317
017d002
036112b
df74797
cd580c6
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,3 +1,4 @@ | ||
| twilio-join-sandbox.txt | ||
| config.ini.local | ||
| .env.local | ||
| devicestore.db |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,16 +1,18 @@ | ||
| FROM golang:1.24.6 AS builder | ||
| FROM golang:1.24-alpine AS builder | ||
| ENV CGO_ENABLED=1 | ||
| RUN apk add --no-cache gcc musl-dev sqlite-dev | ||
| WORKDIR /app | ||
|
|
||
| COPY go.mod go.sum ./ | ||
| RUN go mod download | ||
| COPY . . | ||
| RUN CGO_ENABLED=0 go build -o backend main.go | ||
| RUN go build -o backend main.go | ||
|
|
||
| FROM gcr.io/distroless/static-debian12 | ||
| FROM alpine:3.21 | ||
| RUN apk add --no-cache sqlite-libs | ||
| WORKDIR /app | ||
| COPY --from=builder /app/backend . | ||
| COPY .env . | ||
| COPY config.ini . | ||
|
|
||
| EXPOSE 8080 | ||
| CMD ["./backend"] | ||
| CMD ["./backend", "-w"] | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,16 +1,23 @@ | ||
| package main | ||
|
|
||
| import ( | ||
| "context" | ||
| "fmt" | ||
| "household-planner/pkg/backend" | ||
| "household-planner/pkg/planner" | ||
| "os" | ||
| "slices" | ||
| "time" | ||
|
|
||
| "github.com/kr/pretty" | ||
| "go.mau.fi/whatsmeow/proto/waE2E" | ||
| "google.golang.org/protobuf/proto" | ||
| ) | ||
|
|
||
| func main() { | ||
| fmt.Println("[INFO] Starting Household Planner...") | ||
| debug := len(os.Args) > 1 && os.Args[1] == "-d" | ||
| debug := len(os.Args) > 1 && slices.Contains(os.Args, "-d") | ||
| useWhatsApp := len(os.Args) > 1 && slices.Contains(os.Args, "-w") | ||
|
|
||
| myHousehold, err := planner.NewHousehold() | ||
| if err != nil { | ||
|
|
@@ -24,7 +31,6 @@ func main() { | |
| for { | ||
| if debug { | ||
| fmt.Println("[DEBUG] Starting next day in one minute...: ") | ||
| // fmt.Printf("%# v\n", pretty.Formatter(myHousehold)) | ||
| time.Sleep(1 * time.Minute) | ||
| } else { | ||
| planner.WaitUntilNoon() | ||
|
|
@@ -38,10 +44,44 @@ func main() { | |
| myHousehold.AssignWeeklyTasks() | ||
| myHousehold.AssignMonthlyTasks() | ||
|
|
||
| client := planner.InitializeTwilioClient() | ||
| for _, member := range myHousehold.Members { | ||
| assignedTasks := myHousehold.GetAssignedTasks(member) | ||
| planner.SendMessageSms(client, member, assignedTasks, debug) | ||
| // Send messages via whatsmeow | ||
| if useWhatsApp { | ||
| client := planner.NewWhatsmeowClient() | ||
|
|
||
| // NOTE: Needs QR Login via terminal on first startup | ||
| planner.Login(client) | ||
| time.Sleep(time.Second * 30) | ||
|
ashiven marked this conversation as resolved.
|
||
|
|
||
| phoneNumbers := myHousehold.PhoneNumbers() | ||
| JIDs := planner.PhoneNumbersToJIDs(client, phoneNumbers) | ||
|
Comment on lines
+49
to
+56
|
||
|
|
||
| for _, member := range myHousehold.Members { | ||
| assignedTasks := myHousehold.GetAssignedTasks(member) | ||
| message := planner.CreateDailyTaskMessage(assignedTasks, member) | ||
|
|
||
| if debug { | ||
| pretty.Println("[DEBUG] member: ", member) | ||
| pretty.Println("[DEBUG] phoneNumber: ", member.PhoneNumber) | ||
| pretty.Println("[DEBUG] JID: ", JIDs[member.PhoneNumber]) | ||
| pretty.Println("[DEBUG] message: ", message) | ||
|
|
||
| } else { | ||
| JID := JIDs[member.PhoneNumber] | ||
| waMessage := &waE2E.Message{Conversation: proto.String(message)} | ||
| _, err := client.SendMessage(context.Background(), JID, waMessage) | ||
| if err != nil { | ||
| fmt.Printf("[ERROR] Failed to deliver message to %s.\n", member.Name) | ||
| } | ||
| } | ||
|
Comment on lines
+69
to
+75
|
||
| } | ||
|
|
||
| // Send messages via twilio sms | ||
| } else { | ||
| client := planner.InitializeTwilioClient() | ||
| for _, member := range myHousehold.Members { | ||
| assignedTasks := myHousehold.GetAssignedTasks(member) | ||
| planner.SendMessageSms(client, member, assignedTasks, debug) | ||
| } | ||
| } | ||
| } | ||
| } | ||
Uh oh!
There was an error while loading. Please reload this page.