feat: publish standalone worker
Separate worker packaging and service lifecycle from the control plane.
Этот коммит содержится в:
78
internal/tg/debug/main.go
Обычный файл
78
internal/tg/debug/main.go
Обычный файл
@@ -0,0 +1,78 @@
|
||||
// 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"
|
||||
|
||||
"rsgit.ru/rsmon/rsmon/app/models"
|
||||
"rsgit.ru/rsmon/rsmon/config/database"
|
||||
_ "rsgit.ru/rsmon/rsmon/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)
|
||||
}
|
||||
}
|
||||
}
|
||||
Ссылка в новой задаче
Block a user