mirror of
https://github.com/lukaszraczylo/go-telegram.git
synced 2026-12-06 07:44:04 +00:00
* chore(api): regenerate for BotFullInfo and optional chat_id Telegram split BotFullInfo out of User and getMe now returns it, and chat_id is optional in the methods that accept an ephemeral callback reply. Regenerate the API, make MeCache cache BotFullInfo, and wrap the now-optional chat_id arguments in the examples. This is the output of make regen, so the weekly regen job no longer fails its api test. * chore(api): pin the 2026-11-29 API snapshot the regen used codegen-clean regenerates from testdata/html/latest.html, so the new BotFullInfo output needs a matching snapshot.
33 lines
937 B
Go
33 lines
937 B
Go
package main
|
|
|
|
import (
|
|
"fmt"
|
|
|
|
"github.com/lukaszraczylo/go-telegram/api"
|
|
"github.com/lukaszraczylo/go-telegram/dispatch"
|
|
)
|
|
|
|
// register wires all handlers onto the router. Exposed so tests can call
|
|
// handlers directly without going through the router run loop.
|
|
func register(r *dispatch.Router) {
|
|
r.OnCommand("/start", handleStart)
|
|
r.OnText(`.+`, handleEcho)
|
|
}
|
|
|
|
func handleStart(c *dispatch.Context, m *api.Message) error {
|
|
_, err := api.SendMessage(c.Ctx, c.Bot, &api.SendMessageParams{
|
|
ChatID: api.Ptr(api.ChatIDFromInt(m.Chat.ID)),
|
|
Text: fmt.Sprintf("hello %s, send me anything to echo", m.From.FirstName),
|
|
})
|
|
return err
|
|
}
|
|
|
|
func handleEcho(c *dispatch.Context, m *api.Message) error {
|
|
_, err := api.SendMessage(c.Ctx, c.Bot, &api.SendMessageParams{
|
|
ChatID: api.Ptr(api.ChatIDFromInt(m.Chat.ID)),
|
|
Text: m.Text,
|
|
ReplyParameters: &api.ReplyParameters{MessageID: &m.MessageID},
|
|
})
|
|
return err
|
|
}
|