mirror of
https://github.com/lukaszraczylo/go-telegram.git
synced 2026-07-22 12:39:32 +00:00
Snapshot taken 2026-07-21. Notable shape change: ReplyParameters.MessageID becomes optional (*int64) because Bot API 10.2 allows a reply to target ephemeral_message_id instead. This breaks callers that set MessageID by value, so examples/echo passes the address now. New surface includes the ephemeral message methods, sendRichMessage with InputRichMessageMedia, and the Community service messages.
33 lines
919 B
Go
33 lines
919 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.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.ChatIDFromInt(m.Chat.ID),
|
|
Text: m.Text,
|
|
ReplyParameters: &api.ReplyParameters{MessageID: &m.MessageID},
|
|
})
|
|
return err
|
|
}
|