Skip to content

Commit d05ba26

Browse files
committed
feat: refactoring to support latest tbotapi and botsfw changes
1 parent baa1e2a commit d05ba26

File tree

7 files changed

+54
-23
lines changed

7 files changed

+54
-23
lines changed

go.mod

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@ go 1.24.3
99
//replace github.com/bots-go-framework/bots-fw-store => ../bots-fw-store
1010

1111
require (
12-
github.com/bots-go-framework/bots-api-telegram v0.13.2
13-
github.com/bots-go-framework/bots-fw v0.68.0
12+
github.com/bots-go-framework/bots-api-telegram v0.14.0
13+
github.com/bots-go-framework/bots-fw v0.70.0
1414
github.com/bots-go-framework/bots-fw-store v0.10.0
1515
github.com/bots-go-framework/bots-fw-telegram-models v0.3.26
1616
github.com/bots-go-framework/bots-go-core v0.2.1
@@ -22,7 +22,7 @@ require (
2222

2323
require (
2424
github.com/alexsergivan/transliterator v1.0.1 // indirect
25-
github.com/strongo/analytics v0.0.11 // indirect
25+
github.com/strongo/analytics v0.2.1 // indirect
2626
github.com/strongo/random v0.0.1 // indirect
2727
github.com/strongo/slice v0.3.1 // indirect
2828
github.com/strongo/strongoapp v0.31.7 // indirect

go.sum

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
github.com/alexsergivan/transliterator v1.0.1 h1:vON2ilWCHjq+S5Y4obhLGhHK4Y1VIhsHEtQlij5d9pI=
22
github.com/alexsergivan/transliterator v1.0.1/go.mod h1:0IrumukulURJ4PD0z6UcdJKP2job1DYDhnHAP5y+5pE=
3-
github.com/bots-go-framework/bots-api-telegram v0.13.2 h1:s8BbyeLY2+U8tz7JqNb+c/4QE0JC1d01LywjNX9hkWg=
4-
github.com/bots-go-framework/bots-api-telegram v0.13.2/go.mod h1:/HcUOCL75qOKP2l2mk+o0FSfp86r6Zto5L/voN8rvPo=
5-
github.com/bots-go-framework/bots-fw v0.68.0 h1:p6EhXptWcRZInfZ0Dzey3e27PjdKI6+f5P77gs31JAM=
6-
github.com/bots-go-framework/bots-fw v0.68.0/go.mod h1:lGsoeShOymf7Pe6FCQmDuPjuGQ4+6ouHbUF3mRZ/u2I=
3+
github.com/bots-go-framework/bots-api-telegram v0.14.0 h1:t4/Jvf+N+nU/LqG3GebIcSmQk8T0Vmdl+Nzi0QkdvhM=
4+
github.com/bots-go-framework/bots-api-telegram v0.14.0/go.mod h1:/HcUOCL75qOKP2l2mk+o0FSfp86r6Zto5L/voN8rvPo=
5+
github.com/bots-go-framework/bots-fw v0.70.0 h1:QM32CYH6Jwu/AqbqyQELqwoAfDe2oeQQkzJECiCfLXQ=
6+
github.com/bots-go-framework/bots-fw v0.70.0/go.mod h1:T6EyFubSt3ZJbIosiL8b11YE4PGqTWGu47TPLSGTT2U=
77
github.com/bots-go-framework/bots-fw-store v0.10.0 h1:e6bD274mjrHVp+X05/7uqqT3s5xZOqV9divKTaM2W+w=
88
github.com/bots-go-framework/bots-fw-store v0.10.0/go.mod h1:7oU4B8j5HuJZM8AftosbyQD+AqckXsDv8eU1auGPzn8=
99
github.com/bots-go-framework/bots-fw-telegram-models v0.3.26 h1:J6mdMcrouCB0yjzDMFhVJxnB2epnnltC+iyTtISL27c=
@@ -21,8 +21,8 @@ github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+
2121
github.com/stretchr/testify v1.5.1/go.mod h1:5W2xD1RspED5o8YsWQXVCued0rvSQ+mT+I5cxcmMvtA=
2222
github.com/stretchr/testify v1.10.0 h1:Xv5erBjTwe/5IxqUQTdXv5kgmIvbHo3QQyRwhJsOfJA=
2323
github.com/stretchr/testify v1.10.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY=
24-
github.com/strongo/analytics v0.0.11 h1:rgORqeYRf1kXkJOBX+7UO5Op2ulcc5jkp7fbUC5+ANM=
25-
github.com/strongo/analytics v0.0.11/go.mod h1:1OdiZI9/fPDN8ep1Pbz+F3UZPNbttUD7T1St15r760c=
24+
github.com/strongo/analytics v0.2.1 h1:PP/TMyE20QjfQjPY7S+bUbSgyd01f9ZUjeuniRsEvEE=
25+
github.com/strongo/analytics v0.2.1/go.mod h1:1OdiZI9/fPDN8ep1Pbz+F3UZPNbttUD7T1St15r760c=
2626
github.com/strongo/i18n v0.8.2 h1:tJxeajC6OLENFus2GQ/jZGDjFmd6lPQuhand9jD0Moc=
2727
github.com/strongo/i18n v0.8.2/go.mod h1:4jBQ4PJ3Uiri2Y+LHJ5/o1nB1H2ToddRW/yZXSOTUjE=
2828
github.com/strongo/logus v0.2.1 h1:ZzAtdSg6PPF1Y43WbNWl7MH1XYl7kvKMxyxv/lpbadI=

telegram/get_message_uid.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,6 @@ func GetMessageUID(whc botsfw.WebhookContext) (*ChatMessageUID, error) {
2020
if tgChatID, err = strconv.ParseInt(chatID, 10, 64); err != nil {
2121
return nil, err
2222
}
23-
messageID := whc.Input().(TgWebhookCallbackQuery).GetMessage().IntID()
24-
return NewChatMessageUID(tgChatID, int(messageID)), nil
23+
messageID := whc.Input().(TgWebhookCallbackQuery).GetMessage().MessageIntID()
24+
return NewChatMessageUID(tgChatID, messageID), nil
2525
}

telegram/webhook_callbackquery.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,10 @@ type TgWebhookCallbackQuery struct { // TODO: make non-exportable
2020
//message botsfw.WebhookMessage
2121
}
2222

23+
func (whi TgWebhookCallbackQuery) MessageIntID() int {
24+
return whi.update.CallbackQuery.Message.MessageID
25+
}
26+
2327
func (whi TgWebhookCallbackQuery) GetChatInstanceID() string {
2428
return whi.update.CallbackQuery.ChatInstance
2529
}

telegram/webhook_input.go

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -207,8 +207,28 @@ func (whi tgWebhookInput) GetTime() time.Time {
207207
return time.Time{}
208208
}
209209

210-
func (whi tgWebhookInput) StringID() string {
211-
return ""
210+
func (whi tgWebhookInput) MessageIntID() int {
211+
switch {
212+
case whi.update.CallbackQuery != nil:
213+
return whi.update.CallbackQuery.Message.MessageID
214+
case whi.update.Message != nil:
215+
return whi.update.Message.MessageID
216+
case whi.update.EditedMessage != nil:
217+
return whi.update.EditedMessage.MessageID
218+
case whi.update.ChannelPost != nil:
219+
return whi.update.ChannelPost.MessageID
220+
case whi.update.EditedChannelPost != nil:
221+
return whi.update.EditedChannelPost.MessageID
222+
}
223+
return 0
224+
}
225+
226+
func (whi tgWebhookInput) MessageStringID() string {
227+
messageID := whi.MessageIntID()
228+
if messageID == 0 {
229+
return ""
230+
}
231+
return strconv.Itoa(messageID)
212232
}
213233

214234
func (whi tgWebhookInput) TelegramChatID() int64 {

telegram/webhook_message.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,8 @@ type tgWebhookMessage struct {
1010
message *tgbotapi.Message // Can be either whi.update.Message or whi.update.CallbackQuery.Message
1111
}
1212

13-
func (whm tgWebhookMessage) IntID() int64 {
14-
return (int64)(whm.message.MessageID)
13+
func (whm tgWebhookMessage) IntID() int {
14+
return whm.message.MessageID
1515
}
1616

1717
func newTelegramWebhookMessage(input tgWebhookInput, message *tgbotapi.Message) tgWebhookMessage {

telegram/webhook_responder.go

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -234,8 +234,14 @@ func (r tgWebhookResponder) SendMessage(ctx context.Context, m botmsg.MessageFro
234234
case *botkb.MessageKeyboard:
235235
switch keyboard.KeyboardType() {
236236
case botkb.KeyboardTypeInline:
237-
kb := getTelegramInlineKeyboard(m.Keyboard)
238-
sendable = tgbotapi.NewEditMessageReplyMarkup(chatID, messageID, inlineMessageID, tgbotapi.NewInlineKeyboardMarkup(kb.InlineKeyboard...))
237+
kb := getTelegramKeyboard(m.Keyboard)
238+
inlineKbMarkup := kb.(*tgbotapi.InlineKeyboardMarkup)
239+
sendable = tgbotapi.NewEditMessageReplyMarkup(chatID, messageID, inlineMessageID, tgbotapi.NewInlineKeyboardMarkup(inlineKbMarkup.InlineKeyboard...))
240+
case botkb.KeyboardTypeBottom:
241+
kb := getTelegramKeyboard(m.Keyboard)
242+
msg := tgbotapi.NewMessage(chatID, m.Text)
243+
msg.ReplyMarkup = kb.(*tgbotapi.InlineKeyboardMarkup)
244+
sendable = msg
239245
default:
240246
err = fmt.Errorf("unknown keyboard type %T(%v)", keyboard.KeyboardType(), keyboard)
241247
return
@@ -246,7 +252,7 @@ func (r tgWebhookResponder) SendMessage(ctx context.Context, m botmsg.MessageFro
246252
editMessageTextConfig.ParseMode = parseMode()
247253
editMessageTextConfig.DisableWebPagePreview = m.DisableWebPagePreview
248254
if m.Keyboard != nil {
249-
editMessageTextConfig.ReplyMarkup = getTelegramInlineKeyboard(m.Keyboard)
255+
editMessageTextConfig.ReplyMarkup = getTelegramKeyboard(m.Keyboard).(*tgbotapi.InlineKeyboardMarkup)
250256
}
251257
sendable = editMessageTextConfig
252258
} else {
@@ -262,7 +268,7 @@ func (r tgWebhookResponder) SendMessage(ctx context.Context, m botmsg.MessageFro
262268
messageConfig.DisableWebPagePreview = m.DisableWebPagePreview
263269
messageConfig.DisableNotification = m.DisableNotification
264270
if m.Keyboard != nil {
265-
messageConfig.ReplyMarkup = getTelegramInlineKeyboard(m.Keyboard)
271+
messageConfig.ReplyMarkup = getTelegramKeyboard(m.Keyboard)
266272
}
267273

268274
messageConfig.ParseMode = parseMode()
@@ -313,7 +319,7 @@ func (r tgWebhookResponder) SendMessage(ctx context.Context, m botmsg.MessageFro
313319

314320
var message tgbotapi.Message
315321
message, err = r.sendOverHttps(ctx, sendable)
316-
return botsfw.OnMessageSentResponse{TelegramMessage: message}, err
322+
return botsfw.OnMessageSentResponse{Message: &message}, err
317323
default:
318324
panic(fmt.Sprintf("Unknown channel: %v", channel))
319325
}
@@ -345,10 +351,11 @@ func (r tgWebhookResponder) sendOverHttps(ctx context.Context, chattable tgbotap
345351
return
346352
}
347353

348-
func getTelegramInlineKeyboard(keyboard botkb.Keyboard) *tgbotapi.InlineKeyboardMarkup {
349-
switch kb := keyboard.(type) {
350-
case *tgbotapi.InlineKeyboardMarkup:
354+
func getTelegramKeyboard(keyboard botkb.Keyboard) tgbotapi.Keyboard {
355+
if kb, ok := keyboard.(tgbotapi.Keyboard); ok {
351356
return kb
357+
}
358+
switch kb := keyboard.(type) {
352359
case *botkb.MessageKeyboard:
353360
tgButtons := make([][]tgbotapi.InlineKeyboardButton, len(kb.Buttons))
354361
for i, buttons := range kb.Buttons {

0 commit comments

Comments
 (0)