@@ -18,7 +18,7 @@ import (
18
18
"go.uber.org/zap"
19
19
)
20
20
21
- func (s * Service ) processOutput (info types.TaskInfo , result * smr.URLSummarizationOutput ) string {
21
+ func (s * Service ) formatOutput (info types.TaskInfo , result * smr.URLSummarizationOutput ) string {
22
22
switch info .Platform {
23
23
case bot .FromPlatformTelegram :
24
24
return result .FormatSummarizationAsHTML ()
@@ -31,7 +31,7 @@ func (s *Service) processOutput(info types.TaskInfo, result *smr.URLSummarizatio
31
31
}
32
32
}
33
33
34
- func (s * Service ) processError (err error , language string ) string {
34
+ func (s * Service ) formatError (err error , language string ) string {
35
35
if errors .Is (err , smr .ErrContentNotSupported ) {
36
36
return s .i18n .TWithLanguage (language , "commands.groups.summarization.commands.smr.contentNotSupported" )
37
37
} else if errors .Is (err , smr .ErrNetworkError ) || errors .Is (err , smr .ErrRequestFailed ) {
@@ -41,7 +41,22 @@ func (s *Service) processError(err error, language string) string {
41
41
return s .i18n .TWithLanguage (language , "commands.groups.summarization.commands.smr.failedToRead" )
42
42
}
43
43
44
- func (s * Service ) sendResult (output * smr.URLSummarizationOutput , info types.TaskInfo , result string ) {
44
+ func (s * Service ) newRetryButtonMarkup (info types.TaskInfo ) (tgbotapi.InlineKeyboardMarkup , error ) {
45
+ data , err := s .tgBot .Bot ().AssignOneCallbackQueryData ("smr/summarization/retry" , & info )
46
+
47
+ if err != nil {
48
+ return tgbotapi.InlineKeyboardMarkup {}, err
49
+ }
50
+
51
+ return tgbotapi .NewInlineKeyboardMarkup ([]tgbotapi.InlineKeyboardButton {
52
+ {
53
+ Text : s .i18n .TWithLanguage (info .Language , "commands.groups.summarization.commands.smr.retry" ),
54
+ CallbackData : & data ,
55
+ },
56
+ }), nil
57
+ }
58
+
59
+ func (s * Service ) sendResult (output * smr.URLSummarizationOutput , info types.TaskInfo , result string , provideRetryButton bool ) {
45
60
switch info .Platform {
46
61
case bot .FromPlatformTelegram :
47
62
msgEdit := tgbotapi.EditMessageTextConfig {
@@ -53,6 +68,23 @@ func (s *Service) sendResult(output *smr.URLSummarizationOutput, info types.Task
53
68
ParseMode : tgbotapi .ModeHTML ,
54
69
}
55
70
71
+ if provideRetryButton {
72
+ var err error
73
+ retryButtonMarkup , err := s .newRetryButtonMarkup (info )
74
+
75
+ if err != nil {
76
+ s .logger .Error ("smr service: failed to create retry button markup" ,
77
+ zap .Error (err ),
78
+ zap .Int64 ("chat_id" , info .ChatID ),
79
+ zap .String ("platform" , info .Platform .String ()),
80
+ )
81
+
82
+ return
83
+ }
84
+
85
+ msgEdit .ReplyMarkup = & retryButtonMarkup
86
+ }
87
+
56
88
if output == nil {
57
89
_ , err := s .tgBot .Send (msgEdit )
58
90
if err != nil {
@@ -99,6 +131,7 @@ func (s *Service) sendResult(output *smr.URLSummarizationOutput, info types.Task
99
131
)
100
132
}
101
133
case bot .FromPlatformSlack :
134
+ // TODO: provide retry button
102
135
token , err := s .ent .SlackOAuthCredentials .Query ().
103
136
Where (slackoauthcredentials .TeamID (info .TeamID )).
104
137
First (context .Background ())
@@ -127,6 +160,7 @@ func (s *Service) sendResult(output *smr.URLSummarizationOutput, info types.Task
127
160
)
128
161
}
129
162
case bot .FromPlatformDiscord :
163
+ // TODO: provide retry button
130
164
channelID , _ := snowflake .Parse (info .ChannelID )
131
165
_ , err := s .discordBot .Rest ().
132
166
CreateMessage (channelID , discord .NewMessageCreateBuilder ().
@@ -174,12 +208,12 @@ func (s *Service) processor(info types.TaskInfo) {
174
208
smrResult , err := s .model .SummarizeInputURL (ctx , info .URL , info .Platform )
175
209
if err != nil {
176
210
s .logger .Warn ("smr service: summarization failed" , zap .Error (err ))
177
- errStr := s .processError (err , lo .Ternary (info .Language == "" , "en" , info .Language ))
178
- s .sendResult (nil , info , errStr )
211
+ errStr := s .formatError (err , lo .Ternary (info .Language == "" , "en" , info .Language ))
212
+ s .sendResult (nil , info , errStr , ! errors . Is ( err , smr . ErrContentNotSupported ) )
179
213
180
214
return
181
215
}
182
216
183
- finalResult := s .processOutput (info , smrResult )
184
- s .sendResult (smrResult , info , finalResult )
217
+ finalResult := s .formatOutput (info , smrResult )
218
+ s .sendResult (smrResult , info , finalResult , false )
185
219
}
0 commit comments