Skip to content

Commit 9314961

Browse files
mrinjamulmrasif
andauthored
feat: Add Gotify Provider and CLI flags for title and priority (#9)
* feat: add gotify notification support * fix: #8 add title and priority for gotify notification * fix: add subject for smtp too and load default title and priority from env or config for gotify * optimizing code structure... --------- Co-authored-by: Asif Mohammad Mollah <admin@mrasif.in>
1 parent 9e65adb commit 9314961

21 files changed

Lines changed: 387 additions & 176 deletions

File tree

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
build
22

33
chatz
4+
*.exe
45
coverage.out

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ With chatz, you can streamline your notification processes across multiple platf
2828
- Discord: [Read documentation](docs/discord.md)
2929
- Redis: [Read documentation](docs/redis.md)
3030
- SMTP: [Read documentation](docs/smtp.md)
31+
- Gotify: [Read documentation](docs/gotify.md)
3132

3233
## Installation
3334
Download and install executable binary from GitHub releases page.

chatz.ini

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,3 +36,10 @@ SMTP_PASSWORD=<app-password>
3636
SMTP_SUBJECT=<Your subject>
3737
SMTP_FROM=<from-mail@gmail.com>
3838
SMTP_TO=<user1@gmail.com,user1@gmail.com>
39+
40+
[gotify]
41+
PROVIDER=gotify
42+
GOTIFY_URL=<gotify-url>
43+
GOTIFY_TOKEN=<gotify-token>
44+
GOTIFY_TITLE="Chatz"
45+
GOTIFY_PRIORITY=5

config/config.go

Lines changed: 19 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -2,19 +2,23 @@ package config
22

33
// Environment
44
type Config struct {
5-
Provider string
6-
WebHookURL string
7-
Token string
8-
ChannelId string
9-
ChatId string
10-
ConnectionURL string
11-
SMTPHost string
12-
SMTPPort string
13-
UseTLS bool
14-
UseSTARTTLS bool
15-
SMTPUser string
16-
SMTPPassword string
17-
SMTPSubject string
18-
SMTPFrom string
19-
SMTPTo string
5+
Provider string
6+
WebHookURL string
7+
Token string
8+
ChannelId string
9+
ChatId string
10+
ConnectionURL string
11+
SMTPHost string
12+
SMTPPort string
13+
UseTLS bool
14+
UseSTARTTLS bool
15+
SMTPUser string
16+
SMTPPassword string
17+
SMTPSubject string
18+
SMTPFrom string
19+
SMTPTo string
20+
GotifyURL string
21+
GotifyToken string
22+
GotifyTitle string
23+
GotifyPriority int
2024
}

constants/common.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,4 +7,5 @@ const (
77
PROVIDER_GOOGLE = "google"
88
PROVIDER_REDIS = "redis"
99
PROVIDER_SMTP = "smtp"
10+
PROVIDER_GOTIFY = "gotify"
1011
)

docs/gotify.md

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
# Gotify Notification Setup
2+
3+
This guide will walk you through setting up Gotify notifications. You will learn how to obtain the necessary credentials and configure them in your environment.
4+
5+
## 1. Get Gotify URL and App Token
6+
7+
First, you need to get the Gotify server URL and an app token.
8+
9+
1. **Gotify Server URL**: This is the URL of your Gotify server.
10+
2. **App Token**: You can create a new app in the Gotify web UI and get the token.
11+
12+
## 2. Configure Chatz
13+
14+
Next, you need to configure Chatz to use the Gotify provider. You can do this by editing the `~/.chatz.ini` file or by setting environment variables.
15+
16+
### Using `~/.chatz.ini`
17+
18+
Add the following section to your `~/.chatz.ini` file:
19+
20+
```ini
21+
[gotify]
22+
PROVIDER=gotify
23+
GOTIFY_URL=<your-gotify-server-url>
24+
GOTIFY_TOKEN=<your-gotify-app-token>
25+
GOTIFY_TITLE=<your-gotify-title>
26+
GOTIFY_PRIORITY=<your-gotify-priority>
27+
```
28+
29+
### Using Environment Variables
30+
31+
Set the following environment variables:
32+
33+
```sh
34+
export PROVIDER=gotify
35+
export GOTIFY_URL=<your-gotify-server-url>
36+
export GOTIFY_TOKEN=<your-gotify-app-token>
37+
export GOTIFY_TITLE=<your-gotify-title>
38+
export GOTIFY_PRIORITY=<your-gotify-priority>
39+
```
40+
41+
## 3. Send a Test Notification
42+
43+
Now you can send a test notification to your Gotify server.
44+
45+
```sh
46+
chatz --profile=gotify "Hello from Chatz!"
47+
```
48+
49+
You should receive a notification on your Gotify server.
50+
51+
### Using CLI Flags
52+
53+
You can also override the title and priority using CLI flags:
54+
55+
```sh
56+
chatz --profile=gotify --subject "Custom Title" --priority 7 "Hello from Chatz!"
57+
```
58+
59+
This will send a notification with "Custom Title" as the title and a priority of 7.

docs/smtp.md

Lines changed: 29 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -2,41 +2,34 @@
22

33
This document explains how to configure SMTP with Gmail, including creating an App Password, and understanding TLS/STARTTLS and encryption options.
44

5-
65
## 1. Creating an App Password
76

8-
Gmail requires an "App Password" for less secure apps accessing your account. This is a more secure alternative to using your regular Gmail password directly.
7+
Gmail requires an "App Password" for less secure apps accessing your account. This is a more secure alternative to using your regular Gmail password directly.
98

109
1. Go to your [Google account security settings](https://myaccount.google.com/security).
1110
2. Scroll down to "Signing in to Google" and click "App Passwords".
12-
3. Select "Mail" as the app and "Other (Custom name)" as the device. Give it a descriptive name (e.g., "My SMTP App").
13-
4. Click "Generate". A new password will be displayed. **Copy this password immediately; you won't be able to see it again.**
11+
3. Select "Mail" as the app and "Other (Custom name)" as the device. Give it a descriptive name (e.g., "My SMTP App").
12+
4. Click "Generate". A new password will be displayed. **Copy this password immediately; you won't be able to see it again.**
1413

1514
## 2. SMTP Server Settings
1615

17-
* **Server:** `smtp.gmail.com`
18-
* **Port:**
19-
* **STARTTLS:** 587 (Recommended)
20-
* **TLS:** 465
21-
* **No Encryption (Insecure - Avoid):** 25
22-
* **Username:** Your full Gmail address (e.g., `yourname@gmail.com`)
23-
* **Password:** The App Password you generated.
24-
16+
- **Server:** `smtp.gmail.com`
17+
- **Port:**
18+
- **STARTTLS:** 587 (Recommended)
19+
- **TLS:** 465
20+
- **No Encryption (Insecure - Avoid):** 25
21+
- **Username:** Your full Gmail address (e.g., `yourname@gmail.com`)
22+
- **Password:** The App Password you generated.
2523

2624
## 3. TLS/STARTTLS and Encryption
2725

28-
* **TLS (Transport Layer Security) / STARTTLS:** These are encryption protocols that secure the connection between your email client and the SMTP server. They encrypt your email messages and prevent eavesdropping. **Using TLS/STARTTLS is strongly recommended.** Many email clients support STARTTLS, initiating encryption during the connection process.
29-
30-
31-
* **No Encryption:** Sending emails without encryption is highly discouraged. Your email, including the subject, body, and any attachments, could be intercepted by malicious actors. Avoid this unless absolutely necessary, and only with trusted parties.
32-
26+
- **TLS (Transport Layer Security) / STARTTLS:** These are encryption protocols that secure the connection between your email client and the SMTP server. They encrypt your email messages and prevent eavesdropping. **Using TLS/STARTTLS is strongly recommended.** Many email clients support STARTTLS, initiating encryption during the connection process.
3327

28+
- **No Encryption:** Sending emails without encryption is highly discouraged. Your email, including the subject, body, and any attachments, could be intercepted by malicious actors. Avoid this unless absolutely necessary, and only with trusted parties.
3429

3530
## 4. Example Configuration (Illustrative - adapt to your email client)
3631

37-
38-
This is a generic example; the exact settings will depend on your email client (e.g., Outlook, Thunderbird). Refer to your email client's documentation for specific instructions.
39-
32+
This is a generic example; the exact settings will depend on your email client (e.g., Outlook, Thunderbird). Refer to your email client's documentation for specific instructions.
4033

4134
```
4235
SMTP_HOST=smtp.gmail.com
@@ -46,14 +39,26 @@ SMTP_USE_STARTTLS=true
4639

4740
Remember to replace placeholders with your actual information.
4841

49-
## 5. Troubleshooting
42+
### Using CLI Flags
5043

44+
You can also override the subject using the CLI flag:
45+
46+
```sh
47+
chatz --profile=smtp --subject "Custom Subject" "Hello from Chatz!"
48+
```
49+
50+
This will send an email with "Custom Subject" as the subject.
51+
52+
## 5. Troubleshooting
5153

5254
If you encounter issues, check:
5355

54-
* **Correct App Password:** Verify you copied the correct App Password.
55-
* **Firewall Settings:** Ensure your firewall isn't blocking outgoing connections on port 587 (or 465 if using no encryption).
56-
* **Email Client Configuration:** Double-check all server settings in your email client.
56+
- **Correct App Password:** Verify you copied the correct App Password.
57+
- **Firewall Settings:** Ensure your firewall isn't blocking outgoing connections on port 587 (or 465 if using no encryption).
58+
- **Email Client Configuration:** Double-check all server settings in your email client.
5759

5860
Using an App Password is crucial for securing your Gmail account when using SMTP. Always prioritize using TLS/STARTTLS encryption for the security of your emails.
61+
62+
```
63+
5964
```

main.go

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import (
44
"fmt"
55
"os"
66

7+
"github.com/tech-thinker/chatz/models"
78
"github.com/tech-thinker/chatz/providers"
89
"github.com/tech-thinker/chatz/utils"
910
"github.com/urfave/cli/v2"
@@ -22,6 +23,8 @@ func main() {
2223
var threadId string
2324
var output bool
2425
var fromEnv bool
26+
var subject string
27+
var priority int
2528

2629
app := cli.NewApp()
2730
app.Name = "chatz"
@@ -59,6 +62,18 @@ func main() {
5962
Usage: "To use config from environment variables",
6063
Destination: &fromEnv,
6164
},
65+
&cli.StringFlag{
66+
Name: "subject",
67+
Aliases: []string{"s"},
68+
Usage: "Subject for provider which supports subject or title",
69+
Destination: &subject,
70+
},
71+
&cli.IntFlag{
72+
Name: "priority",
73+
Aliases: []string{"pr"},
74+
Usage: "Priority for gotify notification",
75+
Destination: &priority,
76+
},
6277
}
6378
app.Action = func(ctx *cli.Context) error {
6479
if version {
@@ -92,14 +107,21 @@ func main() {
92107
return nil
93108
}
94109

110+
option := models.Option{
111+
Title: &subject,
112+
Subject: &subject,
113+
Priority: &priority,
114+
}
115+
95116
if len(threadId) > 0 {
96-
res, _ := provider.Reply(threadId, message)
117+
res, _ := provider.Reply(threadId, message, option)
97118
if output {
98119
fmt.Println(res)
99120
}
100121
return nil
101122
}
102-
res, err := provider.Post(message)
123+
124+
res, err := provider.Post(message, option)
103125
if output {
104126
fmt.Println(res)
105127
}

man/chatz.1

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,9 @@ Print output to stdout.
2525
.B \-t, \-\-thread-id
2626
Thread ID for replies to a message.
2727
.TP
28+
.B \-s, \-\-subject
29+
Subject for provider which supports subject or title.
30+
.TP
2831
.B \-e, \-\-from-env
2932
Use system environment variables.
3033
.TP

models/base.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
package models
2+
3+
type Option struct {
4+
Priority *int `json:"priority"`
5+
Title *string `json:"title"`
6+
Subject *string `json:"subject"`
7+
}

0 commit comments

Comments
 (0)