// Package main provides functionality. package main import ( "log" "github.com/davecgh/go-spew/spew" tgbotapi "github.com/go-telegram-bot-api/telegram-bot-api/v5" "rocketgit.ru/rsmon/worker/app/models" "rocketgit.ru/rsmon/worker/config/database" _ "rocketgit.ru/rsmon/worker/config/env" ) func main() { database.Init() creds, err := models.EnabledCredentialsByKind(models.CredentialKindTelegram) if err != nil { log.Panic(err) } if len(creds) == 0 { log.Panic("telegram credential is not configured") } token, err := creds[0].GetSecret() if err != nil { log.Panic(err) } bot, err := tgbotapi.NewBotAPI(token) if err != nil { log.Panic(err) } bot.Debug = true log.Printf("Authorized on account %s", bot.Self.UserName) u := tgbotapi.NewUpdate(0) u.Timeout = 60 updates := bot.GetUpdatesChan(u) for update := range updates { if update.Message == nil { // ignore any non-Message updates continue } if !update.Message.IsCommand() { // ignore any non-command Messages continue } // Create a new MessageConfig. We don't have text yet, // so we leave it empty. msg := tgbotapi.NewMessage(update.Message.Chat.ID, "") spew.Dump(update.Message) spew.Dump(update.Message.Chat) switch update.Message.Chat.Type { case "private": // Extract the command from the Message. switch update.Message.Command() { case "start": msg.Text = "Для завершения добавления вида оповещений перейдите по ссылке https://rsmon.ru/contacts/new?kind=telegram&" case "help": msg.Text = "/start - добавление способа оповещений\n/list список способов оповещений для этого чата\n" default: msg.Text = "Неизвестная команда" } case "group": default: msg.Text = "Неизвестный тип чата: " + update.Message.Chat.Type } if _, err := bot.Send(msg); err != nil { log.Panic(err) } } }