feat: register Telegram command menu via SetMyCommands
Call bot.SetMyCommands() on startup so that Telegram displays the command menu when users press "/" in chat. Registration failure is logged as a warning and does not block bot startup.
This commit is contained in:
parent
8928f83c7f
commit
fa6a8f9a72
1 changed files with 20 additions and 0 deletions
|
|
@ -130,6 +130,13 @@ func (c *TelegramChannel) Start(ctx context.Context) error {
|
||||||
"username": c.bot.Username(),
|
"username": c.bot.Username(),
|
||||||
})
|
})
|
||||||
|
|
||||||
|
// Register command menu with Telegram
|
||||||
|
if err := c.registerCommands(ctx); err != nil {
|
||||||
|
logger.WarnCF("telegram", "Failed to register commands menu", map[string]any{
|
||||||
|
"error": err.Error(),
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
go bh.Start()
|
go bh.Start()
|
||||||
|
|
||||||
go func() {
|
go func() {
|
||||||
|
|
@ -146,6 +153,19 @@ func (c *TelegramChannel) Stop(ctx context.Context) error {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (c *TelegramChannel) registerCommands(ctx context.Context) error {
|
||||||
|
commands := []telego.BotCommand{
|
||||||
|
{Command: "start", Description: "Start the bot"},
|
||||||
|
{Command: "help", Description: "Show available commands"},
|
||||||
|
{Command: "show", Description: "Show current configuration"},
|
||||||
|
{Command: "list", Description: "List available options"},
|
||||||
|
}
|
||||||
|
|
||||||
|
return c.bot.SetMyCommands(ctx, &telego.SetMyCommandsParams{
|
||||||
|
Commands: commands,
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
func (c *TelegramChannel) Send(ctx context.Context, msg bus.OutboundMessage) error {
|
func (c *TelegramChannel) Send(ctx context.Context, msg bus.OutboundMessage) error {
|
||||||
if !c.IsRunning() {
|
if !c.IsRunning() {
|
||||||
return fmt.Errorf("telegram bot not running")
|
return fmt.Errorf("telegram bot not running")
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue