Added basic inline-buttons support.

This commit is contained in:
Andrey Parhomenko 2023-07-12 14:30:05 +03:00
parent 2935a7db99
commit 521709f87d
2 changed files with 13 additions and 7 deletions

View file

@ -2,7 +2,7 @@ package behx
import ( import (
apix "github.com/go-telegram-bot-api/telegram-bot-api/v5" apix "github.com/go-telegram-bot-api/telegram-bot-api/v5"
"fmt" //"fmt"
) )
// The type represents way to interact with user in // The type represents way to interact with user in
@ -20,10 +20,10 @@ func (ctx *Context) handleUpdateChan(updates chan *Update) {
for u := range updates { for u := range updates {
screen := bot.Screens[session.CurrentScreenId] screen := bot.Screens[session.CurrentScreenId]
kbd := bot.Keyboards[screen.KeyboardId]
btns := kbd.buttonMap()
if u.Message != nil { if u.Message != nil {
kbd := bot.Keyboards[screen.KeyboardId]
btns := kbd.buttonMap()
text := u.Message.Text text := u.Message.Text
btn, ok := btns[text] btn, ok := btns[text]
@ -35,11 +35,16 @@ func (ctx *Context) handleUpdateChan(updates chan *Update) {
btn.Action.Act(ctx) btn.Action.Act(ctx)
} else if u.CallbackQuery != nil { } else if u.CallbackQuery != nil {
cb := apix.NewCallback(u.CallbackQuery.ID, u.CallbackQuery.Data) cb := apix.NewCallback(u.CallbackQuery.ID, u.CallbackQuery.Data)
data := u.CallbackQuery.Data
_, err := bot.Request(cb) _, err := bot.Request(cb)
if err != nil { if err != nil {
panic(err) panic(err)
} }
kbd := bot.Keyboards[screen.InlineKeyboardId]
btns := kbd.buttonMap()
btn := btns[data]
btn.Action.Act(ctx)
} }
} }
} }

View file

@ -47,9 +47,10 @@ var inlineKbd = behx.NewKeyboard(
})), })),
), ),
behx.NewButtonRow( behx.NewButtonRow(
behx.NewButton("INLINE PRESS ME 3", behx.NewCustomAction(func(c *behx.Context){ behx.NewButton(
log.Println("INLINE pressed third button!") "INLINE PRESS ME 3",
})), behx.ScreenChange("second"),
),
), ),
) )