customer/internal/interface/client/telegram.go
Pasha 34a88a3a70
Some checks failed
Lint / Lint (push) Failing after 1m2s
rename go.mod
2024-11-18 21:44:09 +00:00

50 lines
1.3 KiB
Go
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

package client
import (
"fmt"
tb "gopkg.in/tucnak/telebot.v2"
"gitea.pena/PenaSide/customer/internal/errors"
"gitea.pena/PenaSide/customer/internal/models"
)
type TelegramClient struct {
notifier *tb.Bot
notifierPayChannel int64
}
type TelegramClientDeps struct {
Notifier *tb.Bot
NotifierPayChannel int64
}
func NewTelegramClient(deps TelegramClientDeps) *TelegramClient {
return &TelegramClient{
notifier: deps.Notifier,
notifierPayChannel: deps.NotifierPayChannel,
}
}
func (t *TelegramClient) NotifyRsPay(userEmail string, verification *models.Verification, money float32) errors.Error {
message := fmt.Sprintf(
"Поступила заявка на оплату через Р/С от пользователя с почтой %s (%s)\n"+
"Вот файлы его верификации:\n"+
"Запрос на оплату: %f рублей\n",
userEmail, verification.UserID, money,
)
for _, file := range verification.Files {
message += fmt.Sprintf("%s: %s\n", file.Name, file.URL)
}
fmt.Println("RSP", t.notifierPayChannel)
_, err := t.notifier.Send(
&tb.Chat{ID: t.notifierPayChannel},
message,
)
if err != nil {
return errors.New(fmt.Errorf("failed to send tg RS PAY message: %v", err), errors.ErrInternalError)
}
return nil
}