@@ -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