Skip to content

Commit

Permalink
Improve telegram command message
Browse files Browse the repository at this point in the history
  • Loading branch information
web-flow committed Apr 20, 2021
1 parent 2821564 commit 8450034
Showing 1 changed file with 20 additions and 2 deletions.
22 changes: 20 additions & 2 deletions service/telegram/telegram.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ func (t *Telegram) Serve(ctx context.Context) (err error) {
updates := t.bot.GetUpdatesChan(cfg)

c := make(chan os.Signal)
signal.Notify(c, os.Interrupt, syscall.SIGTERM)
signal.Notify(c, os.Interrupt, syscall.SIGTERM, syscall.SIGINT)
go func() {
<-c
logger.Info("[telegram] stopping receive updates...")
Expand Down Expand Up @@ -101,7 +101,11 @@ func (t *Telegram) process(ctx context.Context, update telegram.Update) error {
t.bot.Send(msg)
return nil
case message.IsCommand():
msg := telegram.NewMessage(message.Chat.ID, fmt.Sprintf("/%s no specified", message.Command()))
commands := t.myCommands()
if commands != "" {
commands = fmt.Sprintf(", you can type:\n\n%s", commands)
}
msg := telegram.NewMessage(message.Chat.ID, fmt.Sprintf("/%s is no specified command%s", message.Command(), commands))
msg.ReplyToMessageID = message.MessageID
t.bot.Send(msg)
return nil
Expand Down Expand Up @@ -177,3 +181,17 @@ func (t *Telegram) archive(urls []string) (col []*wayback.Collect, err error) {

return col, nil
}

func (t *Telegram) myCommands() string {
commands, err := t.bot.GetMyCommands()
if err != nil {
return ""
}

var list string
for _, command := range commands {
list = fmt.Sprintf("/%s - %s\n", command.Command, command.Description)
}

return list
}

0 comments on commit 8450034

Please sign in to comment.