Skip to content

Commit 2a3b79f

Browse files
committed
feat: send new message for button of price update notification
1 parent 7d0e3df commit 2a3b79f

3 files changed

Lines changed: 17 additions & 13 deletions

File tree

internal/bot/bot.go

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -179,12 +179,12 @@ func mainMenuHandler(b *gotgbot.Bot, ctx *ext.Context) error {
179179
func showPriceagentDetail(b *gotgbot.Bot, ctx *ext.Context) error {
180180
cb := ctx.Update.CallbackQuery
181181

182-
priceagentID, parseErr := parseIDFromCallbackData(cb.Data, "m03_00_")
182+
menu, parseErr := models.NewMenu(cb.Data)
183183
if parseErr != nil {
184-
return fmt.Errorf("showPriceagentDetail: failed to parse priceagentID from callback data: %w", parseErr)
184+
return fmt.Errorf("showPriceagentDetail: failed to parse callback data: %w", parseErr)
185185
}
186186

187-
priceagent, dbErr := database.GetPriceagentForUserByID(ctx.EffectiveUser.Id, priceagentID)
187+
priceagent, dbErr := database.GetPriceagentForUserByID(ctx.EffectiveUser.Id, menu.PriceAgent)
188188
if dbErr != nil {
189189
return fmt.Errorf("showPriceagentDetail: failed to get priceagent from database: %w", dbErr)
190190
}
@@ -220,21 +220,25 @@ func showPriceagentDetail(b *gotgbot.Bot, ctx *ext.Context) error {
220220
},
221221
}
222222

223-
// Check if the initial message contained a photo, if yes, we're coming from the price history graph
224-
if len(cb.Message.Photo) > 0 {
223+
switch menu.SubMenu {
224+
case "00":
225+
_, err := cb.Message.EditText(b, editedText, &gotgbot.EditMessageTextOpts{ReplyMarkup: markup, ParseMode: "HTML"})
226+
if err != nil {
227+
return fmt.Errorf("showPriceagent: failed to edit message text: %w", err)
228+
}
229+
case "01":
225230
bot.DeleteMessage(ctx.EffectiveChat.Id, cb.Message.MessageId)
226231

227232
_, err := b.SendMessage(ctx.EffectiveChat.Id, editedText, &gotgbot.SendMessageOpts{ReplyMarkup: markup, ParseMode: "HTML"})
228233
if err != nil {
229234
return fmt.Errorf("showPriceagent: failed to send new message: %w", err)
230235
}
231-
} else {
232-
_, err := cb.Message.EditText(b, editedText, &gotgbot.EditMessageTextOpts{ReplyMarkup: markup, ParseMode: "HTML"})
236+
case "02":
237+
_, err := b.SendMessage(ctx.EffectiveChat.Id, editedText, &gotgbot.SendMessageOpts{ReplyMarkup: markup, ParseMode: "HTML"})
233238
if err != nil {
234-
return fmt.Errorf("showPriceagent: failed to edit message text: %w", err)
239+
return fmt.Errorf("showPriceagent: failed to send new message: %w", err)
235240
}
236241
}
237-
238242
return nil
239243
}
240244

@@ -410,7 +414,7 @@ func addMessageHandlers(dispatcher *ext.Dispatcher) {
410414
dispatcher.AddHandler(handlers.NewCallback(callbackquery.Prefix("m04_02_"), setNotificationBelowHandler))
411415
dispatcher.AddHandler(handlers.NewCallback(callbackquery.Prefix("m04_01_"), setNotificationAlwaysHandler))
412416
dispatcher.AddHandler(handlers.NewCallback(callbackquery.Prefix("m04_00_"), changePriceagentSettingsHandler))
413-
dispatcher.AddHandler(handlers.NewCallback(callbackquery.Prefix("m03_00_"), showPriceagentDetail))
417+
dispatcher.AddHandler(handlers.NewCallback(callbackquery.Prefix("m03_"), showPriceagentDetail))
414418
dispatcher.AddHandler(handlers.NewCallback(callbackquery.Equal("m02_00"), showWishlistPriceagents))
415419
dispatcher.AddHandler(handlers.NewCallback(callbackquery.Equal("m02_01"), showProductPriceagents))
416420
dispatcher.AddHandler(handlers.NewCallback(callbackquery.Equal("m01_01"), viewPriceagentsHandler))

internal/bot/notification.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ func notifyUsers(priceAgent models.PriceAgent, oldEntity, updatedEntity geizhals
9090
markup := gotgbot.InlineKeyboardMarkup{
9191
InlineKeyboard: [][]gotgbot.InlineKeyboardButton{
9292
{
93-
{Text: "Zum Preisagenten!", CallbackData: fmt.Sprintf("m03_00_%d", priceAgent.ID)},
93+
{Text: "Zum Preisagenten!", CallbackData: fmt.Sprintf("m03_02_%d", priceAgent.ID)},
9494
},
9595
},
9696
}

internal/bot/pricehistory.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ func showPriceHistoryHandler(b *gotgbot.Bot, ctx *ext.Context) error {
3535
markup := gotgbot.InlineKeyboardMarkup{
3636
InlineKeyboard: [][]gotgbot.InlineKeyboardButton{
3737
dateRangeKeyboard,
38-
{{Text: "↩️ Zurück", CallbackData: fmt.Sprintf("m03_00_%d", priceagent.ID)}},
38+
{{Text: "↩️ Zurück", CallbackData: fmt.Sprintf("m03_01_%d", priceagent.ID)}},
3939
},
4040
}
4141

@@ -79,7 +79,7 @@ func updatePriceHistoryGraphHandler(b *gotgbot.Bot, ctx *ext.Context) error {
7979
markup := gotgbot.InlineKeyboardMarkup{
8080
InlineKeyboard: [][]gotgbot.InlineKeyboardButton{
8181
dateRangeKeyboard,
82-
{{Text: "↩️ Zurück", CallbackData: fmt.Sprintf("m03_00_%d", priceagent.ID)}},
82+
{{Text: "↩️ Zurück", CallbackData: fmt.Sprintf("m03_01_%d", priceagent.ID)}},
8383
},
8484
}
8585

0 commit comments

Comments
 (0)