tg/cmd/test/main.go

112 lines
2 KiB
Go
Raw Normal View History

2023-07-03 17:22:45 +03:00
package main
2023-07-08 22:26:21 +03:00
import (
"log"
"os"
//tgbotapi "github.com/go-telegram-bot-api/telegram-bot-api/v5"
"boteval/src/behx"
2023-07-09 01:28:59 +03:00
)
var rootKbd = behx.NewKeyboard(
behx.NewButtonRow(
behx.NewButton(
"Increment",
behx.NewCustomAction(func(c *behx.Context){
counter := c.V["counter"].(*int)
*counter++
c.Sendf("%d", *counter)
}),
),
behx.NewButton(
"Decrement",
behx.NewCustomAction(func(c *behx.Context){
counter := c.V["counter"].(*int)
*counter--
c.Sendf("%d", *counter)
}),
2023-07-09 01:28:59 +03:00
),
),
behx.NewButtonRow(
2023-07-12 14:06:05 +03:00
behx.NewButton("To second screen", behx.NewScreenChange("second")),
),
)
var secondKbd = behx.NewKeyboard(
behx.NewButtonRow(
behx.NewButton(
"❤",
2023-07-12 14:20:52 +03:00
behx.NewScreenChange("start"),
2023-07-12 14:06:05 +03:00
),
),
)
var inlineKbd = behx.NewKeyboard(
behx.NewButtonRow(
behx.NewButton(
"INLINE PRESS ME",
behx.NewCustomAction(func(c *behx.Context){
log.Println("INLINE pressed the button!")
}),
2023-07-09 01:28:59 +03:00
),
behx.NewButton("INLINE PRESS ME 2", behx.NewCustomAction(func(c *behx.Context){
log.Println("INLINE pressed another button!")
})),
),
behx.NewButtonRow(
2023-07-12 14:30:05 +03:00
behx.NewButton(
"INLINE PRESS ME 3",
behx.ScreenChange("second"),
),
2023-07-09 01:28:59 +03:00
),
2023-07-08 22:26:21 +03:00
)
var startScreen = behx.NewScreen(
"Hello, World!",
"inline",
"root",
)
2023-07-12 14:06:05 +03:00
var secondScreen = behx.NewScreen(
"Second screen!",
"",
"second",
)
var behaviour = behx.NewBehaviour(
behx.NewCustomAction(func(c *behx.Context){
// This way we provide counter for EACH user.
c.V["counter"] = new(int)
// Do NOT forget to change to some of the screens
// since they are the ones who provide behaviour
// definition.
c.ChangeScreen("start")
}),
behx.ScreenMap{
2023-07-09 01:28:59 +03:00
"start": startScreen,
2023-07-12 14:06:05 +03:00
"second": secondScreen,
2023-07-09 01:28:59 +03:00
},
behx.KeyboardMap{
"root": rootKbd,
"inline": inlineKbd,
2023-07-12 14:06:05 +03:00
"second": secondKbd,
},
)
2023-07-09 01:28:59 +03:00
2023-07-03 17:22:45 +03:00
func main() {
2023-07-08 22:26:21 +03:00
token := os.Getenv("BOT_TOKEN")
bot, err := behx.NewBot(token, behaviour, nil)
2023-07-08 22:26:21 +03:00
if err != nil {
log.Panic(err)
}
bot.Debug = true
log.Printf("Authorized on account %s", bot.Self.UserName)
bot.Run()
2023-07-03 17:22:45 +03:00
}
2023-07-08 22:26:21 +03:00