customer/internal/interface/client/telegram.go

50 lines
1.3 KiB
Go
Raw Normal View History

package client
import (
"fmt"
tb "gopkg.in/tucnak/telebot.v2"
2024-11-18 07:23:41 +00:00
"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)
}
2024-10-20 21:53:58 +00:00
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
}