From 3f84b3cf093d73abf84ca9cd8731572222726766 Mon Sep 17 00:00:00 2001 From: 6justgotme Date: Mon, 3 Aug 2026 16:22:04 -0300 Subject: [PATCH] fix: recover undecryptable messages via AutomaticMessageRerequestFromPhone Companion/multi-device deployments drop the first message from new contacts when it fails to decrypt: whatsmeow emits UndecryptableMessage and the event handler skips the webhook (only view_once / ID 66-67 are handled), with no retry, so the message is lost. Enable whatsmeow's AutomaticMessageRerequestFromPhone so undecryptable messages are re-requested from the phone and re-dispatched as normal Message events. Gated behind a new REREQUEST_FROM_PHONE env var (opt-in, default off) so operators choose per deployment. Co-Authored-By: Claude Opus 4.8 --- pkg/config/config.go | 4 ++++ pkg/config/env/env.go | 1 + pkg/whatsmeow/service/whatsmeow.go | 2 ++ 3 files changed, 7 insertions(+) diff --git a/pkg/config/config.go b/pkg/config/config.go index c90c9e14..0ebec2e2 100644 --- a/pkg/config/config.go +++ b/pkg/config/config.go @@ -30,6 +30,7 @@ type Config struct { LogType string WebhookFiles bool ConnectOnStartup bool + RerequestFromPhone bool OsName string AmqpUrl string AmqpGlobalEnabled bool @@ -280,6 +281,8 @@ func Load() *Config { checkUserExists = "true" } + rerequestFromPhone := os.Getenv(config_env.REREQUEST_FROM_PHONE) + // Convertendo para int com valores padrĂ£o caso estejam vazios major := 0 if whatsappVersionMajor != "" { @@ -375,6 +378,7 @@ func Load() *Config { EventIgnoreStatus: eventIgnoreStatus == "true", QrcodeMaxCount: qrMaxCount, CheckUserExists: checkUserExists != "false", // Default true, set to false to disable + RerequestFromPhone: rerequestFromPhone == "true", AmqpGlobalEvents: amqpGlobalEvents, AmqpSpecificEvents: amqpSpecificEvents, NatsUrl: natsUrl, diff --git a/pkg/config/env/env.go b/pkg/config/env/env.go index cda9be84..949307e0 100644 --- a/pkg/config/env/env.go +++ b/pkg/config/env/env.go @@ -14,6 +14,7 @@ const ( LOGTYPE = "LOG_TYPE" WEBHOOKFILES = "WEBHOOK_FILES" CONNECT_ON_STARTUP = "CONNECT_ON_STARTUP" + REREQUEST_FROM_PHONE = "REREQUEST_FROM_PHONE" OS_NAME = "OS_NAME" AMQP_URL = "AMQP_URL" AMQP_GLOBAL_ENABLED = "AMQP_GLOBAL_ENABLED" diff --git a/pkg/whatsmeow/service/whatsmeow.go b/pkg/whatsmeow/service/whatsmeow.go index 366f0edb..de144f10 100644 --- a/pkg/whatsmeow/service/whatsmeow.go +++ b/pkg/whatsmeow/service/whatsmeow.go @@ -463,6 +463,8 @@ func (w whatsmeowService) StartClient(cd *ClientData) { client.EnableAutoReconnect = false client.AutoTrustIdentity = true + // Re-request messages that fail to decrypt from the phone instead of dropping them. + client.AutomaticMessageRerequestFromPhone = w.config.RerequestFromPhone mycli := &MyClient{ service: &w,