mirror of
https://github.com/idanoo/autobrr
synced 2025-07-23 16:59: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) {
|
func (r *NotificationRepo) Find(ctx context.Context, params domain.NotificationQueryParams) ([]domain.Notification, int, error) {
|
||||||
queryBuilder := r.db.squirrel.
|
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").
|
From("notification").
|
||||||
OrderBy("name")
|
OrderBy("name")
|
||||||
|
|
||||||
|
@ -51,9 +51,9 @@ func (r *NotificationRepo) Find(ctx context.Context, params domain.NotificationQ
|
||||||
for rows.Next() {
|
for rows.Next() {
|
||||||
var n domain.Notification
|
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")
|
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.Channel = channel.String
|
||||||
n.Topic = topic.String
|
n.Topic = topic.String
|
||||||
n.Host = host.String
|
n.Host = host.String
|
||||||
|
n.Username = username.String
|
||||||
|
|
||||||
notifications = append(notifications, n)
|
notifications = append(notifications, n)
|
||||||
}
|
}
|
||||||
|
@ -185,6 +186,7 @@ func (r *NotificationRepo) Store(ctx context.Context, notification domain.Notifi
|
||||||
channel := toNullString(notification.Channel)
|
channel := toNullString(notification.Channel)
|
||||||
topic := toNullString(notification.Topic)
|
topic := toNullString(notification.Topic)
|
||||||
host := toNullString(notification.Host)
|
host := toNullString(notification.Host)
|
||||||
|
username := toNullString(notification.Username)
|
||||||
|
|
||||||
queryBuilder := r.db.squirrel.
|
queryBuilder := r.db.squirrel.
|
||||||
Insert("notification").
|
Insert("notification").
|
||||||
|
@ -200,6 +202,7 @@ func (r *NotificationRepo) Store(ctx context.Context, notification domain.Notifi
|
||||||
"priority",
|
"priority",
|
||||||
"topic",
|
"topic",
|
||||||
"host",
|
"host",
|
||||||
|
"username",
|
||||||
).
|
).
|
||||||
Values(
|
Values(
|
||||||
notification.Name,
|
notification.Name,
|
||||||
|
@ -213,6 +216,7 @@ func (r *NotificationRepo) Store(ctx context.Context, notification domain.Notifi
|
||||||
notification.Priority,
|
notification.Priority,
|
||||||
topic,
|
topic,
|
||||||
host,
|
host,
|
||||||
|
username,
|
||||||
).
|
).
|
||||||
Suffix("RETURNING id").RunWith(r.db.handler)
|
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)
|
channel := toNullString(notification.Channel)
|
||||||
topic := toNullString(notification.Topic)
|
topic := toNullString(notification.Topic)
|
||||||
host := toNullString(notification.Host)
|
host := toNullString(notification.Host)
|
||||||
|
username := toNullString(notification.Username)
|
||||||
|
|
||||||
queryBuilder := r.db.squirrel.
|
queryBuilder := r.db.squirrel.
|
||||||
Update("notification").
|
Update("notification").
|
||||||
|
@ -250,6 +255,7 @@ func (r *NotificationRepo) Update(ctx context.Context, notification domain.Notif
|
||||||
Set("priority", notification.Priority).
|
Set("priority", notification.Priority).
|
||||||
Set("topic", topic).
|
Set("topic", topic).
|
||||||
Set("host", host).
|
Set("host", host).
|
||||||
|
Set("username", username).
|
||||||
Set("updated_at", sq.Expr("CURRENT_TIMESTAMP")).
|
Set("updated_at", sq.Expr("CURRENT_TIMESTAMP")).
|
||||||
Where(sq.Eq{"id": notification.ID})
|
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 {
|
func (s *telegramSender) Send(event domain.NotificationEvent, payload domain.NotificationPayload) error {
|
||||||
|
|
||||||
payload.Sender = "autobrr"
|
payload.Sender = s.Settings.Username
|
||||||
|
|
||||||
message := s.builder.BuildBody(payload)
|
message := s.builder.BuildBody(payload)
|
||||||
m := TelegramMessage{
|
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."
|
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"
|
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>
|
</div>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
@ -373,7 +379,8 @@ export function NotificationAddForm({ isOpen, toggle }: AddProps) {
|
||||||
type: "",
|
type: "",
|
||||||
name: "",
|
name: "",
|
||||||
webhook: "",
|
webhook: "",
|
||||||
events: []
|
events: [],
|
||||||
|
username: ""
|
||||||
}}
|
}}
|
||||||
onSubmit={onSubmit}
|
onSubmit={onSubmit}
|
||||||
validate={validate}
|
validate={validate}
|
||||||
|
@ -577,6 +584,7 @@ interface InitialValues {
|
||||||
topic?: string;
|
topic?: string;
|
||||||
host?: string;
|
host?: string;
|
||||||
events: NotificationEvent[];
|
events: NotificationEvent[];
|
||||||
|
username?: string
|
||||||
}
|
}
|
||||||
|
|
||||||
export function NotificationUpdateForm({ isOpen, toggle, notification }: UpdateProps) {
|
export function NotificationUpdateForm({ isOpen, toggle, notification }: UpdateProps) {
|
||||||
|
@ -626,7 +634,8 @@ export function NotificationUpdateForm({ isOpen, toggle, notification }: UpdateP
|
||||||
channel: notification.channel,
|
channel: notification.channel,
|
||||||
topic: notification.topic,
|
topic: notification.topic,
|
||||||
host: notification.host,
|
host: notification.host,
|
||||||
events: notification.events || []
|
events: notification.events || [],
|
||||||
|
username: notification.username
|
||||||
};
|
};
|
||||||
|
|
||||||
return (
|
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;
|
priority?: number;
|
||||||
topic?: string;
|
topic?: string;
|
||||||
host?: string;
|
host?: string;
|
||||||
|
username?: string;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue