mirror of
https://github.com/idanoo/autobrr
synced 2025-07-22 16:29:12 +00:00
feat(notifications): optional Telegram sender (#1726)
refactor(notifications): optional Telegram sender
This commit is contained in:
parent
c8e2fba334
commit
ec79eafe43
4 changed files with 22 additions and 6 deletions
|
@ -30,7 +30,7 @@ func NewNotificationRepo(log logger.Logger, db *DB) domain.NotificationRepo {
|
|||
|
||||
func (r *NotificationRepo) Find(ctx context.Context, params domain.NotificationQueryParams) ([]domain.Notification, int, error) {
|
||||
queryBuilder := r.db.squirrel.
|
||||
Select("id", "name", "type", "enabled", "events", "webhook", "token", "api_key", "channel", "priority", "topic", "host", "created_at", "updated_at", "COUNT(*) OVER() AS total_count").
|
||||
Select("id", "name", "type", "enabled", "events", "webhook", "token", "api_key", "channel", "priority", "topic", "host", "username", "created_at", "updated_at", "COUNT(*) OVER() AS total_count").
|
||||
From("notification").
|
||||
OrderBy("name")
|
||||
|
||||
|
@ -51,9 +51,9 @@ func (r *NotificationRepo) Find(ctx context.Context, params domain.NotificationQ
|
|||
for rows.Next() {
|
||||
var n domain.Notification
|
||||
|
||||
var webhook, token, apiKey, channel, host, topic sql.NullString
|
||||
var webhook, token, apiKey, channel, host, topic, username sql.NullString
|
||||
|
||||
if err := rows.Scan(&n.ID, &n.Name, &n.Type, &n.Enabled, pq.Array(&n.Events), &webhook, &token, &apiKey, &channel, &n.Priority, &topic, &host, &n.CreatedAt, &n.UpdatedAt, &totalCount); err != nil {
|
||||
if err := rows.Scan(&n.ID, &n.Name, &n.Type, &n.Enabled, pq.Array(&n.Events), &webhook, &token, &apiKey, &channel, &n.Priority, &topic, &host, &username, &n.CreatedAt, &n.UpdatedAt, &totalCount); err != nil {
|
||||
return nil, 0, errors.Wrap(err, "error scanning row")
|
||||
}
|
||||
|
||||
|
@ -63,6 +63,7 @@ func (r *NotificationRepo) Find(ctx context.Context, params domain.NotificationQ
|
|||
n.Channel = channel.String
|
||||
n.Topic = topic.String
|
||||
n.Host = host.String
|
||||
n.Username = username.String
|
||||
|
||||
notifications = append(notifications, n)
|
||||
}
|
||||
|
@ -185,6 +186,7 @@ func (r *NotificationRepo) Store(ctx context.Context, notification domain.Notifi
|
|||
channel := toNullString(notification.Channel)
|
||||
topic := toNullString(notification.Topic)
|
||||
host := toNullString(notification.Host)
|
||||
username := toNullString(notification.Username)
|
||||
|
||||
queryBuilder := r.db.squirrel.
|
||||
Insert("notification").
|
||||
|
@ -200,6 +202,7 @@ func (r *NotificationRepo) Store(ctx context.Context, notification domain.Notifi
|
|||
"priority",
|
||||
"topic",
|
||||
"host",
|
||||
"username",
|
||||
).
|
||||
Values(
|
||||
notification.Name,
|
||||
|
@ -213,6 +216,7 @@ func (r *NotificationRepo) Store(ctx context.Context, notification domain.Notifi
|
|||
notification.Priority,
|
||||
topic,
|
||||
host,
|
||||
username,
|
||||
).
|
||||
Suffix("RETURNING id").RunWith(r.db.handler)
|
||||
|
||||
|
@ -236,6 +240,7 @@ func (r *NotificationRepo) Update(ctx context.Context, notification domain.Notif
|
|||
channel := toNullString(notification.Channel)
|
||||
topic := toNullString(notification.Topic)
|
||||
host := toNullString(notification.Host)
|
||||
username := toNullString(notification.Username)
|
||||
|
||||
queryBuilder := r.db.squirrel.
|
||||
Update("notification").
|
||||
|
@ -250,6 +255,7 @@ func (r *NotificationRepo) Update(ctx context.Context, notification domain.Notif
|
|||
Set("priority", notification.Priority).
|
||||
Set("topic", topic).
|
||||
Set("host", host).
|
||||
Set("username", username).
|
||||
Set("updated_at", sq.Expr("CURRENT_TIMESTAMP")).
|
||||
Where(sq.Eq{"id": notification.ID})
|
||||
|
||||
|
|
|
@ -64,7 +64,7 @@ func NewTelegramSender(log zerolog.Logger, settings domain.Notification) domain.
|
|||
|
||||
func (s *telegramSender) Send(event domain.NotificationEvent, payload domain.NotificationPayload) error {
|
||||
|
||||
payload.Sender = "autobrr"
|
||||
payload.Sender = s.Settings.Username
|
||||
|
||||
message := s.builder.BuildBody(payload)
|
||||
m := TelegramMessage{
|
||||
|
|
|
@ -146,6 +146,12 @@ function FormFieldsTelegram() {
|
|||
help="Reverse proxy domain for api.telegram.org, only needs to be specified if the network you are using has blocked the Telegram API."
|
||||
placeholder="http(s)://ip:port"
|
||||
/>
|
||||
<TextFieldWide
|
||||
name="username"
|
||||
label="Sender"
|
||||
help="Custom sender name to show at the top of a notification"
|
||||
placeholder="autobrr"
|
||||
/>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
@ -373,7 +379,8 @@ export function NotificationAddForm({ isOpen, toggle }: AddProps) {
|
|||
type: "",
|
||||
name: "",
|
||||
webhook: "",
|
||||
events: []
|
||||
events: [],
|
||||
username: ""
|
||||
}}
|
||||
onSubmit={onSubmit}
|
||||
validate={validate}
|
||||
|
@ -577,6 +584,7 @@ interface InitialValues {
|
|||
topic?: string;
|
||||
host?: string;
|
||||
events: NotificationEvent[];
|
||||
username?: string
|
||||
}
|
||||
|
||||
export function NotificationUpdateForm({ isOpen, toggle, notification }: UpdateProps) {
|
||||
|
@ -626,7 +634,8 @@ export function NotificationUpdateForm({ isOpen, toggle, notification }: UpdateP
|
|||
channel: notification.channel,
|
||||
topic: notification.topic,
|
||||
host: notification.host,
|
||||
events: notification.events || []
|
||||
events: notification.events || [],
|
||||
username: notification.username
|
||||
};
|
||||
|
||||
return (
|
||||
|
|
1
web/src/types/Notification.d.ts
vendored
1
web/src/types/Notification.d.ts
vendored
|
@ -25,4 +25,5 @@ interface ServiceNotification {
|
|||
priority?: number;
|
||||
topic?: string;
|
||||
host?: string;
|
||||
username?: string;
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue