Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
build

chatz
*.exe
coverage.out
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ With chatz, you can streamline your notification processes across multiple platf
- Discord: [Read documentation](docs/discord.md)
- Redis: [Read documentation](docs/redis.md)
- SMTP: [Read documentation](docs/smtp.md)
- Gotify: [Read documentation](docs/gotify.md)

## Installation
Download and install executable binary from GitHub releases page.
Expand Down
7 changes: 7 additions & 0 deletions chatz.ini
Original file line number Diff line number Diff line change
Expand Up @@ -36,3 +36,10 @@ SMTP_PASSWORD=<app-password>
SMTP_SUBJECT=<Your subject>
SMTP_FROM=<[email protected]>
SMTP_TO=<[email protected],[email protected]>

[gotify]
PROVIDER=gotify
GOTIFY_URL=<gotify-url>
GOTIFY_TOKEN=<gotify-token>
GOTIFY_TITLE="Chatz"
GOTIFY_PRIORITY=5
34 changes: 19 additions & 15 deletions config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,23 @@ package config

// Environment
type Config struct {
Provider string
WebHookURL string
Token string
ChannelId string
ChatId string
ConnectionURL string
SMTPHost string
SMTPPort string
UseTLS bool
UseSTARTTLS bool
SMTPUser string
SMTPPassword string
SMTPSubject string
SMTPFrom string
SMTPTo string
Provider string
WebHookURL string
Token string
ChannelId string
ChatId string
ConnectionURL string
SMTPHost string
SMTPPort string
UseTLS bool
UseSTARTTLS bool
SMTPUser string
SMTPPassword string
SMTPSubject string
SMTPFrom string
SMTPTo string
GotifyURL string
GotifyToken string
GotifyTitle string
GotifyPriority int
}
1 change: 1 addition & 0 deletions constants/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,5 @@ const (
PROVIDER_GOOGLE = "google"
PROVIDER_REDIS = "redis"
PROVIDER_SMTP = "smtp"
PROVIDER_GOTIFY = "gotify"
)
59 changes: 59 additions & 0 deletions docs/gotify.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
# Gotify Notification Setup

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.

## 1. Get Gotify URL and App Token

First, you need to get the Gotify server URL and an app token.

1. **Gotify Server URL**: This is the URL of your Gotify server.
2. **App Token**: You can create a new app in the Gotify web UI and get the token.

## 2. Configure Chatz

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.

### Using `~/.chatz.ini`

Add the following section to your `~/.chatz.ini` file:

```ini
[gotify]
PROVIDER=gotify
GOTIFY_URL=<your-gotify-server-url>
GOTIFY_TOKEN=<your-gotify-app-token>
GOTIFY_TITLE=<your-gotify-title>
GOTIFY_PRIORITY=<your-gotify-priority>
```

### Using Environment Variables

Set the following environment variables:

```sh
export PROVIDER=gotify
export GOTIFY_URL=<your-gotify-server-url>
export GOTIFY_TOKEN=<your-gotify-app-token>
export GOTIFY_TITLE=<your-gotify-title>
export GOTIFY_PRIORITY=<your-gotify-priority>
```

## 3. Send a Test Notification

Now you can send a test notification to your Gotify server.

```sh
chatz --profile=gotify "Hello from Chatz!"
```

You should receive a notification on your Gotify server.

### Using CLI Flags

You can also override the title and priority using CLI flags:

```sh
chatz --profile=gotify --subject "Custom Title" --priority 7 "Hello from Chatz!"
```

This will send a notification with "Custom Title" as the title and a priority of 7.
53 changes: 29 additions & 24 deletions docs/smtp.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,41 +2,34 @@

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


## 1. Creating an App Password

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.
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.

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

## 2. SMTP Server Settings

* **Server:** `smtp.gmail.com`
* **Port:**
* **STARTTLS:** 587 (Recommended)
* **TLS:** 465
* **No Encryption (Insecure - Avoid):** 25
* **Username:** Your full Gmail address (e.g., `[email protected]`)
* **Password:** The App Password you generated.

- **Server:** `smtp.gmail.com`
- **Port:**
- **STARTTLS:** 587 (Recommended)
- **TLS:** 465
- **No Encryption (Insecure - Avoid):** 25
- **Username:** Your full Gmail address (e.g., `[email protected]`)
- **Password:** The App Password you generated.

## 3. TLS/STARTTLS and Encryption

* **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.


* **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.

- **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.

- **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.

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


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.

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.

```
SMTP_HOST=smtp.gmail.com
Expand All @@ -46,14 +39,26 @@ SMTP_USE_STARTTLS=true

Remember to replace placeholders with your actual information.

## 5. Troubleshooting
### Using CLI Flags

You can also override the subject using the CLI flag:

```sh
chatz --profile=smtp --subject "Custom Subject" "Hello from Chatz!"
```

This will send an email with "Custom Subject" as the subject.

## 5. Troubleshooting

If you encounter issues, check:

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

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.

```

```
26 changes: 24 additions & 2 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"fmt"
"os"

"github.com/tech-thinker/chatz/models"
"github.com/tech-thinker/chatz/providers"
"github.com/tech-thinker/chatz/utils"
"github.com/urfave/cli/v2"
Expand All @@ -22,6 +23,8 @@ func main() {
var threadId string
var output bool
var fromEnv bool
var subject string
var priority int

app := cli.NewApp()
app.Name = "chatz"
Expand Down Expand Up @@ -59,6 +62,18 @@ func main() {
Usage: "To use config from environment variables",
Destination: &fromEnv,
},
&cli.StringFlag{
Name: "subject",
Aliases: []string{"s"},
Usage: "Subject for provider which supports subject or title",
Destination: &subject,
},
&cli.IntFlag{
Name: "priority",
Aliases: []string{"pr"},
Usage: "Priority for gotify notification",
Destination: &priority,
},
}
app.Action = func(ctx *cli.Context) error {
if version {
Expand Down Expand Up @@ -92,14 +107,21 @@ func main() {
return nil
}

option := models.Option{
Title: &subject,
Subject: &subject,
Priority: &priority,
}

if len(threadId) > 0 {
res, _ := provider.Reply(threadId, message)
res, _ := provider.Reply(threadId, message, option)
if output {
fmt.Println(res)
}
return nil
}
res, err := provider.Post(message)

res, err := provider.Post(message, option)
if output {
fmt.Println(res)
}
Expand Down
3 changes: 3 additions & 0 deletions man/chatz.1
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,9 @@ Print output to stdout.
.B \-t, \-\-thread-id
Thread ID for replies to a message.
.TP
.B \-s, \-\-subject
Subject for provider which supports subject or title.
.TP
.B \-e, \-\-from-env
Use system environment variables.
.TP
Expand Down
7 changes: 7 additions & 0 deletions models/base.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package models

type Option struct {
Priority *int `json:"priority"`
Title *string `json:"title"`
Subject *string `json:"subject"`
}
42 changes: 21 additions & 21 deletions models/slack.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,36 +2,36 @@ package models

// SlackRes represents the main structure of the JSON response.
type SlackRes struct {
Ok bool `json:"ok"`
Channel string `json:"channel"`
Ts string `json:"ts"`
Ok bool `json:"ok"`
Channel string `json:"channel"`
Ts string `json:"ts"`
Message SlackMessage `json:"message"`
Warning string `json:"warning"`
Warning string `json:"warning"`
ResponseMetadata SlackResponseMetadata `json:"response_metadata"`
}

// SlackMessage represents the message object within the main response.
type SlackMessage struct {
User string `json:"user"`
Type string `json:"type"`
Ts string `json:"ts"`
BotID string `json:"bot_id"`
AppID string `json:"app_id"`
Text string `json:"text"`
Team string `json:"team"`
User string `json:"user"`
Type string `json:"type"`
Ts string `json:"ts"`
BotID string `json:"bot_id"`
AppID string `json:"app_id"`
Text string `json:"text"`
Team string `json:"team"`
BotProfile SlackBotProfile `json:"bot_profile"`
Blocks []SlackBlock `json:"blocks"`
}

// SlackBotProfile represents the profile of the bot that sent the message.
type SlackBotProfile struct {
ID string `json:"id"`
AppID string `json:"app_id"`
Name string `json:"name"`
Icons SlackIcons `json:"icons"`
Deleted bool `json:"deleted"`
Updated int64 `json:"updated"`
TeamID string `json:"team_id"`
ID string `json:"id"`
AppID string `json:"app_id"`
Name string `json:"name"`
Icons SlackIcons `json:"icons"`
Deleted bool `json:"deleted"`
Updated int64 `json:"updated"`
TeamID string `json:"team_id"`
}

// SlackIcons represents the bot's profile images of different sizes.
Expand All @@ -43,14 +43,14 @@ type SlackIcons struct {

// Block represents the block object in the message.
type SlackBlock struct {
Type string `json:"type"`
BlockID string `json:"block_id"`
Type string `json:"type"`
BlockID string `json:"block_id"`
Elements []SlackElement `json:"elements"`
}

// SlackElement represents a section within the block.
type SlackElement struct {
Type string `json:"type"`
Type string `json:"type"`
Elements []SlackInnerElement `json:"elements"`
}

Expand Down
7 changes: 5 additions & 2 deletions providers/agent.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,12 @@ import (

"github.com/tech-thinker/chatz/config"
"github.com/tech-thinker/chatz/constants"
"github.com/tech-thinker/chatz/models"
)

type Provider interface {
Post(message string) (interface{}, error)
Reply(threadId string, message string) (interface{}, error)
Post(message string, option models.Option) (any, error)
Reply(threadId string, message string, option models.Option) (any, error)
}

func NewProvider(env *config.Config) (Provider, error) {
Expand All @@ -26,6 +27,8 @@ func NewProvider(env *config.Config) (Provider, error) {
return &RedisProvider{config: env}, nil
case constants.PROVIDER_SMTP:
return &SMTPProvider{config: env}, nil
case constants.PROVIDER_GOTIFY:
return &GotifyProvider{config: env}, nil
default:
return nil, errors.New("Invalid provider config in ~/.chatz.ini")
}
Expand Down
Loading