diff --git a/sample_config.yaml b/sample_config.yaml index 2bfbcdf..6ddb873 100644 --- a/sample_config.yaml +++ b/sample_config.yaml @@ -57,6 +57,7 @@ whatsapp: send_revoked_message_updates: false whatsmeow_debug_mode: false send_my_messages_from_other_devices: false # If set to true, the messages sent by you from other devices will be sent to Telgram as well + create_thread_for_info_updates: false # If set to true, new thread will be created (if it doesn't exist) when profile picture changes for group/someone and when group metadata/members changes #login_database: # Uncomment only if you want to use something other than sqlite # type: sqlite3 # url: file:wawebstore.db?foreign_keys=on diff --git a/state/config.go b/state/config.go index aa21d9b..548f713 100644 --- a/state/config.go +++ b/state/config.go @@ -32,7 +32,7 @@ type Config struct { SendMyPresence bool `yaml:"send_my_presence"` SendMyReadReceipts bool `yaml:"send_my_read_receipts"` SilentConfirmation bool `yaml:"silent_confirmation"` - EmojiConfirmation bool `yaml:"emoji_confirmation"` + EmojiConfirmation bool `yaml:"emoji_confirmation"` } `yaml:"telegram"` WhatsApp struct { @@ -64,6 +64,7 @@ type Config struct { SendRevokedMessageUpdates bool `yaml:"send_revoked_message_updates"` WhatsmeowDebugMode bool `yaml:"whatsmeow_debug_mode"` SendMyMessagesFromOtherDevices bool `yaml:"send_my_messages_from_other_devices"` + CreateThreadForInfoUpdates bool `yaml:"create_thread_for_info_updates"` } `yaml:"whatsapp"` Database map[string]string `yaml:"database"` diff --git a/whatsapp/handlers.go b/whatsapp/handlers.go index c8f913e..b84b963 100644 --- a/whatsapp/handlers.go +++ b/whatsapp/handlers.go @@ -1306,10 +1306,21 @@ func PictureEventHandler(v *events.Picture) { "no thread found for a WhatsApp chat (handling Picture event)", zap.String("chat", v.JID.String()), ) - return + if !cfg.WhatsApp.CreateThreadForInfoUpdates { + return + } } if v.JID.Server == waTypes.GroupServer { + tgThreadId, err = utils.TgGetOrMakeThreadFromWa(v.JID.ToNonAD().String(), cfg.Telegram.TargetChatID, utils.WaGetGroupName(v.JID)) + if err != nil { + logger.Warn( + "failed to create a new thread for a WhatsApp chat (handling Picture event)", + zap.String("chat", v.JID.String()), + zap.Error(err), + ) + return + } changer := utils.WaGetContactName(v.Author) if v.Remove { updateText := fmt.Sprintf("The profile picture was removed by %s", html.EscapeString(changer)) @@ -1353,8 +1364,17 @@ func PictureEventHandler(v *events.Picture) { } } } else if v.JID.Server == waTypes.DefaultUserServer { + tgThreadId, err = utils.TgGetOrMakeThreadFromWa(v.JID.ToNonAD().String(), cfg.Telegram.TargetChatID, utils.WaGetContactName(v.JID.ToNonAD())) + if err != nil { + logger.Warn( + "failed to create a new thread for a WhatsApp chat (handling Picture event)", + zap.String("chat", v.JID.String()), + zap.Error(err), + ) + return + } if v.Remove { - updateText := fmt.Sprintf("The profile picture was removed") + updateText := "The profile picture was removed" err = utils.TgSendTextById( tgBot, cfg.Telegram.TargetChatID, tgThreadId, updateText, @@ -1424,7 +1444,19 @@ func GroupInfoEventHandler(v *events.GroupInfo) { "no thread found for a WhatsApp chat (handling GroupInfo event)", zap.String("chat", v.JID.String()), ) - return + if cfg.WhatsApp.CreateThreadForInfoUpdates { + tgThreadId, err = utils.TgGetOrMakeThreadFromWa(v.JID.ToNonAD().String(), cfg.Telegram.TargetChatID, utils.WaGetGroupName(v.JID)) + if err != nil { + logger.Warn( + "failed to create a new thread for a WhatsApp chat (handling GroupInfo event)", + zap.String("chat", v.JID.String()), + zap.Error(err), + ) + return + } + } else { + return + } } if v.Announce != nil {