package client import ( "bytes" _ "embed" "fmt" tgbotapi "github.com/go-telegram-bot-api/telegram-bot-api/v5" "go.uber.org/zap" "penahub.gitlab.yandexcloud.net/backend/verification/internal/models" "text/template" ) //go:embed assets/new_verification.txt var NewVerification string //go:embed assets/updated_verification.txt var UpdatedVerification string type Deps struct { Logger *zap.Logger Bot *tgbotapi.BotAPI ChatID int64 StagingURL string } type Telegram struct { logger *zap.Logger bot *tgbotapi.BotAPI chatID int64 stagingURL string } func NewTelegram(deps Deps) *Telegram { return &Telegram{logger: deps.Logger, bot: deps.Bot, chatID: deps.ChatID, stagingURL: deps.StagingURL} } func (t *Telegram) SendVerification(data *models.Verification, url string, isUpdate bool) error { var tplPath string if isUpdate { tplPath = UpdatedVerification } else { tplPath = NewVerification } var userURL string if url == t.stagingURL { userURL = fmt.Sprintf("https://sadmin.pena/users/%s", data.UserID) } else { userURL = fmt.Sprintf("https://admin.pena/users/%s", data.UserID) } tpl, err := template.New("verification_template").Parse(tplPath) if err != nil { return fmt.Errorf("error parsing template: %w", err) } var text bytes.Buffer toTG := models.ToTelegram{ ID: data.ID, UserID: data.UserID, UserURL: userURL, Accepted: data.Accepted, Status: data.Status, UpdatedAt: data.UpdatedAt, Comment: data.Comment, Files: data.Files, TaxNumber: data.TaxNumber, } err = tpl.Execute(&text, toTG) if err != nil { return fmt.Errorf("error executing template: %w", err) } msg := tgbotapi.NewMessage(t.chatID, text.String()) _, err = t.bot.Send(msg) if err != nil { return fmt.Errorf("error sending message: %w", err) } return nil }