Committing current WIP with command set for administrators.
For whatever reason, it wasn't displaying or refreshing in Telegram for Desktop.
This commit is contained in:
parent
12e0ba0010
commit
fd608a857c
1 changed files with 43 additions and 12 deletions
|
|
@ -70,7 +70,7 @@ func (b *bot) init() {
|
|||
}
|
||||
|
||||
func (b *bot) AttachHandlers() {
|
||||
fmt.Println("add handlers")
|
||||
fmt.Println("add handlers", b.handler)
|
||||
b.handler.HandleMessage(func(ctx *th.Context, message telego.Message) error {
|
||||
fmt.Println("handling message")
|
||||
if !slices.Contains(b.settings.Chat.Channels, message.Chat.ID) {
|
||||
|
|
@ -88,6 +88,21 @@ func (b *bot) AttachHandlers() {
|
|||
))*/
|
||||
return nil
|
||||
}, th.CommandEqual("start"))
|
||||
|
||||
b.handler.HandleMessage(func(ctx *th.Context, message telego.Message) error {
|
||||
fmt.Println("received help command:", message.Text)
|
||||
// Send a message with inline keyboard
|
||||
/*_, _ = ctx.Bot().SendMessage(ctx, tu.Message(
|
||||
tu.ID(message.Chat.ID),
|
||||
fmt.Sprintf("Hello %s!", message.From.FirstName),
|
||||
).WithReplyMarkup(tu.InlineKeyboard(
|
||||
tu.InlineKeyboardRow(
|
||||
tu.InlineKeyboardButton("Go!").WithCallbackData("go"),
|
||||
)),
|
||||
))*/
|
||||
return nil
|
||||
}, th.CommandEqual("help"))
|
||||
|
||||
}
|
||||
|
||||
func (b *bot) SendMarkdownMessage(chatid int64, message string) error {
|
||||
|
|
@ -143,7 +158,19 @@ func (b *bot) SendScripture() {
|
|||
}
|
||||
|
||||
func (b *bot) SetCommands(ctx context.Context) (err error) {
|
||||
commands, err := b.tgbot.GetMyCommands(ctx, &telego.GetMyCommandsParams{})
|
||||
commands, err := b.tgbot.GetMyCommands(ctx, &telego.GetMyCommandsParams{
|
||||
Scope: &telego.BotCommandScopeAllGroupChats{
|
||||
Type: "all_group_chats",
|
||||
},
|
||||
})
|
||||
fmt.Println("all_group_chats:")
|
||||
fmt.Println(commands)
|
||||
commands, err = b.tgbot.GetMyCommands(ctx, &telego.GetMyCommandsParams{
|
||||
Scope: &telego.BotCommandScopeAllChatAdministrators{
|
||||
Type: "all_chat_administrators",
|
||||
},
|
||||
})
|
||||
fmt.Println("all_chat_administrators:")
|
||||
fmt.Println(commands)
|
||||
if len(commands) > 0 {
|
||||
if b.settings.Debug.Commands.Reset {
|
||||
|
|
@ -152,12 +179,13 @@ func (b *bot) SetCommands(ctx context.Context) (err error) {
|
|||
Type: "all_chat_administrators",
|
||||
},
|
||||
})
|
||||
b.tgbot.DeleteMyCommands(ctx, &telego.DeleteMyCommandsParams{})
|
||||
b.tgbot.DeleteMyCommands(ctx, &telego.DeleteMyCommandsParams{
|
||||
Scope: &telego.BotCommandScopeAllGroupChats{
|
||||
Type: "all_group_chats",
|
||||
},
|
||||
})
|
||||
}
|
||||
for _, command := range commands {
|
||||
fmt.Println(command)
|
||||
}
|
||||
return
|
||||
//return
|
||||
}
|
||||
if !b.settings.Debug.Commands.Register {
|
||||
return
|
||||
|
|
@ -210,6 +238,9 @@ func (b *bot) SetCommands(ctx context.Context) (err error) {
|
|||
},
|
||||
})
|
||||
b.tgbot.SetMyCommands(ctx, &telego.SetMyCommandsParams{
|
||||
Scope: &telego.BotCommandScopeAllGroupChats{
|
||||
Type: "all_group_chats",
|
||||
},
|
||||
Commands: []telego.BotCommand{
|
||||
{
|
||||
Command: "help",
|
||||
|
|
@ -285,6 +316,11 @@ func (b *bot) SetWebhook(ctx context.Context, conf *settings.Settings) (err erro
|
|||
return
|
||||
}
|
||||
|
||||
info, err := b.tgbot.GetWebhookInfo(b.ctx)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
fmt.Println("webhook info:", info)
|
||||
err = b.tgbot.SetWebhook(b.ctx, &telego.SetWebhookParams{
|
||||
URL: b.settings.Service.Webhook.URI,
|
||||
SecretToken: b.tgbot.SecretToken(),
|
||||
|
|
@ -292,11 +328,6 @@ func (b *bot) SetWebhook(ctx context.Context, conf *settings.Settings) (err erro
|
|||
if err != nil {
|
||||
return
|
||||
}
|
||||
info, err := b.tgbot.GetWebhookInfo(b.ctx)
|
||||
if err != nil {
|
||||
fmt.Println(info, err)
|
||||
return
|
||||
}
|
||||
|
||||
mux := http.NewServeMux()
|
||||
updates, err := b.tgbot.UpdatesViaWebhook(ctx,
|
||||
|
|
|
|||
Loading…
Reference in a new issue