Skip to content

Commit 76361d7

Browse files
committed
feat!(config): telegram.emoji_confirmation => telegram.confirmation_type
Replace telegram.emoji_confirmation with telegram.confirmation_type and add more confirmation type: "none" i.e. no confirmation
1 parent 04d59d1 commit 76361d7

File tree

5 files changed

+93
-173
lines changed

5 files changed

+93
-173
lines changed

main.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,14 @@ func main() {
3434
panic(fmt.Errorf("failed to load config file: %s", err))
3535
}
3636

37+
deprecatedOptions := state.GetDeprecatedConfigOptions(cfg)
38+
if deprecatedOptions != nil {
39+
fmt.Println("The following options have been deprecated/removed:")
40+
for num, opt := range deprecatedOptions {
41+
fmt.Printf("%d. %s: %s\n", num+1, opt.Name, opt.Description)
42+
}
43+
}
44+
3745
if cfg.Telegram.APIURL == "" {
3846
cfg.Telegram.APIURL = gotgbot.DefaultAPIURL
3947
}

sample_config.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ telegram:
2424
send_my_read_receipts: false # Setting this to true will mark all unread messages in a chat as read when you send a new message using Telegram
2525

2626
silent_confirmation: true # Send a silent "Successfully sent" message
27-
emoji_confirmation: true # Reacts to the message with a "👍" emoji instead of replying
27+
confirmation_type: "emoji" # Can have three values: "text", "emoji" or "none"
2828

2929
skip_startup_message: false # If set to true, then a message will NOT be sent to your Telegram DM when the bot starts
3030

state/config.go

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,8 @@ type Config struct {
3232
SendMyPresence bool `yaml:"send_my_presence"`
3333
SendMyReadReceipts bool `yaml:"send_my_read_receipts"`
3434
SilentConfirmation bool `yaml:"silent_confirmation"`
35-
EmojiConfirmation bool `yaml:"emoji_confirmation"`
35+
ConfirmationType string `yaml:"confirmation_type"`
36+
EmojiConfirmation *bool `yaml:"emoji_confirmation"`
3637
SkipStartupMessage bool `yaml:"skip_startup_message"`
3738
SpoilerViewOnce bool `yaml:"spoiler_as_viewonce"`
3839
Reactions bool `yaml:"reactions"`
@@ -123,9 +124,12 @@ func (cfg *Config) SaveConfig() error {
123124

124125
func (cfg *Config) SetDefaults() {
125126
cfg.TimeZone = "UTC"
127+
126128
cfg.WhatsApp.SessionName = "watgbridge"
127129
cfg.WhatsApp.LoginDatabase.Type = "sqlite3"
128130
cfg.WhatsApp.LoginDatabase.URL = "file:wawebstore.db?foreign_keys=on"
129131
cfg.WhatsApp.StickerMetadata.PackName = "WaTgBridge"
130132
cfg.WhatsApp.StickerMetadata.AuthorName = "WaTgBridge"
133+
134+
cfg.Telegram.ConfirmationType = "emoji"
131135
}

state/utils.go

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
package state
2+
3+
type DeprecatedOption struct {
4+
Name string
5+
Description string
6+
}
7+
8+
func GetDeprecatedConfigOptions(cfg *Config) []DeprecatedOption {
9+
10+
returnValue := []DeprecatedOption{}
11+
12+
if cfg.Telegram.EmojiConfirmation != nil {
13+
returnValue = append(returnValue, DeprecatedOption{
14+
Name: "[telegram.emoji_confirmation]",
15+
Description: "It has been replaced with [telegram.confirmation_type]",
16+
})
17+
18+
if *cfg.Telegram.EmojiConfirmation {
19+
cfg.Telegram.ConfirmationType = "emoji"
20+
} else {
21+
cfg.Telegram.ConfirmationType = "text"
22+
}
23+
cfg.Telegram.EmojiConfirmation = nil
24+
25+
cfg.SaveConfig()
26+
}
27+
28+
if len(returnValue) > 0 {
29+
return returnValue
30+
} else {
31+
return nil
32+
}
33+
}

utils/telegram.go

Lines changed: 46 additions & 171 deletions
Original file line numberDiff line numberDiff line change
@@ -329,21 +329,7 @@ func TgSendToWhatsApp(b *gotgbot.Bot, c *ext.Context,
329329
return TgReplyWithErrorByContext(b, c, "Failed to send image to WhatsApp", err)
330330
}
331331
revokeKeyboard := TgMakeRevokeKeyboard(sentMsg.ID, waChatJID.String(), false)
332-
if cfg.Telegram.EmojiConfirmation {
333-
b.SetMessageReaction(
334-
msgToForward.Chat.Id,
335-
msgToForward.MessageId,
336-
&gotgbot.SetMessageReactionOpts{Reaction: []gotgbot.ReactionType{gotgbot.ReactionTypeEmoji{Emoji: "👍"}}},
337-
)
338-
} else {
339-
msg, err := TgReplyTextByContext(b, c, "Successfully sent", revokeKeyboard, cfg.Telegram.SilentConfirmation)
340-
if err == nil {
341-
go func(_b *gotgbot.Bot, _m *gotgbot.Message) {
342-
time.Sleep(15 * time.Second)
343-
_b.DeleteMessage(_m.Chat.Id, _m.MessageId, &gotgbot.DeleteMessageOpts{})
344-
}(b, msg)
345-
}
346-
}
332+
SendMessageConfirmation(b, c, cfg, msgToForward, revokeKeyboard)
347333

348334
err = database.MsgIdAddNewPair(sentMsg.ID, waClient.Store.ID.String(), waChatJID.String(),
349335
cfg.Telegram.TargetChatID, msgToForward.MessageId, msgToForward.MessageThreadId)
@@ -412,21 +398,7 @@ func TgSendToWhatsApp(b *gotgbot.Bot, c *ext.Context,
412398
return TgReplyWithErrorByContext(b, c, "Failed to send video to WhatsApp", err)
413399
}
414400
revokeKeyboard := TgMakeRevokeKeyboard(sentMsg.ID, waChatJID.String(), false)
415-
if cfg.Telegram.EmojiConfirmation {
416-
b.SetMessageReaction(
417-
msgToForward.Chat.Id,
418-
msgToForward.MessageId,
419-
&gotgbot.SetMessageReactionOpts{Reaction: []gotgbot.ReactionType{gotgbot.ReactionTypeEmoji{Emoji: "👍"}}},
420-
)
421-
} else {
422-
msg, err := TgReplyTextByContext(b, c, "Successfully sent", revokeKeyboard, cfg.Telegram.SilentConfirmation)
423-
if err == nil {
424-
go func(_b *gotgbot.Bot, _m *gotgbot.Message) {
425-
time.Sleep(15 * time.Second)
426-
_b.DeleteMessage(_m.Chat.Id, _m.MessageId, &gotgbot.DeleteMessageOpts{})
427-
}(b, msg)
428-
}
429-
}
401+
SendMessageConfirmation(b, c, cfg, msgToForward, revokeKeyboard)
430402

431403
err = database.MsgIdAddNewPair(sentMsg.ID, waClient.Store.ID.String(), waChatJID.String(),
432404
cfg.Telegram.TargetChatID, msgToForward.MessageId, msgToForward.MessageThreadId)
@@ -492,21 +464,7 @@ func TgSendToWhatsApp(b *gotgbot.Bot, c *ext.Context,
492464
return TgReplyWithErrorByContext(b, c, "Failed to send video note to WhatsApp", err)
493465
}
494466
revokeKeyboard := TgMakeRevokeKeyboard(sentMsg.ID, waChatJID.String(), false)
495-
if cfg.Telegram.EmojiConfirmation {
496-
b.SetMessageReaction(
497-
msgToForward.Chat.Id,
498-
msgToForward.MessageId,
499-
&gotgbot.SetMessageReactionOpts{Reaction: []gotgbot.ReactionType{gotgbot.ReactionTypeEmoji{Emoji: "👍"}}},
500-
)
501-
} else {
502-
msg, err := TgReplyTextByContext(b, c, "Successfully sent", revokeKeyboard, cfg.Telegram.SilentConfirmation)
503-
if err == nil {
504-
go func(_b *gotgbot.Bot, _m *gotgbot.Message) {
505-
time.Sleep(15 * time.Second)
506-
_b.DeleteMessage(_m.Chat.Id, _m.MessageId, &gotgbot.DeleteMessageOpts{})
507-
}(b, msg)
508-
}
509-
}
467+
SendMessageConfirmation(b, c, cfg, msgToForward, revokeKeyboard)
510468

511469
err = database.MsgIdAddNewPair(sentMsg.ID, waClient.Store.ID.String(), waChatJID.String(),
512470
cfg.Telegram.TargetChatID, msgToForward.MessageId, msgToForward.MessageThreadId)
@@ -575,21 +533,7 @@ func TgSendToWhatsApp(b *gotgbot.Bot, c *ext.Context,
575533
return TgReplyWithErrorByContext(b, c, "Failed to send animation to WhatsApp", err)
576534
}
577535
revokeKeyboard := TgMakeRevokeKeyboard(sentMsg.ID, waChatJID.String(), false)
578-
if cfg.Telegram.EmojiConfirmation {
579-
b.SetMessageReaction(
580-
msgToForward.Chat.Id,
581-
msgToForward.MessageId,
582-
&gotgbot.SetMessageReactionOpts{Reaction: []gotgbot.ReactionType{gotgbot.ReactionTypeEmoji{Emoji: "👍"}}},
583-
)
584-
} else {
585-
msg, err := TgReplyTextByContext(b, c, "Successfully sent", revokeKeyboard, cfg.Telegram.SilentConfirmation)
586-
if err == nil {
587-
go func(_b *gotgbot.Bot, _m *gotgbot.Message) {
588-
time.Sleep(15 * time.Second)
589-
_b.DeleteMessage(_m.Chat.Id, _m.MessageId, &gotgbot.DeleteMessageOpts{})
590-
}(b, msg)
591-
}
592-
}
536+
SendMessageConfirmation(b, c, cfg, msgToForward, revokeKeyboard)
593537

594538
err = database.MsgIdAddNewPair(sentMsg.ID, waClient.Store.ID.String(), waChatJID.String(),
595539
cfg.Telegram.TargetChatID, msgToForward.MessageId, msgToForward.MessageThreadId)
@@ -653,21 +597,7 @@ func TgSendToWhatsApp(b *gotgbot.Bot, c *ext.Context,
653597
return TgReplyWithErrorByContext(b, c, "Failed to send audio to WhatsApp", err)
654598
}
655599
revokeKeyboard := TgMakeRevokeKeyboard(sentMsg.ID, waChatJID.String(), false)
656-
if cfg.Telegram.EmojiConfirmation {
657-
b.SetMessageReaction(
658-
msgToForward.Chat.Id,
659-
msgToForward.MessageId,
660-
&gotgbot.SetMessageReactionOpts{Reaction: []gotgbot.ReactionType{gotgbot.ReactionTypeEmoji{Emoji: "👍"}}},
661-
)
662-
} else {
663-
msg, err := TgReplyTextByContext(b, c, "Successfully sent", revokeKeyboard, cfg.Telegram.SilentConfirmation)
664-
if err == nil {
665-
go func(_b *gotgbot.Bot, _m *gotgbot.Message) {
666-
time.Sleep(15 * time.Second)
667-
_b.DeleteMessage(_m.Chat.Id, _m.MessageId, &gotgbot.DeleteMessageOpts{})
668-
}(b, msg)
669-
}
670-
}
600+
SendMessageConfirmation(b, c, cfg, msgToForward, revokeKeyboard)
671601

672602
err = database.MsgIdAddNewPair(sentMsg.ID, waClient.Store.ID.String(), waChatJID.String(),
673603
cfg.Telegram.TargetChatID, msgToForward.MessageId, msgToForward.MessageThreadId)
@@ -731,21 +661,7 @@ func TgSendToWhatsApp(b *gotgbot.Bot, c *ext.Context,
731661
return TgReplyWithErrorByContext(b, c, "Failed to send voice to WhatsApp", err)
732662
}
733663
revokeKeyboard := TgMakeRevokeKeyboard(sentMsg.ID, waChatJID.String(), false)
734-
if cfg.Telegram.EmojiConfirmation {
735-
b.SetMessageReaction(
736-
msgToForward.Chat.Id,
737-
msgToForward.MessageId,
738-
&gotgbot.SetMessageReactionOpts{Reaction: []gotgbot.ReactionType{gotgbot.ReactionTypeEmoji{Emoji: "👍"}}},
739-
)
740-
} else {
741-
msg, err := TgReplyTextByContext(b, c, "Successfully sent", revokeKeyboard, cfg.Telegram.SilentConfirmation)
742-
if err == nil {
743-
go func(_b *gotgbot.Bot, _m *gotgbot.Message) {
744-
time.Sleep(15 * time.Second)
745-
_b.DeleteMessage(_m.Chat.Id, _m.MessageId, &gotgbot.DeleteMessageOpts{})
746-
}(b, msg)
747-
}
748-
}
664+
SendMessageConfirmation(b, c, cfg, msgToForward, revokeKeyboard)
749665

750666
err = database.MsgIdAddNewPair(sentMsg.ID, waClient.Store.ID.String(), waChatJID.String(),
751667
cfg.Telegram.TargetChatID, msgToForward.MessageId, msgToForward.MessageThreadId)
@@ -810,21 +726,7 @@ func TgSendToWhatsApp(b *gotgbot.Bot, c *ext.Context,
810726
return TgReplyWithErrorByContext(b, c, "Failed to send document to WhatsApp", err)
811727
}
812728
revokeKeyboard := TgMakeRevokeKeyboard(sentMsg.ID, waChatJID.String(), false)
813-
if cfg.Telegram.EmojiConfirmation {
814-
b.SetMessageReaction(
815-
msgToForward.Chat.Id,
816-
msgToForward.MessageId,
817-
&gotgbot.SetMessageReactionOpts{Reaction: []gotgbot.ReactionType{gotgbot.ReactionTypeEmoji{Emoji: "👍"}}},
818-
)
819-
} else {
820-
msg, err := TgReplyTextByContext(b, c, "Successfully sent", revokeKeyboard, cfg.Telegram.SilentConfirmation)
821-
if err == nil {
822-
go func(_b *gotgbot.Bot, _m *gotgbot.Message) {
823-
time.Sleep(15 * time.Second)
824-
_b.DeleteMessage(_m.Chat.Id, _m.MessageId, &gotgbot.DeleteMessageOpts{})
825-
}(b, msg)
826-
}
827-
}
729+
SendMessageConfirmation(b, c, cfg, msgToForward, revokeKeyboard)
828730

829731
err = database.MsgIdAddNewPair(sentMsg.ID, waClient.Store.ID.String(), waChatJID.String(),
830732
cfg.Telegram.TargetChatID, msgToForward.MessageId, msgToForward.MessageThreadId)
@@ -929,21 +831,7 @@ func TgSendToWhatsApp(b *gotgbot.Bot, c *ext.Context,
929831
return TgReplyWithErrorByContext(b, c, "Failed to send sticker to WhatsApp", err)
930832
}
931833
revokeKeyboard := TgMakeRevokeKeyboard(sentMsg.ID, waChatJID.String(), false)
932-
if cfg.Telegram.EmojiConfirmation {
933-
b.SetMessageReaction(
934-
msgToForward.Chat.Id,
935-
msgToForward.MessageId,
936-
&gotgbot.SetMessageReactionOpts{Reaction: []gotgbot.ReactionType{gotgbot.ReactionTypeEmoji{Emoji: "👍"}}},
937-
)
938-
} else {
939-
msg, err := TgReplyTextByContext(b, c, "Successfully sent", revokeKeyboard, cfg.Telegram.SilentConfirmation)
940-
if err == nil {
941-
go func(_b *gotgbot.Bot, _m *gotgbot.Message) {
942-
time.Sleep(15 * time.Second)
943-
_b.DeleteMessage(_m.Chat.Id, _m.MessageId, &gotgbot.DeleteMessageOpts{})
944-
}(b, msg)
945-
}
946-
}
834+
SendMessageConfirmation(b, c, cfg, msgToForward, revokeKeyboard)
947835

948836
err = database.MsgIdAddNewPair(sentMsg.ID, waClient.Store.ID.String(), waChatJID.String(),
949837
cfg.Telegram.TargetChatID, msgToForward.MessageId, msgToForward.MessageThreadId)
@@ -1006,21 +894,7 @@ func TgSendToWhatsApp(b *gotgbot.Bot, c *ext.Context,
1006894
return TgReplyWithErrorByContext(b, c, "Failed to send sticker to WhatsApp", err)
1007895
}
1008896
revokeKeyboard := TgMakeRevokeKeyboard(sentMsg.ID, waChatJID.String(), false)
1009-
if cfg.Telegram.EmojiConfirmation {
1010-
b.SetMessageReaction(
1011-
msgToForward.Chat.Id,
1012-
msgToForward.MessageId,
1013-
&gotgbot.SetMessageReactionOpts{Reaction: []gotgbot.ReactionType{gotgbot.ReactionTypeEmoji{Emoji: "👍"}}},
1014-
)
1015-
} else {
1016-
msg, err := TgReplyTextByContext(b, c, "Successfully sent", revokeKeyboard, cfg.Telegram.SilentConfirmation)
1017-
if err == nil {
1018-
go func(_b *gotgbot.Bot, _m *gotgbot.Message) {
1019-
time.Sleep(15 * time.Second)
1020-
_b.DeleteMessage(_m.Chat.Id, _m.MessageId, &gotgbot.DeleteMessageOpts{})
1021-
}(b, msg)
1022-
}
1023-
}
897+
SendMessageConfirmation(b, c, cfg, msgToForward, revokeKeyboard)
1024898

1025899
err = database.MsgIdAddNewPair(sentMsg.ID, waClient.Store.ID.String(), waChatJID.String(),
1026900
cfg.Telegram.TargetChatID, msgToForward.MessageId, msgToForward.MessageThreadId)
@@ -1074,21 +948,7 @@ func TgSendToWhatsApp(b *gotgbot.Bot, c *ext.Context,
1074948
return TgReplyWithErrorByContext(b, c, "Failed to send sticker to WhatsApp", err)
1075949
}
1076950
revokeKeyboard := TgMakeRevokeKeyboard(sentMsg.ID, waChatJID.String(), false)
1077-
if cfg.Telegram.EmojiConfirmation {
1078-
b.SetMessageReaction(
1079-
msgToForward.Chat.Id,
1080-
msgToForward.MessageId,
1081-
&gotgbot.SetMessageReactionOpts{Reaction: []gotgbot.ReactionType{gotgbot.ReactionTypeEmoji{Emoji: "👍"}}},
1082-
)
1083-
} else {
1084-
msg, err := TgReplyTextByContext(b, c, "Successfully sent", revokeKeyboard, cfg.Telegram.SilentConfirmation)
1085-
if err == nil {
1086-
go func(_b *gotgbot.Bot, _m *gotgbot.Message) {
1087-
time.Sleep(15 * time.Second)
1088-
_b.DeleteMessage(_m.Chat.Id, _m.MessageId, &gotgbot.DeleteMessageOpts{})
1089-
}(b, msg)
1090-
}
1091-
}
951+
SendMessageConfirmation(b, c, cfg, msgToForward, revokeKeyboard)
1092952

1093953
err = database.MsgIdAddNewPair(sentMsg.ID, waClient.Store.ID.String(), waChatJID.String(),
1094954
cfg.Telegram.TargetChatID, msgToForward.MessageId, msgToForward.MessageThreadId)
@@ -1113,12 +973,16 @@ func TgSendToWhatsApp(b *gotgbot.Bot, c *ext.Context,
1113973
if err != nil {
1114974
return TgReplyWithErrorByContext(b, c, "Failed to send reaction to WhatsApp", err)
1115975
}
1116-
msg, err := TgReplyTextByContext(b, c, "Successfully reacted", nil, cfg.Telegram.SilentConfirmation)
1117-
if err == nil {
1118-
go func(_b *gotgbot.Bot, _m *gotgbot.Message) {
1119-
time.Sleep(15 * time.Second)
1120-
_b.DeleteMessage(_m.Chat.Id, _m.MessageId, &gotgbot.DeleteMessageOpts{})
1121-
}(b, msg)
976+
if cfg.Telegram.ConfirmationType != "none" {
977+
msg, err := TgReplyTextByContext(b, c, "Successfully reacted", nil, cfg.Telegram.SilentConfirmation)
978+
979+
if err == nil {
980+
go func(_b *gotgbot.Bot, _m *gotgbot.Message) {
981+
time.Sleep(15 * time.Second)
982+
_b.DeleteMessage(_m.Chat.Id, _m.MessageId, &gotgbot.DeleteMessageOpts{})
983+
}(b, msg)
984+
}
985+
return err
1122986
}
1123987
return err
1124988
}
@@ -1148,21 +1012,7 @@ func TgSendToWhatsApp(b *gotgbot.Bot, c *ext.Context,
11481012
return TgReplyWithErrorByContext(b, c, "Failed to send message to WhatsApp", err)
11491013
}
11501014
revokeKeyboard := TgMakeRevokeKeyboard(sentMsg.ID, waChatJID.String(), false)
1151-
if cfg.Telegram.EmojiConfirmation {
1152-
b.SetMessageReaction(
1153-
msgToForward.Chat.Id,
1154-
msgToForward.MessageId,
1155-
&gotgbot.SetMessageReactionOpts{Reaction: []gotgbot.ReactionType{gotgbot.ReactionTypeEmoji{Emoji: "👍"}}},
1156-
)
1157-
} else {
1158-
msg, err := TgReplyTextByContext(b, c, "Successfully sent", revokeKeyboard, cfg.Telegram.SilentConfirmation)
1159-
if err == nil {
1160-
go func(_b *gotgbot.Bot, _m *gotgbot.Message) {
1161-
time.Sleep(15 * time.Second)
1162-
_b.DeleteMessage(_m.Chat.Id, _m.MessageId, &gotgbot.DeleteMessageOpts{})
1163-
}(b, msg)
1164-
}
1165-
}
1015+
SendMessageConfirmation(b, c, cfg, msgToForward, revokeKeyboard)
11661016

11671017
err = database.MsgIdAddNewPair(sentMsg.ID, waClient.Store.ID.String(), waChatJID.String(),
11681018
cfg.Telegram.TargetChatID, msgToForward.MessageId, msgToForward.MessageThreadId)
@@ -1241,3 +1091,28 @@ func TgBuildUrlButton(text, url string) gotgbot.InlineKeyboardMarkup {
12411091
}}},
12421092
}
12431093
}
1094+
1095+
func SendMessageConfirmation(
1096+
b *gotgbot.Bot,
1097+
c *ext.Context,
1098+
cfg *state.Config,
1099+
msgToForward *gotgbot.Message,
1100+
revokeKeyboard *gotgbot.InlineKeyboardMarkup,
1101+
) {
1102+
switch cfg.Telegram.ConfirmationType {
1103+
case "emoji":
1104+
b.SetMessageReaction(
1105+
msgToForward.Chat.Id,
1106+
msgToForward.MessageId,
1107+
&gotgbot.SetMessageReactionOpts{Reaction: []gotgbot.ReactionType{gotgbot.ReactionTypeEmoji{Emoji: "👍"}}},
1108+
)
1109+
case "text":
1110+
msg, err := TgReplyTextByContext(b, c, "Successfully sent", revokeKeyboard, cfg.Telegram.SilentConfirmation)
1111+
if err == nil {
1112+
go func(_b *gotgbot.Bot, _m *gotgbot.Message) {
1113+
time.Sleep(15 * time.Second)
1114+
_b.DeleteMessage(_m.Chat.Id, _m.MessageId, &gotgbot.DeleteMessageOpts{})
1115+
}(b, msg)
1116+
}
1117+
}
1118+
}

0 commit comments

Comments
 (0)