mirror of
https://github.com/crazy-max/diun.git
synced 2025-04-17 08:22:40 +00:00
Allow customizing Signal notification message
This commit is contained in:
parent
63c8302332
commit
d7909f0156
3 changed files with 42 additions and 13 deletions
|
@ -15,14 +15,17 @@ You can send Signal notifications via the Signal REST API with the following set
|
||||||
recipients:
|
recipients:
|
||||||
- "+00472323111337"
|
- "+00472323111337"
|
||||||
timeout: 10s
|
timeout: 10s
|
||||||
|
templateBody: |
|
||||||
|
Docker tag {{ .Entry.Image }} which you subscribed to through {{ .Entry.Provider }} provider has been released.
|
||||||
```
|
```
|
||||||
|
|
||||||
| Name | Default | Description |
|
| Name | Default | Description |
|
||||||
|--------------------|---------------------------------|-----------------------------------------------------------|
|
|--------------------|------------------------------------|---------------------------------------------------------------------------|
|
||||||
| `endpoint` | `http://localhost:8080/v2/send` | URL of the Signal REST API endpoint |
|
| `endpoint` | `http://localhost:8080/v2/send` | URL of the Signal REST API endpoint |
|
||||||
| `number`[^1] | | The senders number you registered |
|
| `number`[^1] | | The senders number you registered |
|
||||||
| `recipients`[^1] | | A list of recipients, either phone numbers or group ID's |
|
| `recipients`[^1] | | A list of recipients, either phone numbers or group ID's |
|
||||||
| `timeout` | `10s` | Timeout specifies a time limit for the request to be made |
|
| `timeout` | `10s` | Timeout specifies a time limit for the request to be made |
|
||||||
|
| `templateBody`[^1] | See [below](#default-templatebody) | [Notification template](../faq.md#notification-template) for message body |
|
||||||
|
|
||||||
!!! abstract "Environment variables"
|
!!! abstract "Environment variables"
|
||||||
* `DIUN_NOTIF_SIGNALREST_ENDPOINT`
|
* `DIUN_NOTIF_SIGNALREST_ENDPOINT`
|
||||||
|
@ -30,12 +33,18 @@ You can send Signal notifications via the Signal REST API with the following set
|
||||||
* `DIUN_NOTIF_SIGNALREST_RECIPIENTS_<KEY>`
|
* `DIUN_NOTIF_SIGNALREST_RECIPIENTS_<KEY>`
|
||||||
* `DIUN_NOTIF_SIGNALREST_TIMEOUT`
|
* `DIUN_NOTIF_SIGNALREST_TIMEOUT`
|
||||||
|
|
||||||
|
### Default `templateBody`
|
||||||
|
|
||||||
|
```
|
||||||
|
Docker tag {{ .Entry.Image }} which you subscribed to through {{ .Entry.Provider }} provider {{ if (eq .Entry.Status "new") }}is available{{ else }}has been updated{{ end }} on {{ .Entry.Image.Domain }} registry (triggered by {{ .Meta.Hostname }} host).
|
||||||
|
```
|
||||||
|
|
||||||
## Sample
|
## Sample
|
||||||
|
|
||||||
The message you receive in your Signal App will look like this:
|
The message you receive in your Signal App will look like this:
|
||||||
|
|
||||||
```text
|
```text
|
||||||
Docker tag docker.io/diun/testnotif:latest which you subscribed to through file provider new has been updated on docker.io registry (triggered by5bfaae601770 host).
|
Docker tag docker.io/diun/testnotif:latest which you subscribed to through file provider new has been updated on docker.io registry (triggered by 5bfaae601770 host).
|
||||||
```
|
```
|
||||||
|
|
||||||
[^1]: Value required
|
[^1]: Value required
|
||||||
|
|
|
@ -6,13 +6,17 @@ import (
|
||||||
"github.com/crazy-max/diun/v4/pkg/utl"
|
"github.com/crazy-max/diun/v4/pkg/utl"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
// NotifSignalRestDefaultTemplateBody ...
|
||||||
|
const NotifSignalRestDefaultTemplateBody = `Docker tag {{ .Entry.Image }} which you subscribed to through {{ .Entry.Provider }} provider {{ if (eq .Entry.Status "new") }}is available{{ else }}has been updated{{ end }} on {{ .Entry.Image.Domain }} registry (triggered by {{ .Meta.Hostname }} host).`
|
||||||
|
|
||||||
// NotifSignalRest holds SignalRest notification configuration details
|
// NotifSignalRest holds SignalRest notification configuration details
|
||||||
type NotifSignalRest struct {
|
type NotifSignalRest struct {
|
||||||
Endpoint string `yaml:"endpoint,omitempty" json:"endpoint,omitempty" validate:"required"`
|
Endpoint string `yaml:"endpoint,omitempty" json:"endpoint,omitempty" validate:"required"`
|
||||||
Number string `yaml:"number,omitempty" json:"method,omitempty" validate:"required"`
|
Number string `yaml:"number,omitempty" json:"method,omitempty" validate:"required"`
|
||||||
Recipients []string `yaml:"recipients,omitempty" json:"recipients,omitempty" validate:"omitempty"`
|
Recipients []string `yaml:"recipients,omitempty" json:"recipients,omitempty" validate:"omitempty"`
|
||||||
Headers map[string]string `yaml:"headers,omitempty" json:"headers,omitempty" validate:"omitempty"`
|
Headers map[string]string `yaml:"headers,omitempty" json:"headers,omitempty" validate:"omitempty"`
|
||||||
Timeout *time.Duration `yaml:"timeout,omitempty" json:"timeout,omitempty" validate:"required"`
|
Timeout *time.Duration `yaml:"timeout,omitempty" json:"timeout,omitempty" validate:"required"`
|
||||||
|
TemplateBody string `yaml:"templateBody,omitempty" json:"templateBody,omitempty" validate:"required"`
|
||||||
}
|
}
|
||||||
|
|
||||||
// GetDefaults gets the default values
|
// GetDefaults gets the default values
|
||||||
|
@ -26,4 +30,5 @@ func (s *NotifSignalRest) GetDefaults() *NotifSignalRest {
|
||||||
func (s *NotifSignalRest) SetDefaults() {
|
func (s *NotifSignalRest) SetDefaults() {
|
||||||
s.Timeout = utl.NewDuration(10 * time.Second)
|
s.Timeout = utl.NewDuration(10 * time.Second)
|
||||||
s.Endpoint = "http://localhost:8080/v2/send"
|
s.Endpoint = "http://localhost:8080/v2/send"
|
||||||
|
s.TemplateBody = NotifSignalRestDefaultTemplateBody
|
||||||
}
|
}
|
||||||
|
|
|
@ -6,6 +6,7 @@ import (
|
||||||
"net/http"
|
"net/http"
|
||||||
|
|
||||||
"github.com/crazy-max/diun/v4/internal/model"
|
"github.com/crazy-max/diun/v4/internal/model"
|
||||||
|
"github.com/crazy-max/diun/v4/internal/msg"
|
||||||
"github.com/crazy-max/diun/v4/internal/notif/notifier"
|
"github.com/crazy-max/diun/v4/internal/notif/notifier"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -37,12 +38,26 @@ func (c *Client) Send(entry model.NotifEntry) error {
|
||||||
Timeout: *c.cfg.Timeout,
|
Timeout: *c.cfg.Timeout,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
message, err := msg.New(msg.Options{
|
||||||
|
Meta: c.meta,
|
||||||
|
Entry: entry,
|
||||||
|
TemplateBody: c.cfg.TemplateBody,
|
||||||
|
})
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
_, bodyrender, err := message.RenderMarkdown()
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
body, err := json.Marshal(struct {
|
body, err := json.Marshal(struct {
|
||||||
Message string `json:"message"`
|
Message string `json:"message"`
|
||||||
Number string `json:"number"`
|
Number string `json:"number"`
|
||||||
Recipients []string `json:"recipients"`
|
Recipients []string `json:"recipients"`
|
||||||
}{
|
}{
|
||||||
Message: "Docker tag " + entry.Image.String() + " which you subscribed to through " + entry.Provider + " provider " + string(entry.Status) + " has been updated on " + entry.Image.Domain + " registry (triggered by" + c.meta.Hostname + " host).",
|
Message: string(bodyrender),
|
||||||
Number: c.cfg.Number,
|
Number: c.cfg.Number,
|
||||||
Recipients: c.cfg.Recipients,
|
Recipients: c.cfg.Recipients,
|
||||||
})
|
})
|
||||||
|
|
Loading…
Add table
Reference in a new issue