Added basic inline-buttons support.
This commit is contained in:
parent
2935a7db99
commit
521709f87d
2 changed files with 13 additions and 7 deletions
|
@ -2,7 +2,7 @@ package behx
|
|||
|
||||
import (
|
||||
apix "github.com/go-telegram-bot-api/telegram-bot-api/v5"
|
||||
"fmt"
|
||||
//"fmt"
|
||||
)
|
||||
|
||||
// The type represents way to interact with user in
|
||||
|
@ -20,10 +20,10 @@ func (ctx *Context) handleUpdateChan(updates chan *Update) {
|
|||
for u := range updates {
|
||||
screen := bot.Screens[session.CurrentScreenId]
|
||||
|
||||
kbd := bot.Keyboards[screen.KeyboardId]
|
||||
btns := kbd.buttonMap()
|
||||
|
||||
if u.Message != nil {
|
||||
|
||||
kbd := bot.Keyboards[screen.KeyboardId]
|
||||
btns := kbd.buttonMap()
|
||||
text := u.Message.Text
|
||||
btn, ok := btns[text]
|
||||
|
||||
|
@ -35,11 +35,16 @@ func (ctx *Context) handleUpdateChan(updates chan *Update) {
|
|||
btn.Action.Act(ctx)
|
||||
} else if u.CallbackQuery != nil {
|
||||
cb := apix.NewCallback(u.CallbackQuery.ID, u.CallbackQuery.Data)
|
||||
data := u.CallbackQuery.Data
|
||||
|
||||
_, err := bot.Request(cb)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
kbd := bot.Keyboards[screen.InlineKeyboardId]
|
||||
btns := kbd.buttonMap()
|
||||
btn := btns[data]
|
||||
btn.Action.Act(ctx)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -47,9 +47,10 @@ var inlineKbd = behx.NewKeyboard(
|
|||
})),
|
||||
),
|
||||
behx.NewButtonRow(
|
||||
behx.NewButton("INLINE PRESS ME 3", behx.NewCustomAction(func(c *behx.Context){
|
||||
log.Println("INLINE pressed third button!")
|
||||
})),
|
||||
behx.NewButton(
|
||||
"INLINE PRESS ME 3",
|
||||
behx.ScreenChange("second"),
|
||||
),
|
||||
),
|
||||
)
|
||||
|
||||
|
|
Loading…
Reference in a new issue