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: update .gitignore and enhance environment variable handling

Aldino Kemal31c57f459dc6
diff --git a/.gitignore b/.gitignore
index 7677f1dc..afb8def8 100644
--- a/.gitignore
+++ b/.gitignore
@@ -8,4 +8,5 @@ main.exe
*.jpe
src/pkged.go
storages
-.env
\ No newline at end of file
+.env
+bin
\ No newline at end of file
diff --git a/src/cmd/root.go b/src/cmd/root.go
index 1f76819a..57bb5a6b 100644
--- a/src/cmd/root.go
+++ b/src/cmd/root.go
@@ -3,6 +3,7 @@ package cmd
import (
"context"
"embed"
+ "fmt"
"os"
"strings"
"time"
@@ -68,45 +69,46 @@ func init() {
// initEnvConfig loads configuration from environment variables
func initEnvConfig() {
+ fmt.Println(viper.AllSettings())
// Application settings
- if envPort := viper.GetString("APP_PORT"); envPort != "" {
+ if envPort := viper.GetString("app_port"); envPort != "" {
config.AppPort = envPort
}
- if envDebug := viper.GetBool("APP_DEBUG"); envDebug {
+ if envDebug := viper.GetBool("app_debug"); envDebug {
config.AppDebug = envDebug
}
- if envOs := viper.GetString("APP_OS"); envOs != "" {
+ if envOs := viper.GetString("app_os"); envOs != "" {
config.AppOs = envOs
}
- if envBasicAuth := viper.GetString("APP_BASIC_AUTH"); envBasicAuth != "" {
+ if envBasicAuth := viper.GetString("app_basic_auth"); envBasicAuth != "" {
credential := strings.Split(envBasicAuth, ",")
config.AppBasicAuthCredential = credential
}
- if envChatFlushInterval := viper.GetInt("APP_CHAT_FLUSH_INTERVAL"); envChatFlushInterval > 0 {
+ if envChatFlushInterval := viper.GetInt("app_chat_flush_interval"); envChatFlushInterval > 0 {
config.AppChatFlushIntervalDays = envChatFlushInterval
}
// Database settings
- if envDBURI := viper.GetString("DB_URI"); envDBURI != "" {
+ if envDBURI := viper.GetString("db_uri"); envDBURI != "" {
config.DBURI = envDBURI
}
// WhatsApp settings
- if envAutoReply := viper.GetString("WHATSAPP_AUTO_REPLY"); envAutoReply != "" {
+ if envAutoReply := viper.GetString("whatsapp_auto_reply"); envAutoReply != "" {
config.WhatsappAutoReplyMessage = envAutoReply
}
- if envWebhook := viper.GetString("WHATSAPP_WEBHOOK"); envWebhook != "" {
+ if envWebhook := viper.GetString("whatsapp_webhook"); envWebhook != "" {
webhook := strings.Split(envWebhook, ",")
config.WhatsappWebhook = webhook
}
- if envWebhookSecret := viper.GetString("WHATSAPP_WEBHOOK_SECRET"); envWebhookSecret != "" {
+ if envWebhookSecret := viper.GetString("whatsapp_webhook_secret"); envWebhookSecret != "" {
config.WhatsappWebhookSecret = envWebhookSecret
}
- if envAccountValidation := viper.GetBool("WHATSAPP_ACCOUNT_VALIDATION"); envAccountValidation {
- config.WhatsappAccountValidation = envAccountValidation
+ if viper.IsSet("whatsapp_account_validation") {
+ config.WhatsappAccountValidation = viper.GetBool("whatsapp_account_validation")
}
- if envChatStorage := viper.GetBool("WHATSAPP_CHAT_STORAGE"); !envChatStorage {
- config.WhatsappChatStorage = envChatStorage
+ if viper.IsSet("whatsapp_chat_storage") {
+ config.WhatsappChatStorage = viper.GetBool("whatsapp_chat_storage")
}
}
diff --git a/src/infrastructure/whatsapp/init.go b/src/infrastructure/whatsapp/init.go
index 11907981..1eea4bb1 100644
--- a/src/infrastructure/whatsapp/init.go
+++ b/src/infrastructure/whatsapp/init.go
@@ -247,9 +247,18 @@ func handleAutoReply(evt *events.Message) {
}
func handleWebhookForward(ctx context.Context, evt *events.Message) {
+ // Skip webhook for specific protocol messages that shouldn't trigger webhooks
+ if protocolMessage := evt.Message.GetProtocolMessage(); protocolMessage != nil {
+ protocolType := protocolMessage.GetType().String()
+ // Skip EPHEMERAL_SYNC_RESPONSE but allow REVOKE and MESSAGE_EDIT
+ if protocolType == "EPHEMERAL_SYNC_RESPONSE" {
+ log.Debugf("Skipping webhook for EPHEMERAL_SYNC_RESPONSE message")
+ return
+ }
+ }
+
if len(config.WhatsappWebhook) > 0 &&
- !strings.Contains(evt.Info.SourceString(), "broadcast") &&
- !isFromMySelf(evt.Info.SourceString()) {
+ !strings.Contains(evt.Info.SourceString(), "broadcast") {
go func(evt *events.Message) {
if err := forwardToWebhook(ctx, evt); err != nil {
logrus.Error("Failed forward to webhook: ", err)
@@ -259,9 +268,10 @@ func handleWebhookForward(ctx context.Context, evt *events.Message) {
}
func handleReceipt(_ context.Context, evt *events.Receipt) {
- if evt.Type == types.ReceiptTypeRead || evt.Type == types.ReceiptTypeReadSelf {
+ switch evt.Type {
+ case types.ReceiptTypeRead, types.ReceiptTypeReadSelf:
log.Infof("%v was read by %s at %s", evt.MessageIDs, evt.SourceString(), evt.Timestamp)
- } else if evt.Type == types.ReceiptTypeDelivered {
+ case types.ReceiptTypeDelivered:
log.Infof("%s was delivered to %s at %s", evt.MessageIDs[0], evt.SourceString(), evt.Timestamp)
}
}
diff --git a/src/infrastructure/whatsapp/webhook.go b/src/infrastructure/whatsapp/webhook.go
index 052d8187..59e6ad56 100644
--- a/src/infrastructure/whatsapp/webhook.go
+++ b/src/infrastructure/whatsapp/webhook.go
@@ -5,12 +5,13 @@ import (
"context"
"encoding/json"
"fmt"
- "go.mau.fi/whatsmeow/types"
"net/http"
"regexp"
"strings"
"time"
+ "go.mau.fi/whatsmeow/types"
+
"github.com/aldinokemal/go-whatsapp-web-multidevice/config"
pkgError "github.com/aldinokemal/go-whatsapp-web-multidevice/pkg/error"
"github.com/sirupsen/logrus"
@@ -109,6 +110,32 @@ func createPayload(ctx context.Context, evt *events.Message) (map[string]interfa
body["timestamp"] = timestamp
}
+ // Handle protocol messages (revoke, etc.)
+ if protocolMessage := evt.Message.GetProtocolMessage(); protocolMessage != nil {
+ protocolType := protocolMessage.GetType().String()
+
+ switch protocolType {
+ case "REVOKE":
+ body["action"] = "message_revoked"
+ if key := protocolMessage.GetKey(); key != nil {
+ body["revoked_message_id"] = key.GetID()
+ body["revoked_from_me"] = key.GetFromMe()
+ if key.GetRemoteJID() != "" {
+ body["revoked_chat"] = key.GetRemoteJID()
+ }
+ }
+ case "MESSAGE_EDIT":
+ body["action"] = "message_edited"
+ if editedMessage := protocolMessage.GetEditedMessage(); editedMessage != nil {
+ if editedText := editedMessage.GetExtendedTextMessage(); editedText != nil {
+ body["edited_text"] = editedText.GetText()
+ } else if editedConv := editedMessage.GetConversation(); editedConv != "" {
+ body["edited_text"] = editedConv
+ }
+ }
+ }
+ }
+
if audioMedia := evt.Message.GetAudioMessage(); audioMedia != nil {
path, err := ExtractMedia(ctx, config.PathMedia, audioMedia)
if err != nil {