generated from PenaSide/GolangTemplate
50 lines
1.3 KiB
Go
50 lines
1.3 KiB
Go
package client
|
||
|
||
import (
|
||
"fmt"
|
||
tb "gopkg.in/tucnak/telebot.v2"
|
||
"penahub.gitlab.yandexcloud.net/pena-services/customer/internal/errors"
|
||
"penahub.gitlab.yandexcloud.net/pena-services/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
|
||
}
|