Skip to content

Commit

Permalink
fixes for bot lib v1.0.1 with bot API v7.0
Browse files Browse the repository at this point in the history
  • Loading branch information
negasus committed Jan 19, 2024
1 parent 96bead6 commit a01a911
Show file tree
Hide file tree
Showing 17 changed files with 39 additions and 35 deletions.
16 changes: 8 additions & 8 deletions datepicker/callback.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ func (datePicker *DatePicker) callback(ctx context.Context, b *bot.Bot, update *
if datePicker.deleteOnSelect {
_, errDelete := b.DeleteMessage(ctx, &bot.DeleteMessageParams{
ChatID: update.CallbackQuery.Message.Chat.ID,
MessageID: update.CallbackQuery.Message.ID,
MessageID: update.CallbackQuery.Message.MessageID,
})
if errDelete != nil {
datePicker.onError(fmt.Errorf("failed to delete message onSelect: %w", errDelete))
Expand All @@ -64,7 +64,7 @@ func (datePicker *DatePicker) callback(ctx context.Context, b *bot.Bot, update *
if datePicker.deleteOnCancel {
_, errDelete := b.DeleteMessage(ctx, &bot.DeleteMessageParams{
ChatID: update.CallbackQuery.Message.Chat.ID,
MessageID: update.CallbackQuery.Message.ID,
MessageID: update.CallbackQuery.Message.MessageID,
})
if errDelete != nil {
datePicker.onError(fmt.Errorf("failed to delete message onCancel: %w", errDelete))
Expand Down Expand Up @@ -105,32 +105,32 @@ func (datePicker *DatePicker) callback(ctx context.Context, b *bot.Bot, update *
datePicker.callbackAnswer(ctx, b, update.CallbackQuery)
}

func (datePicker *DatePicker) showSelectMonth(ctx context.Context, b *bot.Bot, mes *models.Message) {
func (datePicker *DatePicker) showSelectMonth(ctx context.Context, b *bot.Bot, mes models.InaccessibleMessage) {
_, err := b.EditMessageReplyMarkup(ctx, &bot.EditMessageReplyMarkupParams{
ChatID: mes.Chat.ID,
MessageID: mes.ID,
MessageID: mes.MessageID,
ReplyMarkup: models.InlineKeyboardMarkup{InlineKeyboard: datePicker.buildMonthKeyboard()},
})
if err != nil {
datePicker.onError(fmt.Errorf("error edit message in showSelectMonth, %w", err))
}
}

func (datePicker *DatePicker) showSelectYear(ctx context.Context, b *bot.Bot, mes *models.Message, currentYear int) {
func (datePicker *DatePicker) showSelectYear(ctx context.Context, b *bot.Bot, mes models.InaccessibleMessage, currentYear int) {
_, err := b.EditMessageReplyMarkup(ctx, &bot.EditMessageReplyMarkupParams{
ChatID: mes.Chat.ID,
MessageID: mes.ID,
MessageID: mes.MessageID,
ReplyMarkup: models.InlineKeyboardMarkup{InlineKeyboard: datePicker.buildYearKeyboard(currentYear)},
})
if err != nil {
datePicker.onError(fmt.Errorf("error edit message in showSelectYear, %w", err))
}
}

func (datePicker *DatePicker) showMain(ctx context.Context, b *bot.Bot, mes *models.Message) {
func (datePicker *DatePicker) showMain(ctx context.Context, b *bot.Bot, mes models.InaccessibleMessage) {
_, err := b.EditMessageReplyMarkup(ctx, &bot.EditMessageReplyMarkupParams{
ChatID: mes.Chat.ID,
MessageID: mes.ID,
MessageID: mes.MessageID,
ReplyMarkup: models.InlineKeyboardMarkup{InlineKeyboard: datePicker.buildKeyboard()},
})
if err != nil {
Expand Down
6 changes: 3 additions & 3 deletions datepicker/datepicker.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@ const (
DateModeInclude
)

type OnSelectHandler func(ctx context.Context, bot *bot.Bot, mes *models.Message, date time.Time)
type OnCancelHandler func(ctx context.Context, bot *bot.Bot, mes *models.Message)
type OnSelectHandler func(ctx context.Context, bot *bot.Bot, mes models.InaccessibleMessage, date time.Time)
type OnCancelHandler func(ctx context.Context, bot *bot.Bot, mes models.InaccessibleMessage)
type OnErrorHandler func(err error)

type DatePicker struct {
Expand Down Expand Up @@ -80,4 +80,4 @@ func defaultOnError(err error) {
log.Printf("[TG-UI-DATEPICKER] [ERROR] %s", err)
}

func defaultOnCancel(_ context.Context, _ *bot.Bot, _ *models.Message) {}
func defaultOnCancel(_ context.Context, _ *bot.Bot, _ models.InaccessibleMessage) {}
2 changes: 1 addition & 1 deletion dialog/dialog.go
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ func (d *Dialog) callback(ctx context.Context, b *bot.Bot, update *models.Update
if d.inline {
_, errEdit := b.EditMessageText(ctx, &bot.EditMessageTextParams{
ChatID: update.CallbackQuery.Message.Chat.ID,
MessageID: update.CallbackQuery.Message.ID,
MessageID: update.CallbackQuery.Message.MessageID,
Text: node.Text,
ParseMode: models.ParseModeMarkdown,
ReplyMarkup: node.buildKB(d.prefix),
Expand Down
4 changes: 2 additions & 2 deletions examples/datepicker_custom.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,14 +41,14 @@ func handlerDatepickerCustom(ctx context.Context, b *bot.Bot, update *models.Upd
})
}

func onDatepickerCustomCancel(ctx context.Context, b *bot.Bot, mes *models.Message) {
func onDatepickerCustomCancel(ctx context.Context, b *bot.Bot, mes models.InaccessibleMessage) {
b.SendMessage(ctx, &bot.SendMessageParams{
ChatID: mes.Chat.ID,
Text: "Canceled",
})
}

func onDatepickerCustomSelect(ctx context.Context, b *bot.Bot, mes *models.Message, date time.Time) {
func onDatepickerCustomSelect(ctx context.Context, b *bot.Bot, mes models.InaccessibleMessage, date time.Time) {
b.SendMessage(ctx, &bot.SendMessageParams{
ChatID: mes.Chat.ID,
Text: "You select " + date.Format("2006-01-02"),
Expand Down
2 changes: 1 addition & 1 deletion examples/datepicker_simple.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ func handlerDatepickerSimple(ctx context.Context, b *bot.Bot, update *models.Upd
})
}

func onDatepickerSimpleSelect(ctx context.Context, b *bot.Bot, mes *models.Message, date time.Time) {
func onDatepickerSimpleSelect(ctx context.Context, b *bot.Bot, mes models.InaccessibleMessage, date time.Time) {
b.SendMessage(ctx, &bot.SendMessageParams{
ChatID: mes.Chat.ID,
Text: "You select " + date.Format("2006-01-02"),
Expand Down
2 changes: 1 addition & 1 deletion examples/inline_keyboard.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ func handlerInlineKeyboard(ctx context.Context, b *bot.Bot, update *models.Updat
})
}

func onInlineKeyboardSelect(ctx context.Context, b *bot.Bot, mes *models.Message, data []byte) {
func onInlineKeyboardSelect(ctx context.Context, b *bot.Bot, mes models.InaccessibleMessage, data []byte) {
b.SendMessage(ctx, &bot.SendMessageParams{
ChatID: mes.Chat.ID,
Text: "You selected: " + string(data),
Expand Down
10 changes: 6 additions & 4 deletions examples/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,9 +46,11 @@ func defaultHandler(ctx context.Context, b *bot.Bot, update *models.Update) {
return
}
b.SendMessage(ctx, &bot.SendMessageParams{
ChatID: update.Message.Chat.ID,
Text: defaultMessage,
ParseMode: models.ParseModeMarkdown,
DisableWebPagePreview: true,
ChatID: update.Message.Chat.ID,
Text: defaultMessage,
ParseMode: models.ParseModeMarkdown,
LinkPreviewOptions: &models.LinkPreviewOptions{
IsDisabled: bot.True(),
},
})
}
2 changes: 1 addition & 1 deletion examples/progress_custom.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import (
func handlerProgressCustom(ctx context.Context, b *bot.Bot, update *models.Update) {
cancelCtx, cancel := context.WithCancel(context.Background())

progressCancelFunc := func(ctx context.Context, b *bot.Bot, mes *models.Message) {
progressCancelFunc := func(ctx context.Context, b *bot.Bot, mes models.InaccessibleMessage) {
cancel()
b.SendMessage(ctx, &bot.SendMessageParams{
ChatID: mes.Chat.ID,
Expand Down
4 changes: 2 additions & 2 deletions examples/slider.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,14 +43,14 @@ func handlerSlider(ctx context.Context, b *bot.Bot, update *models.Update) {
sl.Show(ctx, b, update.Message.Chat.ID)
}

func sliderOnSelect(ctx context.Context, b *bot.Bot, message *models.Message, item int) {
func sliderOnSelect(ctx context.Context, b *bot.Bot, message models.InaccessibleMessage, item int) {
b.SendMessage(ctx, &bot.SendMessageParams{
ChatID: message.Chat.ID,
Text: "Select " + strconv.Itoa(item),
})
}

func sliderOnCancel(ctx context.Context, b *bot.Bot, message *models.Message) {
func sliderOnCancel(ctx context.Context, b *bot.Bot, message models.InaccessibleMessage) {
b.SendMessage(ctx, &bot.SendMessageParams{
ChatID: message.Chat.ID,
Text: "Cancel",
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@ module github.com/go-telegram/ui

go 1.20

require github.com/go-telegram/bot v0.8.0
require github.com/go-telegram/bot v1.0.1
2 changes: 2 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,5 @@ github.com/go-telegram/bot v0.7.13 h1:8VUBXtYwdh0skrCx6oORSrT0M9ZZaKIKIX3hC3XBs1
github.com/go-telegram/bot v0.7.13/go.mod h1:i2TRs7fXWIeaceF3z7KzsMt/he0TwkVC680mvdTFYeM=
github.com/go-telegram/bot v0.8.0 h1:LQZwaU5eqfXzeUIqDBOLrk6/Lu26zqwnBs5BOKQl7fU=
github.com/go-telegram/bot v0.8.0/go.mod h1:i2TRs7fXWIeaceF3z7KzsMt/he0TwkVC680mvdTFYeM=
github.com/go-telegram/bot v1.0.1 h1:Rxg5H6WLN36n1YWzw61O/+krbNM12E+d+BowkrFEcWA=
github.com/go-telegram/bot v1.0.1/go.mod h1:i2TRs7fXWIeaceF3z7KzsMt/he0TwkVC680mvdTFYeM=
2 changes: 1 addition & 1 deletion keyboard/inline/callback.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ func (kb *Keyboard) callback(ctx context.Context, b *bot.Bot, update *models.Upd

_, errDelete := b.DeleteMessage(ctx, &bot.DeleteMessageParams{
ChatID: update.CallbackQuery.Message.Chat.ID,
MessageID: update.CallbackQuery.Message.ID,
MessageID: update.CallbackQuery.Message.MessageID,
})
if errDelete != nil {
kb.onError(fmt.Errorf("error delete message in callback, %w", errDelete))
Expand Down
2 changes: 1 addition & 1 deletion keyboard/inline/keyboard.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import (
"github.com/go-telegram/bot/models"
)

type OnSelect func(ctx context.Context, bot *bot.Bot, mes *models.Message, data []byte)
type OnSelect func(ctx context.Context, bot *bot.Bot, mes models.InaccessibleMessage, data []byte)
type OnErrorHandler func(err error)

type handlerData struct {
Expand Down
4 changes: 2 additions & 2 deletions paginator/callback.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ func (p *Paginator) callback(ctx context.Context, b *bot.Bot, update *models.Upd

_, errDelete := b.DeleteMessage(ctx, &bot.DeleteMessageParams{
ChatID: update.CallbackQuery.Message.Chat.ID,
MessageID: update.CallbackQuery.Message.ID,
MessageID: update.CallbackQuery.Message.MessageID,
})
if errDelete != nil {
p.onError(errDelete)
Expand All @@ -61,7 +61,7 @@ func (p *Paginator) callback(ctx context.Context, b *bot.Bot, update *models.Upd

_, errEdit := b.EditMessageText(ctx, &bot.EditMessageTextParams{
ChatID: update.CallbackQuery.Message.Chat.ID,
MessageID: update.CallbackQuery.Message.ID,
MessageID: update.CallbackQuery.Message.MessageID,
InlineMessageID: update.CallbackQuery.InlineMessageID,
Text: p.buildText(),
ParseMode: models.ParseModeMarkdown,
Expand Down
4 changes: 2 additions & 2 deletions progress/progress.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import (
"github.com/go-telegram/bot/models"
)

type OnCancelFunc func(ctx context.Context, b *bot.Bot, message *models.Message)
type OnCancelFunc func(ctx context.Context, b *bot.Bot, message models.InaccessibleMessage)
type RenderTextFunc func(value float64) string
type OnErrorHandler func(err error)

Expand Down Expand Up @@ -101,7 +101,7 @@ func (p *Progress) onCancelCall(ctx context.Context, b *bot.Bot, update *models.
if p.deleteOnCancel {
_, err := b.DeleteMessage(ctx, &bot.DeleteMessageParams{
ChatID: update.CallbackQuery.Message.Chat.ID,
MessageID: update.CallbackQuery.Message.ID,
MessageID: update.CallbackQuery.Message.MessageID,
})
if err != nil {
p.onError(err)
Expand Down
6 changes: 3 additions & 3 deletions slider/callback.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ func (s *Slider) callback(ctx context.Context, b *bot.Bot, update *models.Update

_, errDelete := b.DeleteMessage(ctx, &bot.DeleteMessageParams{
ChatID: update.CallbackQuery.Message.Chat.ID,
MessageID: update.CallbackQuery.Message.ID,
MessageID: update.CallbackQuery.Message.MessageID,
})
if errDelete != nil {
s.onError(errDelete)
Expand All @@ -57,7 +57,7 @@ func (s *Slider) callback(ctx context.Context, b *bot.Bot, update *models.Update

_, errDelete := b.DeleteMessage(ctx, &bot.DeleteMessageParams{
ChatID: update.CallbackQuery.Message.Chat.ID,
MessageID: update.CallbackQuery.Message.ID,
MessageID: update.CallbackQuery.Message.MessageID,
})
if errDelete != nil {
s.onError(errDelete)
Expand All @@ -72,7 +72,7 @@ func (s *Slider) callback(ctx context.Context, b *bot.Bot, update *models.Update

editParams := &bot.EditMessageMediaParams{
ChatID: update.CallbackQuery.Message.Chat.ID,
MessageID: update.CallbackQuery.Message.ID,
MessageID: update.CallbackQuery.Message.MessageID,
Media: &models.InputMediaPhoto{
Media: slide.Photo,
Caption: slide.Text,
Expand Down
4 changes: 2 additions & 2 deletions slider/slider.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ import (
"github.com/go-telegram/bot/models"
)

type OnSelectFunc func(ctx context.Context, b *bot.Bot, message *models.Message, item int)
type OnCancelFunc func(ctx context.Context, b *bot.Bot, message *models.Message)
type OnSelectFunc func(ctx context.Context, b *bot.Bot, message models.InaccessibleMessage, item int)
type OnCancelFunc func(ctx context.Context, b *bot.Bot, message models.InaccessibleMessage)
type OnErrorFunc func(err error)

type Slide struct {
Expand Down

0 comments on commit a01a911

Please sign in to comment.